Update Unity SDK for daily space like API

This commit is contained in:
2026-04-21 16:02:06 +08:00
parent a257a8a912
commit 0e5cab4f27
16 changed files with 154 additions and 34 deletions

View File

@@ -249,8 +249,10 @@ internal static class BriskModelMapper
ContentSizeBytes = BriskValueReader.GetLong(data, "content_size_bytes"),
ContentChecksum = BriskValueReader.GetString(data, "content_checksum"),
LikeCount = BriskValueReader.GetLong(data, "like_count"),
TodayLikeCount = BriskValueReader.GetLong(data, "today_like_count"),
VisitCount = BriskValueReader.GetLong(data, "visit_count"),
LikedByMe = BriskValueReader.GetBool(data, "liked_by_me"),
LikeResetAt = BriskValueReader.GetString(data, "like_reset_at"),
UpdatedAt = BriskValueReader.GetString(data, "updated_at")
};
}
@@ -276,7 +278,9 @@ internal static class BriskModelMapper
ContentSizeBytes = BriskValueReader.GetLong(data, "content_size_bytes"),
ContentChecksum = BriskValueReader.GetString(data, "content_checksum"),
LikeCount = BriskValueReader.GetLong(data, "like_count"),
TodayLikeCount = BriskValueReader.GetLong(data, "today_like_count"),
VisitCount = BriskValueReader.GetLong(data, "visit_count"),
LikeResetAt = BriskValueReader.GetString(data, "like_reset_at"),
UpdatedAt = BriskValueReader.GetString(data, "updated_at")
};
}
@@ -309,7 +313,11 @@ internal static class BriskModelMapper
return new BriskSpaceLikeResult
{
Liked = BriskValueReader.GetBool(data, "liked"),
LikeCount = BriskValueReader.GetLong(data, "like_count")
Created = BriskValueReader.GetBool(data, "created"),
LikedByMe = BriskValueReader.GetBool(data, "liked_by_me"),
LikeCount = BriskValueReader.GetLong(data, "like_count"),
TodayLikeCount = BriskValueReader.GetLong(data, "today_like_count"),
LikeResetAt = BriskValueReader.GetString(data, "like_reset_at")
};
}

View File

@@ -1,5 +1,9 @@
public sealed class BriskSpaceLikeResult
{
public bool Liked;
public bool Created;
public bool LikedByMe;
public long LikeCount;
public long TodayLikeCount;
public string LikeResetAt;
}

View File

@@ -12,6 +12,8 @@ public sealed class BriskSpaceStats
public long ContentSizeBytes;
public string ContentChecksum;
public long LikeCount;
public long TodayLikeCount;
public long VisitCount;
public string LikeResetAt;
public string UpdatedAt;
}

View File

@@ -12,7 +12,9 @@ public sealed class BriskSpaceView
public long ContentSizeBytes;
public string ContentChecksum;
public long LikeCount;
public long TodayLikeCount;
public long VisitCount;
public bool LikedByMe;
public string LikeResetAt;
public string UpdatedAt;
}

View File

@@ -68,23 +68,23 @@ public sealed class BriskSpaceModule
}
/// <summary>
/// 按玩家 ID 获取最近点赞列表。
/// 按玩家 ID 获取点赞列表。
/// </summary>
public async Task<IReadOnlyList<BriskSpaceLikeItem>> GetLikesByPlayerIdAsync(string playerId, int limit = 20)
public async Task<IReadOnlyList<BriskSpaceLikeItem>> GetLikesByPlayerIdAsync(string playerId, int limit = 20, bool currentCycleOnly = false)
{
ValidatePlayerId(playerId);
return await ExecuteAsync(async context =>
{
var data = await context.HttpClient.GetRawDataAsync($"/spaces/{playerId}/likes", CreateLimitQuery(limit), true);
var data = await context.HttpClient.GetRawDataAsync($"/spaces/{playerId}/likes", CreateLikesQuery(limit, currentCycleOnly), true);
return (IReadOnlyList<BriskSpaceLikeItem>)BriskModelMapper.ToSpaceLikeItems(data);
});
}
/// <summary>
/// 按登录身份获取最近点赞列表。
/// 按登录身份获取点赞列表。
/// </summary>
public async Task<IReadOnlyList<BriskSpaceLikeItem>> GetLikesByLoginIdentityAsync(string loginProvider, string loginUserId, int limit = 20)
public async Task<IReadOnlyList<BriskSpaceLikeItem>> GetLikesByLoginIdentityAsync(string loginProvider, string loginUserId, int limit = 20, bool currentCycleOnly = false)
{
ValidateLoginIdentity(loginProvider, loginUserId);
@@ -92,6 +92,10 @@ public sealed class BriskSpaceModule
{
var query = CreateLoginIdentityQuery(loginProvider, loginUserId);
query["limit"] = NormalizeLimit(limit);
if (currentCycleOnly)
{
query["scope"] = "cycle";
}
var data = await context.HttpClient.GetRawDataAsync("/spaces/by-login/likes", query, true);
return (IReadOnlyList<BriskSpaceLikeItem>)BriskModelMapper.ToSpaceLikeItems(data);
});
@@ -262,6 +266,17 @@ public sealed class BriskSpaceModule
};
}
private static Dictionary<string, string> CreateLikesQuery(int limit, bool currentCycleOnly)
{
var query = CreateLimitQuery(limit);
if (currentCycleOnly)
{
query["scope"] = "cycle";
}
return query;
}
private static void ValidatePlayerId(string playerId)
{
RequireNotEmpty(playerId, nameof(playerId));

View File

@@ -475,14 +475,16 @@ public sealed class BriskQuickStartSample : MonoBehaviour
DrawValueRow("内容版本", _mySpaceView == null ? "-" : _mySpaceView.ContentVersion.ToString());
DrawValueRow("内容类型", _mySpaceView == null ? "-" : NullToDash(_mySpaceView.ContentType));
DrawValueRow("内容大小", _mySpaceView == null ? "-" : _mySpaceView.ContentSizeBytes + " bytes");
DrawValueRow("点赞数", _mySpaceStats == null ? "-" : _mySpaceStats.LikeCount.ToString());
DrawValueRow("累计点赞数", _mySpaceStats == null ? "-" : _mySpaceStats.LikeCount.ToString());
DrawValueRow("今日点赞数", _mySpaceStats == null ? "-" : _mySpaceStats.TodayLikeCount.ToString());
DrawValueRow("访问数", _mySpaceStats == null ? "-" : _mySpaceStats.VisitCount.ToString());
DrawValueRow("今日点赞重置", _mySpaceStats == null ? "-" : FormatLikeResetAt(_mySpaceStats.LikeResetAt));
DrawValueRow("更新时间", _mySpaceView == null ? "-" : NullToDash(_mySpaceView.UpdatedAt));
GUILayout.Space(8f);
GUILayout.Label("最近给我点赞的用户", _sectionTitleStyle);
GUILayout.Label("今天给我点赞的用户", _sectionTitleStyle);
if (_mySpaceLikes.Count == 0)
{
GUILayout.Label("暂无点赞记录。", _bodyStyle);
GUILayout.Label("当前周期暂无点赞记录。", _bodyStyle);
}
else
{
@@ -509,9 +511,11 @@ public sealed class BriskQuickStartSample : MonoBehaviour
DrawValueRow("PlayerId", _targetSpaceView == null ? "-" : NullToDash(_targetSpaceView.PlayerId));
DrawValueRow("内容类型", _targetSpaceView == null ? "-" : NullToDash(_targetSpaceView.ContentType));
DrawValueRow("内容大小", _targetSpaceView == null ? "-" : _targetSpaceView.ContentSizeBytes + " bytes");
DrawValueRow("点赞数", _targetSpaceStats == null ? "-" : _targetSpaceStats.LikeCount.ToString());
DrawValueRow("累计点赞数", _targetSpaceStats == null ? "-" : _targetSpaceStats.LikeCount.ToString());
DrawValueRow("今日点赞数", _targetSpaceStats == null ? "-" : _targetSpaceStats.TodayLikeCount.ToString());
DrawValueRow("访问数", _targetSpaceStats == null ? "-" : _targetSpaceStats.VisitCount.ToString());
DrawValueRow("我的点赞状态", _targetSpaceView != null && _targetSpaceView.LikedByMe ? "已点赞" : "未点赞");
DrawValueRow("今日点赞状态", _targetSpaceView != null && _targetSpaceView.LikedByMe ? "今日已点赞" : "今日未点赞");
DrawValueRow("今日点赞重置", _targetSpaceView == null ? "-" : FormatLikeResetAt(_targetSpaceView.LikeResetAt));
GUILayout.Space(8f);
GUILayout.Label("空间内容", _sectionTitleStyle);
GUILayout.TextArea(_targetSpaceContentText ?? string.Empty, _textAreaStyle, GUILayout.Height(240f));
@@ -520,8 +524,8 @@ public sealed class BriskQuickStartSample : MonoBehaviour
DrawCard("操作", () =>
{
DrawInlineButtons(
new ButtonSpec("点赞", LikeTargetSpaceAsync, false, true),
new ButtonSpec("取消点赞", UnlikeTargetSpaceAsync, false, true));
new ButtonSpec("今日点赞", LikeTargetSpaceAsync, false, _targetSpaceView != null && !_targetSpaceView.LikedByMe),
new ButtonSpec("撤销今日点赞", UnlikeTargetSpaceAsync, false, _targetSpaceView != null && _targetSpaceView.LikedByMe));
});
}
@@ -636,7 +640,7 @@ public sealed class BriskQuickStartSample : MonoBehaviour
_mySpaceView = await Brisk.Space.GetByPlayerIdAsync(Brisk.PlayerId);
_mySpaceStats = await Brisk.Space.GetStatsByPlayerIdAsync(Brisk.PlayerId);
_mySpaceLikes = await Brisk.Space.GetLikesByPlayerIdAsync(Brisk.PlayerId, 10);
_mySpaceLikes = await Brisk.Space.GetLikesByPlayerIdAsync(Brisk.PlayerId, 10, true);
SpacePayloadText = await DownloadSpaceTextAsync(_mySpaceView, () => Brisk.Space.DownloadContentByPlayerIdAsync(Brisk.PlayerId));
}
@@ -673,13 +677,15 @@ public sealed class BriskQuickStartSample : MonoBehaviour
private async Task LikeTargetSpaceAsync()
{
await Brisk.Space.LikeByPlayerIdAsync(SpacePlayerId);
var result = await Brisk.Space.LikeByPlayerIdAsync(SpacePlayerId);
Log("空间今日点赞结果: created=" + result.Created + ", total=" + result.LikeCount + ", today=" + result.TodayLikeCount);
await LoadTargetSpaceAsync();
}
private async Task UnlikeTargetSpaceAsync()
{
await Brisk.Space.UnlikeByPlayerIdAsync(SpacePlayerId);
var result = await Brisk.Space.UnlikeByPlayerIdAsync(SpacePlayerId);
Log("空间撤销今日点赞结果: total=" + result.LikeCount + ", today=" + result.TodayLikeCount);
await LoadTargetSpaceAsync();
}
@@ -1120,6 +1126,22 @@ public sealed class BriskQuickStartSample : MonoBehaviour
return string.IsNullOrWhiteSpace(value) ? "-" : value;
}
private static string FormatLikeResetAt(string value)
{
if (string.IsNullOrWhiteSpace(value))
{
return "-";
}
DateTimeOffset parsed;
if (!DateTimeOffset.TryParse(value, out parsed))
{
return value;
}
return parsed.LocalDateTime.ToString("yyyy-MM-dd HH:mm:ss");
}
private static async Task<string> DownloadSpaceTextAsync(BriskSpaceView view, Func<Task<BriskSpaceContentDownloadResult>> downloadContent)
{
if (view == null || !view.ContentExists || downloadContent == null)