diff --git a/Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs b/Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs index 9858b0e..16f7092 100644 --- a/Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs +++ b/Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs @@ -37,11 +37,27 @@ public string ToQueryString() } } + public class CreateChannelOptions + { + public string name; + public (string, string)[] props = Array.Empty<(string, string)>(); + + public bool autoCleanup = false; + public bool isPrivate = false; + public bool temporaryMembership = false; + } + + public enum ChannelLeavingReason + { + Default, + TemporaryMembership + } + public class ChannelsAPI : BaseAPI { public event Action OnMessageReceived; public event Action OnChannelJoined; - public event Action OnChannelLeft; + public event Action OnChannelLeft; public event Action OnOwnershipTransferred; public event Action OnChannelDeleted; public event Action OnChannelUpdated; @@ -63,7 +79,7 @@ public ChannelsAPI() : base("v1/game-channels") else if (response.GetResponseType() == "v1.channels.left") { var data = response.GetData(); - OnChannelLeft?.Invoke(data.channel, data.playerAlias); + OnChannelLeft?.Invoke(data.channel, data.playerAlias, data.meta.reason); } else if (response.GetResponseType() == "v1.channels.ownership-transferred") { @@ -113,24 +129,20 @@ public async Task GetSubscribedChannels(GetSubscribedChannelsOptions return res.channels; } - private async Task SendCreateChannelRequest( - string name, - bool autoCleanup = false, - bool isPrivate = false, - params (string, string)[] propTuples - ) + private async Task SendCreateChannelRequest(CreateChannelOptions options) { Talo.IdentityCheck(); - var props = propTuples.Select((propTuple) => new Prop(propTuple)).ToArray(); + var props = options.props.Select((propTuple) => new Prop(propTuple)).ToArray(); var uri = new Uri(baseUrl); var content = JsonUtility.ToJson(new ChannelsCreateRequest { - name = name, - autoCleanup = autoCleanup, + name = options.name, + autoCleanup = options.autoCleanup, props = props, - @private = isPrivate + @private = options.isPrivate, + temporaryMembership = options.temporaryMembership }); var json = await Call(uri, "POST", content); @@ -138,14 +150,36 @@ private async Task SendCreateChannelRequest( return res.channel; } + public async Task Create(CreateChannelOptions options) + { + options ??= new CreateChannelOptions(); + return await SendCreateChannelRequest(options); + } + + [Obsolete("Use Create(CreateChannelOptions options) instead.")] public async Task Create(string name, bool autoCleanup = false, params (string, string)[] propTuples) { - return await SendCreateChannelRequest(name, autoCleanup, false, propTuples); + var options = new CreateChannelOptions + { + name = name, + autoCleanup = autoCleanup, + props = propTuples, + isPrivate = false + }; + return await SendCreateChannelRequest(options); } + [Obsolete("Use Create(CreateChannelOptions options) instead.")] public async Task CreatePrivate(string name, bool autoCleanup = false, params (string, string)[] propTuples) { - return await SendCreateChannelRequest(name, autoCleanup, true, propTuples); + var options = new CreateChannelOptions + { + name = name, + autoCleanup = autoCleanup, + props = propTuples, + isPrivate = true + }; + return await SendCreateChannelRequest(options); } public async Task Join(int channelId) diff --git a/Assets/Talo Game Services/Talo/Runtime/Requests/ChannelsCreateRequest.cs b/Assets/Talo Game Services/Talo/Runtime/Requests/ChannelsCreateRequest.cs index 8e54975..2c2344f 100644 --- a/Assets/Talo Game Services/Talo/Runtime/Requests/ChannelsCreateRequest.cs +++ b/Assets/Talo Game Services/Talo/Runtime/Requests/ChannelsCreateRequest.cs @@ -7,5 +7,6 @@ public class ChannelsCreateRequest public bool autoCleanup; public Prop[] props; public bool @private; + public bool temporaryMembership; } } diff --git a/Assets/Talo Game Services/Talo/Runtime/SocketResponses/ChannelLeftResponse.cs b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/ChannelLeftResponse.cs index e9b6144..fb99c41 100644 --- a/Assets/Talo Game Services/Talo/Runtime/SocketResponses/ChannelLeftResponse.cs +++ b/Assets/Talo Game Services/Talo/Runtime/SocketResponses/ChannelLeftResponse.cs @@ -5,5 +5,12 @@ public class ChannelLeftResponse { public Channel channel; public PlayerAlias playerAlias; + public ChannelLeftResponseMetadata meta; + } + + [System.Serializable] + public class ChannelLeftResponseMetadata + { + public ChannelLeavingReason reason; } } diff --git a/Assets/Talo Game Services/Talo/Samples/ChatDemo/Scripts/ChatUIController.cs b/Assets/Talo Game Services/Talo/Samples/ChatDemo/Scripts/ChatUIController.cs index 1b84624..7011f49 100644 --- a/Assets/Talo Game Services/Talo/Samples/ChatDemo/Scripts/ChatUIController.cs +++ b/Assets/Talo Game Services/Talo/Samples/ChatDemo/Scripts/ChatUIController.cs @@ -132,7 +132,7 @@ private async void OnCreateChannelClick() return; } - var channel = await Talo.Channels.Create(channelName); + var channel = await Talo.Channels.Create(new CreateChannelOptions() { name = channelName, autoCleanup = true }); AddChannelToList(channel); channelNameField.value = ""; activeChannelId = channel.id;