From a15402cd4a3c4557ae1d0833bc449c2c19d4d81a Mon Sep 17 00:00:00 2001 From: tudor <7089284+tudddorrr@users.noreply.github.com> Date: Wed, 24 Sep 2025 20:52:58 +0100 Subject: [PATCH] add list storage props for fetching multiple storage props --- .../Talo/Runtime/APIs/ChannelsAPI.cs | 29 +++++++++++++++++++ .../ChannelStoragePropsListResponse.cs | 10 +++++++ .../ChannelStoragePropsListResponse.cs.meta | 2 ++ .../Runtime/Utils/ChannelStorageManager.cs | 27 +++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 Assets/Talo Game Services/Talo/Runtime/Responses/ChannelStoragePropsListResponse.cs create mode 100644 Assets/Talo Game Services/Talo/Runtime/Responses/ChannelStoragePropsListResponse.cs.meta diff --git a/Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs b/Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs index 38a10ef..96c269b 100644 --- a/Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs +++ b/Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs @@ -348,5 +348,34 @@ public async Task SetStorageProps(int channelId, params (string, string)[] propT OnChannelStoragePropsFailedToSet?.Invoke(res.channel, res.failedProps); } } + + public async Task ListStorageProps(int channelId, string[] propKeys, bool bustCache = false) + { + Talo.IdentityCheck(); + + if (!bustCache) + { + return await _storageManager.ListProps(channelId, propKeys); + } + + var queryParams = propKeys.Length > 0 + ? "?" + string.Join("&", propKeys.Select((key) => $"propKeys={key}")) + : ""; + + var uri = new Uri($"{baseUrl}/{channelId}/storage/list{queryParams}"); + var json = await Call(uri, "GET"); + + var res = JsonUtility.FromJson(json); + if (res.props != null) + { + foreach (var prop in res.props) + { + _storageManager.UpsertProp(channelId, prop); + } + return res.props; + } + + return new ChannelStorageProp[0]; + } } } diff --git a/Assets/Talo Game Services/Talo/Runtime/Responses/ChannelStoragePropsListResponse.cs b/Assets/Talo Game Services/Talo/Runtime/Responses/ChannelStoragePropsListResponse.cs new file mode 100644 index 0000000..98a0a9c --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/Responses/ChannelStoragePropsListResponse.cs @@ -0,0 +1,10 @@ +using System; + +namespace TaloGameServices +{ + [Serializable] + public class ChannelStoragePropsListResponse + { + public ChannelStorageProp[] props; + } +} diff --git a/Assets/Talo Game Services/Talo/Runtime/Responses/ChannelStoragePropsListResponse.cs.meta b/Assets/Talo Game Services/Talo/Runtime/Responses/ChannelStoragePropsListResponse.cs.meta new file mode 100644 index 0000000..0e91b86 --- /dev/null +++ b/Assets/Talo Game Services/Talo/Runtime/Responses/ChannelStoragePropsListResponse.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: ae917c9b5cf1648c1b835588d1d2085f \ No newline at end of file diff --git a/Assets/Talo Game Services/Talo/Runtime/Utils/ChannelStorageManager.cs b/Assets/Talo Game Services/Talo/Runtime/Utils/ChannelStorageManager.cs index 116c8f6..bd0210c 100644 --- a/Assets/Talo Game Services/Talo/Runtime/Utils/ChannelStorageManager.cs +++ b/Assets/Talo Game Services/Talo/Runtime/Utils/ChannelStorageManager.cs @@ -42,5 +42,32 @@ public void DeleteProp(int channelId, string propKey) var key = $"{channelId}:{propKey}"; _currentProps.Remove(key); } + + public async Task ListProps(int channelId, string[] propKeys) + { + var results = new List(); + var keysToFetch = new List(); + + foreach (var propKey in propKeys) + { + var cacheKey = $"{channelId}:{propKey}"; + if (_currentProps.TryGetValue(cacheKey, out var cachedProp)) + { + results.Add(cachedProp); + } + else + { + keysToFetch.Add(propKey); + } + } + + if (keysToFetch.Count > 0) + { + var fetchedProps = await Talo.Channels.ListStorageProps(channelId, keysToFetch.ToArray(), true); + results.AddRange(fetchedProps); + } + + return results.ToArray(); + } } }