Skip to content

Commit 5fb746c

Browse files
authored
Merge pull request #129 from TaloDev/temporary-channel-membership
Add channel create options and temporary membership flag
2 parents dee3e11 + b35204c commit 5fb746c

File tree

4 files changed

+57
-15
lines changed

4 files changed

+57
-15
lines changed

Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,27 @@ public string ToQueryString()
3737
}
3838
}
3939

40+
public class CreateChannelOptions
41+
{
42+
public string name;
43+
public (string, string)[] props = Array.Empty<(string, string)>();
44+
45+
public bool autoCleanup = false;
46+
public bool isPrivate = false;
47+
public bool temporaryMembership = false;
48+
}
49+
50+
public enum ChannelLeavingReason
51+
{
52+
Default,
53+
TemporaryMembership
54+
}
55+
4056
public class ChannelsAPI : BaseAPI
4157
{
4258
public event Action<Channel, PlayerAlias, string> OnMessageReceived;
4359
public event Action<Channel, PlayerAlias> OnChannelJoined;
44-
public event Action<Channel, PlayerAlias> OnChannelLeft;
60+
public event Action<Channel, PlayerAlias, ChannelLeavingReason> OnChannelLeft;
4561
public event Action<Channel, PlayerAlias> OnOwnershipTransferred;
4662
public event Action<Channel> OnChannelDeleted;
4763
public event Action<Channel, string[]> OnChannelUpdated;
@@ -63,7 +79,7 @@ public ChannelsAPI() : base("v1/game-channels")
6379
else if (response.GetResponseType() == "v1.channels.left")
6480
{
6581
var data = response.GetData<ChannelLeftResponse>();
66-
OnChannelLeft?.Invoke(data.channel, data.playerAlias);
82+
OnChannelLeft?.Invoke(data.channel, data.playerAlias, data.meta.reason);
6783
}
6884
else if (response.GetResponseType() == "v1.channels.ownership-transferred")
6985
{
@@ -113,39 +129,57 @@ public async Task<Channel[]> GetSubscribedChannels(GetSubscribedChannelsOptions
113129
return res.channels;
114130
}
115131

116-
private async Task<Channel> SendCreateChannelRequest(
117-
string name,
118-
bool autoCleanup = false,
119-
bool isPrivate = false,
120-
params (string, string)[] propTuples
121-
)
132+
private async Task<Channel> SendCreateChannelRequest(CreateChannelOptions options)
122133
{
123134
Talo.IdentityCheck();
124135

125-
var props = propTuples.Select((propTuple) => new Prop(propTuple)).ToArray();
136+
var props = options.props.Select((propTuple) => new Prop(propTuple)).ToArray();
126137

127138
var uri = new Uri(baseUrl);
128139
var content = JsonUtility.ToJson(new ChannelsCreateRequest
129140
{
130-
name = name,
131-
autoCleanup = autoCleanup,
141+
name = options.name,
142+
autoCleanup = options.autoCleanup,
132143
props = props,
133-
@private = isPrivate
144+
@private = options.isPrivate,
145+
temporaryMembership = options.temporaryMembership
134146
});
135147
var json = await Call(uri, "POST", content);
136148

137149
var res = JsonUtility.FromJson<ChannelResponse>(json);
138150
return res.channel;
139151
}
140152

153+
public async Task<Channel> Create(CreateChannelOptions options)
154+
{
155+
options ??= new CreateChannelOptions();
156+
return await SendCreateChannelRequest(options);
157+
}
158+
159+
[Obsolete("Use Create(CreateChannelOptions options) instead.")]
141160
public async Task<Channel> Create(string name, bool autoCleanup = false, params (string, string)[] propTuples)
142161
{
143-
return await SendCreateChannelRequest(name, autoCleanup, false, propTuples);
162+
var options = new CreateChannelOptions
163+
{
164+
name = name,
165+
autoCleanup = autoCleanup,
166+
props = propTuples,
167+
isPrivate = false
168+
};
169+
return await SendCreateChannelRequest(options);
144170
}
145171

172+
[Obsolete("Use Create(CreateChannelOptions options) instead.")]
146173
public async Task<Channel> CreatePrivate(string name, bool autoCleanup = false, params (string, string)[] propTuples)
147174
{
148-
return await SendCreateChannelRequest(name, autoCleanup, true, propTuples);
175+
var options = new CreateChannelOptions
176+
{
177+
name = name,
178+
autoCleanup = autoCleanup,
179+
props = propTuples,
180+
isPrivate = true
181+
};
182+
return await SendCreateChannelRequest(options);
149183
}
150184

151185
public async Task<Channel> Join(int channelId)

Assets/Talo Game Services/Talo/Runtime/Requests/ChannelsCreateRequest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ public class ChannelsCreateRequest
77
public bool autoCleanup;
88
public Prop[] props;
99
public bool @private;
10+
public bool temporaryMembership;
1011
}
1112
}

Assets/Talo Game Services/Talo/Runtime/SocketResponses/ChannelLeftResponse.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,12 @@ public class ChannelLeftResponse
55
{
66
public Channel channel;
77
public PlayerAlias playerAlias;
8+
public ChannelLeftResponseMetadata meta;
9+
}
10+
11+
[System.Serializable]
12+
public class ChannelLeftResponseMetadata
13+
{
14+
public ChannelLeavingReason reason;
815
}
916
}

Assets/Talo Game Services/Talo/Samples/ChatDemo/Scripts/ChatUIController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private async void OnCreateChannelClick()
132132
return;
133133
}
134134

135-
var channel = await Talo.Channels.Create(channelName);
135+
var channel = await Talo.Channels.Create(new CreateChannelOptions() { name = channelName, autoCleanup = true });
136136
AddChannelToList(channel);
137137
channelNameField.value = "";
138138
activeChannelId = channel.id;

0 commit comments

Comments
 (0)