Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,5 +348,34 @@ public async Task SetStorageProps(int channelId, params (string, string)[] propT
OnChannelStoragePropsFailedToSet?.Invoke(res.channel, res.failedProps);
}
}

public async Task<ChannelStorageProp[]> 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<ChannelStoragePropsListResponse>(json);
if (res.props != null)
{
foreach (var prop in res.props)
{
_storageManager.UpsertProp(channelId, prop);
}
return res.props;
}

return new ChannelStorageProp[0];
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace TaloGameServices
{
[Serializable]
public class ChannelStoragePropsListResponse
{
public ChannelStorageProp[] props;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,32 @@ public void DeleteProp(int channelId, string propKey)
var key = $"{channelId}:{propKey}";
_currentProps.Remove(key);
}

public async Task<ChannelStorageProp[]> ListProps(int channelId, string[] propKeys)
{
var results = new List<ChannelStorageProp>();
var keysToFetch = new List<string>();

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();
}
}
}
Loading