Skip to content
Open
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
77 changes: 51 additions & 26 deletions src/Clients/ChannelClient.Crud.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using StreamChat.Models;
using StreamChat.Rest;
Expand All @@ -22,82 +23,106 @@ public async Task<ChannelGetResponse> GetOrCreateAsync(string channelType, strin
},
});

public async Task<ChannelGetResponse> GetOrCreateAsync(string channelType, string channelId, string createdBy,
string[] members, CancellationToken cancellationToken = default)
=> await GetOrCreateAsync(channelType,
channelId,
new ChannelGetRequest
{
Data = new ChannelRequest
{
CreatedBy = new UserRequest { Id = createdBy },
Members = members.Select(x => new ChannelMember { UserId = x }),
},
},
cancellationToken: cancellationToken);

public async Task<ChannelGetResponse> GetOrCreateAsync(string channelType, string channelId,
ChannelGetRequest channelRequest)
ChannelGetRequest channelRequest, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<ChannelGetResponse>($"channels/{channelType}/{channelId}/query",
HttpMethod.POST,
HttpStatusCode.Created,
channelRequest);
channelRequest,
cancellationToken: cancellationToken);

public async Task<ChannelGetResponse> GetOrCreateAsync(string channelType, ChannelGetRequest channelRequest)
public async Task<ChannelGetResponse> GetOrCreateAsync(string channelType, ChannelGetRequest channelRequest, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<ChannelGetResponse>($"channels/{channelType}/query",
HttpMethod.POST,
HttpStatusCode.Created,
channelRequest);
channelRequest,
cancellationToken: cancellationToken);

public async Task<UpdateChannelResponse> UpdateAsync(string channelType, string channelId,
ChannelUpdateRequest updateRequest)
ChannelUpdateRequest updateRequest, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<UpdateChannelResponse>($"channels/{channelType}/{channelId}",
HttpMethod.POST,
HttpStatusCode.Created,
updateRequest);
updateRequest,
cancellationToken: cancellationToken);

public async Task<PartialUpdateChannelResponse> PartialUpdateAsync(string channelType, string channelId,
PartialUpdateChannelRequest partialUpdateChannelRequest)
PartialUpdateChannelRequest partialUpdateChannelRequest, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<PartialUpdateChannelResponse>($"channels/{channelType}/{channelId}",
HttpMethod.PATCH,
HttpStatusCode.OK,
partialUpdateChannelRequest);
partialUpdateChannelRequest,
cancellationToken: cancellationToken);

public async Task<ApiResponse> DeleteAsync(string channelType, string channelId)
public async Task<ApiResponse> DeleteAsync(string channelType, string channelId, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<ApiResponse>($"channels/{channelType}/{channelId}",
HttpMethod.DELETE,
HttpStatusCode.OK);
HttpStatusCode.OK,
cancellationToken: cancellationToken);

public async Task<TruncateResponse> TruncateAsync(string channelType, string channelId)
=> await TruncateAsync(channelType, channelId, null);
public async Task<TruncateResponse> TruncateAsync(string channelType, string channelId, CancellationToken cancellationToken = default)
=> await TruncateAsync(channelType, channelId, null, cancellationToken);

public async Task<TruncateResponse> TruncateAsync(string channelType, string channelId,
TruncateOptions truncateOptions)
TruncateOptions truncateOptions, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<TruncateResponse>($"channels/{channelType}/{channelId}/truncate",
HttpMethod.POST,
HttpStatusCode.Created,
truncateOptions);
truncateOptions,
cancellationToken: cancellationToken);

public Task<ChannelMemberResponse> PinAsync(string channelType, string channelId, string userId)
public Task<ChannelMemberResponse> PinAsync(string channelType, string channelId, string userId, CancellationToken cancellationToken = default)
=> UpdateMemberPartialAsync(channelType, channelId, new ChannelMemberPartialRequest
{
UserId = userId, Set = new Dictionary<string, object>()
UserId = userId,
Set = new Dictionary<string, object>()
{
{ "pinned", true },
},
});
}, cancellationToken);

public Task<ChannelMemberResponse> UnpinAsync(string channelType, string channelId, string userId)
public Task<ChannelMemberResponse> UnpinAsync(string channelType, string channelId, string userId, CancellationToken cancellationToken = default)
=> UpdateMemberPartialAsync(channelType, channelId, new ChannelMemberPartialRequest
{
UserId = userId, Set = new Dictionary<string, object>()
UserId = userId,
Set = new Dictionary<string, object>()
{
{ "pinned", false },
},
});
}, cancellationToken);

public Task<ChannelMemberResponse> ArchiveAsync(string channelType, string channelId, string userId)
public Task<ChannelMemberResponse> ArchiveAsync(string channelType, string channelId, string userId, CancellationToken cancellationToken = default)
=> UpdateMemberPartialAsync(channelType, channelId, new ChannelMemberPartialRequest
{
UserId = userId, Set = new Dictionary<string, object>()
UserId = userId,
Set = new Dictionary<string, object>()
{
{ "archived", true },
},
});
}, cancellationToken);

public Task<ChannelMemberResponse> UnarchiveAsync(string channelType, string channelId, string userId)
public Task<ChannelMemberResponse> UnarchiveAsync(string channelType, string channelId, string userId, CancellationToken cancellationToken = default)
=> UpdateMemberPartialAsync(channelType, channelId, new ChannelMemberPartialRequest
{
UserId = userId, Set = new Dictionary<string, object>()
UserId = userId,
Set = new Dictionary<string, object>()
{
{ "archived", false },
},
});
}, cancellationToken);
}
}
9 changes: 6 additions & 3 deletions src/Clients/ChannelClient.FilterTags.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using StreamChat.Models;
using StreamChat.Rest;
Expand All @@ -21,7 +22,7 @@ public Task<UpdateChannelResponse> AddFilterTagsAsync(string channelType, string
/// Adds filter tags to the channel.
/// </summary>
public async Task<UpdateChannelResponse> AddFilterTagsAsync(string channelType, string channelId,
IEnumerable<string> filterTags, MessageRequest msg = null) => await ExecuteRequestAsync<UpdateChannelResponse>(
IEnumerable<string> filterTags, MessageRequest msg = null, CancellationToken cancellationToken = default) => await ExecuteRequestAsync<UpdateChannelResponse>(
$"channels/{channelType}/{channelId}",
HttpMethod.POST,
HttpStatusCode.Created,
Expand All @@ -41,14 +42,16 @@ public Task<ApiResponse> RemoveFilterTagsAsync(string channelType, string channe
/// Removes filter tags from the channel.
/// </summary>
public async Task<ApiResponse> RemoveFilterTagsAsync(string channelType, string channelId,
IEnumerable<string> filterTags, MessageRequest msg = null) => await ExecuteRequestAsync<ApiResponse>(
IEnumerable<string> filterTags, MessageRequest msg = null,
CancellationToken cancellationToken = default) => await ExecuteRequestAsync<ApiResponse>(
$"channels/{channelType}/{channelId}",
HttpMethod.POST,
HttpStatusCode.Created,
new ChannelUpdateRequest
{
RemoveFilterTags = filterTags,
Message = msg,
});
},
cancellationToken: cancellationToken);
}
}
49 changes: 29 additions & 20 deletions src/Clients/ChannelClient.Members.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using StreamChat.Models;
using StreamChat.Rest;
Expand All @@ -11,7 +12,10 @@ public partial class ChannelClient
public async Task<UpdateChannelResponse> AddMembersAsync(string channelType, string channelId, params string[] userIds)
=> await AddMembersAsync(channelType, channelId, userIds, null, null);

public async Task<UpdateChannelResponse> AddMembersAsync(string channelType, string channelId, IEnumerable<string> userIds, MessageRequest msg, AddMemberOptions options)
public async Task<UpdateChannelResponse> AddMembersAsync(string channelType, string channelId, string[] userIds, CancellationToken cancellationToken = default)
=> await AddMembersAsync(channelType, channelId, userIds, null, null, cancellationToken);

public async Task<UpdateChannelResponse> AddMembersAsync(string channelType, string channelId, IEnumerable<string> userIds, MessageRequest msg, AddMemberOptions options, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<UpdateChannelResponse>($"channels/{channelType}/{channelId}",
HttpMethod.POST,
HttpStatusCode.Created,
Expand All @@ -21,61 +25,66 @@ public async Task<UpdateChannelResponse> AddMembersAsync(string channelType, str
HideHistory = options?.HideHistory,
HideHistoryBefore = options?.HideHistoryBefore,
Message = msg,
});
},
cancellationToken: cancellationToken);

public async Task<ApiResponse> RemoveMembersAsync(string channelType, string channelId, IEnumerable<string> userIds, MessageRequest msg = null)
public async Task<ApiResponse> RemoveMembersAsync(string channelType, string channelId, IEnumerable<string> userIds, MessageRequest msg = null, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<ApiResponse>($"channels/{channelType}/{channelId}",
HttpMethod.POST,
HttpStatusCode.Created,
new ChannelUpdateRequest
{
RemoveMembers = userIds,
Message = msg,
});
},
cancellationToken: cancellationToken);

public async Task<ChannelMemberResponse> UpdateMemberPartialAsync(string channelType, string channelId, ChannelMemberPartialRequest channelMemberPartialRequest)
public async Task<ChannelMemberResponse> UpdateMemberPartialAsync(string channelType, string channelId, ChannelMemberPartialRequest channelMemberPartialRequest, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<ChannelMemberResponse>($"channels/{channelType}/{channelId}/member/{channelMemberPartialRequest.UserId}",
HttpMethod.PATCH,
HttpStatusCode.OK,
channelMemberPartialRequest);
channelMemberPartialRequest,
cancellationToken: cancellationToken);

public async Task<QueryMembersResponse> QueryMembersAsync(QueryMembersRequest queryMembersRequest)
public async Task<QueryMembersResponse> QueryMembersAsync(QueryMembersRequest queryMembersRequest, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<QueryMembersResponse>("members",
HttpMethod.GET,
HttpStatusCode.OK,
queryParams: queryMembersRequest.ToQueryParameters());
queryParams: queryMembersRequest.ToQueryParameters(),
cancellationToken: cancellationToken);

public async Task<UpdateChannelResponse> AssignRolesAsync(string channelType, string channelId, AssignRoleRequest roleRequest)
public async Task<UpdateChannelResponse> AssignRolesAsync(string channelType, string channelId, AssignRoleRequest roleRequest, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<UpdateChannelResponse>($"channels/{channelType}/{channelId}",
HttpMethod.POST,
HttpStatusCode.Created,
roleRequest);
roleRequest,
cancellationToken: cancellationToken);

public async Task<UpdateChannelResponse> InviteAsync(string channelType, string channelId, string userId, MessageRequest msg = null)
=> await InviteAsync(channelType, channelId, new[] { userId }, msg);
public async Task<UpdateChannelResponse> InviteAsync(string channelType, string channelId, string userId, MessageRequest msg = null, CancellationToken cancellationToken = default)
=> await InviteAsync(channelType, channelId, new[] { userId }, msg, cancellationToken);

public async Task<UpdateChannelResponse> InviteAsync(string channelType, string channelId, IEnumerable<string> userIds)
=> await InviteAsync(channelType, channelId, userIds, null);
public async Task<UpdateChannelResponse> InviteAsync(string channelType, string channelId, IEnumerable<string> userIds, CancellationToken cancellationToken = default)
=> await InviteAsync(channelType, channelId, userIds, null, cancellationToken);

public async Task<UpdateChannelResponse> InviteAsync(string channelType, string channelId, IEnumerable<string> userIds, MessageRequest msg = null)
public async Task<UpdateChannelResponse> InviteAsync(string channelType, string channelId, IEnumerable<string> userIds, MessageRequest msg = null, CancellationToken cancellationToken = default)
=> await UpdateAsync(channelType, channelId, new ChannelUpdateRequest
{
Invites = userIds,
Message = msg,
});
}, cancellationToken);

public async Task<UpdateChannelResponse> AcceptInviteAsync(string channelType, string channelId, string userId)
public async Task<UpdateChannelResponse> AcceptInviteAsync(string channelType, string channelId, string userId, CancellationToken cancellationToken = default)
=> await UpdateAsync(channelType, channelId, new ChannelUpdateRequest
{
AcceptInvite = true,
UserId = userId,
});
}, cancellationToken);

public async Task<UpdateChannelResponse> RejectInviteAsync(string channelType, string channelId, string userId)
public async Task<UpdateChannelResponse> RejectInviteAsync(string channelType, string channelId, string userId, CancellationToken cancellationToken = default)
=> await UpdateAsync(channelType, channelId, new ChannelUpdateRequest
{
RejectInvite = true,
UserId = userId,
});
}, cancellationToken);
}
}
21 changes: 13 additions & 8 deletions src/Clients/ChannelClient.Moderation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using StreamChat.Models;
using StreamChat.Rest;
Expand All @@ -8,28 +9,32 @@ namespace StreamChat.Clients
{
public partial class ChannelClient
{
public async Task<ApiResponse> AddModeratorsAsync(string channelType, string channelId, IEnumerable<string> userIds)
public async Task<ApiResponse> AddModeratorsAsync(string channelType, string channelId, IEnumerable<string> userIds, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<ApiResponse>($"channels/{channelType}/{channelId}",
HttpMethod.POST,
HttpStatusCode.Created,
new { add_moderators = userIds });
new { add_moderators = userIds },
cancellationToken: cancellationToken);

public async Task<ApiResponse> DemoteModeratorsAsync(string channelType, string channelId, IEnumerable<string> userIds)
public async Task<ApiResponse> DemoteModeratorsAsync(string channelType, string channelId, IEnumerable<string> userIds, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<ApiResponse>($"channels/{channelType}/{channelId}",
HttpMethod.POST,
HttpStatusCode.Created,
new { demote_moderators = userIds });
new { demote_moderators = userIds },
cancellationToken: cancellationToken);

public async Task<ChannelMuteResponse> MuteChannelAsync(ChannelMuteRequest request)
public async Task<ChannelMuteResponse> MuteChannelAsync(ChannelMuteRequest request, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<ChannelMuteResponse>("moderation/mute/channel",
HttpMethod.POST,
HttpStatusCode.Created,
request);
request,
cancellationToken: cancellationToken);

public async Task<ChannelUnmuteResponse> UnmuteChannelAsync(ChannelUnmuteRequest request)
public async Task<ChannelUnmuteResponse> UnmuteChannelAsync(ChannelUnmuteRequest request, CancellationToken cancellationToken = default)
=> await ExecuteRequestAsync<ChannelUnmuteResponse>("moderation/unmute/channel",
HttpMethod.POST,
HttpStatusCode.Created,
request);
request,
cancellationToken: cancellationToken);
}
}
Loading