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
33 changes: 31 additions & 2 deletions Assets/Talo Game Services/Talo/Runtime/APIs/ChannelsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,40 @@ public async Task<Channel[]> GetSubscribedChannels()
return res.channels;
}

public async Task<Channel> Create(string name, bool autoCleanup = false, params (string, string)[] propTuples)
private async Task<Channel> SendCreateChannelRequest(
string name,
bool autoCleanup = false,
bool isPrivate = false,
params (string, string)[] propTuples
)
{
Talo.IdentityCheck();

var props = propTuples.Select((propTuple) => new Prop(propTuple)).ToArray();

var uri = new Uri(baseUrl);
var content = JsonUtility.ToJson(new ChannelsCreateRequest { name = name, autoCleanup = autoCleanup, props = props });
var content = JsonUtility.ToJson(new ChannelsCreateRequest {
name = name,
autoCleanup = autoCleanup,
props = props,
@private = isPrivate
});
var json = await Call(uri, "POST", content);

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

public async Task<Channel> Create(string name, bool autoCleanup = false, params (string, string)[] propTuples)
{
return await SendCreateChannelRequest(name, autoCleanup, false, propTuples);
}

public async Task<Channel> CreatePrivate(string name, bool autoCleanup = false, params (string, string)[] propTuples)
{
return await SendCreateChannelRequest(name, autoCleanup, true, propTuples);
}

public async Task<Channel> Join(int channelId)
{
Talo.IdentityCheck();
Expand Down Expand Up @@ -154,5 +174,14 @@ public async Task<Channel> Find(int channelId)
var res = JsonUtility.FromJson<ChannelResponse>(json);
return res.channel;
}

public async Task Invite(int channelId, int playerAliasId)
{
Talo.IdentityCheck();

var uri = new Uri($"{baseUrl}/{channelId}/invite");
var content = JsonUtility.ToJson(new ChannelsInviteRequest { inviteeAliasId = playerAliasId });
await Call(uri, "POST", content);
}
}
}
2 changes: 2 additions & 0 deletions Assets/Talo Game Services/Talo/Runtime/Entities/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class Channel: EntityWithProps
public PlayerAlias ownerAlias;
public int totalMessages;
public int memberCount;
public bool autoCleanup;
public bool @private;
public string createdAt;
public string updatedAt;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

namespace TaloGameServices
{
[System.Serializable]
Expand All @@ -7,5 +6,6 @@ public class ChannelsCreateRequest
public string name;
public bool autoCleanup;
public Prop[] props;
public bool @private;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace TaloGameServices
{
[System.Serializable]
public class ChannelsInviteRequest
{
public int inviteeAliasId;
}
}

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