microsoft/teams.net
Publicmirrored from https://github.com/microsoft/teams.netAvailable
core/src/Microsoft.Teams.Apps/Api/Clients/MemberClient.cs
84lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Teams.Apps.Schema; |
| 5 | using Microsoft.Teams.Core; |
| 6 | using Microsoft.Teams.Core.Schema; |
| 7 | |
| 8 | using CoreConversationClient = Microsoft.Teams.Core.ConversationClient; |
| 9 | |
| 10 | namespace Microsoft.Teams.Apps.Api.Clients; |
| 11 | |
| 12 | /// <summary> |
| 13 | /// Client for managing conversation members. |
| 14 | /// Delegates to the core <see cref="CoreConversationClient"/>. |
| 15 | /// </summary> |
| 16 | public class MemberClient |
| 17 | { |
| 18 | private readonly CoreConversationClient _client; |
| 19 | private readonly Uri _serviceUrl; |
| 20 | |
| 21 | internal MemberClient(Uri serviceUrl, CoreConversationClient client) |
| 22 | { |
| 23 | _serviceUrl = serviceUrl; |
| 24 | _client = client; |
| 25 | } |
| 26 | |
| 27 | /// <summary> |
| 28 | /// Get all members of a conversation. |
| 29 | /// </summary> |
| 30 | [Obsolete("Use GetPagedAsync instead.")] |
| 31 | public async Task<IList<TeamsConversationAccount?>> GetAsync(string conversationId, AgenticIdentity? agenticIdentity = null, Dictionary<string, string>? additionalHeaders = null, CancellationToken cancellationToken = default) |
| 32 | { |
| 33 | IList<ConversationAccount> members = await _client.GetConversationMembersAsync(conversationId, _serviceUrl, agenticIdentity: agenticIdentity, customHeaders: additionalHeaders, cancellationToken: cancellationToken).ConfigureAwait(false); |
| 34 | return [.. members.Select(m => TeamsConversationAccount.FromConversationAccount(m))]; |
| 35 | } |
| 36 | |
| 37 | /// <summary> |
| 38 | /// Get members of a conversation with pagination support. |
| 39 | /// </summary> |
| 40 | public async Task<PagedTeamsMembersResult> GetPagedAsync( |
| 41 | string conversationId, |
| 42 | int pageSize = 50, |
| 43 | string? continuationToken = null, |
| 44 | AgenticIdentity? agenticIdentity = null, |
| 45 | Dictionary<string, string>? additionalHeaders = null, |
| 46 | CancellationToken cancellationToken = default) |
| 47 | { |
| 48 | PagedMembersResult? paged = await _client.GetConversationPagedMembersAsync( |
| 49 | conversationId, |
| 50 | _serviceUrl, |
| 51 | pageSize, |
| 52 | continuationToken, |
| 53 | agenticIdentity: agenticIdentity, |
| 54 | customHeaders: additionalHeaders, |
| 55 | cancellationToken: cancellationToken).ConfigureAwait(false); |
| 56 | PagedTeamsMembersResult result = new(); |
| 57 | if (paged is not null) |
| 58 | { |
| 59 | result.ContinuationToken = paged.ContinuationToken; |
| 60 | if (paged.Members is not null) |
| 61 | { |
| 62 | result.Members = [.. paged.Members.Select(m => TeamsConversationAccount.FromConversationAccount(m))]; |
| 63 | } |
| 64 | } |
| 65 | return result; |
| 66 | } |
| 67 | |
| 68 | /// <summary> |
| 69 | /// Get a specific member of a conversation by ID. |
| 70 | /// </summary> |
| 71 | public Task<T> GetByIdAsync<T>(string conversationId, string memberId, AgenticIdentity? agenticIdentity = null, Dictionary<string, string>? additionalHeaders = null, CancellationToken cancellationToken = default) where T : ConversationAccount |
| 72 | { |
| 73 | return _client.GetConversationMemberAsync<T>(conversationId, memberId, _serviceUrl, agenticIdentity: agenticIdentity, customHeaders: additionalHeaders, cancellationToken: cancellationToken); |
| 74 | } |
| 75 | |
| 76 | /// <summary> |
| 77 | /// Get a specific member of a conversation by ID. |
| 78 | /// </summary> |
| 79 | public async Task<TeamsConversationAccount?> GetByIdAsync(string conversationId, string memberId, AgenticIdentity? agenticIdentity = null, Dictionary<string, string>? additionalHeaders = null, CancellationToken cancellationToken = default) |
| 80 | { |
| 81 | ConversationAccount member = await GetByIdAsync<ConversationAccount>(conversationId, memberId, agenticIdentity, additionalHeaders, cancellationToken).ConfigureAwait(false); |
| 82 | return TeamsConversationAccount.FromConversationAccount(member); |
| 83 | } |
| 84 | } |
| 85 | |