Skip to content

Commit faa6dfc

Browse files
committed
create channel options + temporary membership flag
1 parent dee3e11 commit faa6dfc

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

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

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ 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+
4050
public class ChannelsAPI : BaseAPI
4151
{
4252
public event Action<Channel, PlayerAlias, string> OnMessageReceived;
@@ -113,39 +123,57 @@ public async Task<Channel[]> GetSubscribedChannels(GetSubscribedChannelsOptions
113123
return res.channels;
114124
}
115125

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

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

127132
var uri = new Uri(baseUrl);
128133
var content = JsonUtility.ToJson(new ChannelsCreateRequest
129134
{
130-
name = name,
131-
autoCleanup = autoCleanup,
135+
name = options.name,
136+
autoCleanup = options.autoCleanup,
132137
props = props,
133-
@private = isPrivate
138+
@private = options.isPrivate,
139+
temporaryMembership = options.temporaryMembership
134140
});
135141
var json = await Call(uri, "POST", content);
136142

137143
var res = JsonUtility.FromJson<ChannelResponse>(json);
138144
return res.channel;
139145
}
140146

147+
public async Task<Channel> Create(CreateChannelOptions options)
148+
{
149+
options ??= new CreateChannelOptions();
150+
return await SendCreateChannelRequest(options);
151+
}
152+
153+
[Obsolete("Use Create(CreateChannelOptions options) instead.")]
141154
public async Task<Channel> Create(string name, bool autoCleanup = false, params (string, string)[] propTuples)
142155
{
143-
return await SendCreateChannelRequest(name, autoCleanup, false, propTuples);
156+
var options = new CreateChannelOptions
157+
{
158+
name = name,
159+
autoCleanup = autoCleanup,
160+
props = propTuples,
161+
isPrivate = false
162+
};
163+
return await SendCreateChannelRequest(options);
144164
}
145165

166+
[Obsolete("Use Create(CreateChannelOptions options) instead.")]
146167
public async Task<Channel> CreatePrivate(string name, bool autoCleanup = false, params (string, string)[] propTuples)
147168
{
148-
return await SendCreateChannelRequest(name, autoCleanup, true, propTuples);
169+
var options = new CreateChannelOptions
170+
{
171+
name = name,
172+
autoCleanup = autoCleanup,
173+
props = propTuples,
174+
isPrivate = true
175+
};
176+
return await SendCreateChannelRequest(options);
149177
}
150178

151179
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/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)