microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
docs/update-release-process

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.Api/Clients/MemberClient.cs

95lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4using Microsoft.Teams.Common.Http;
5
6namespace Microsoft.Teams.Api.Clients;
7
8public class MemberClient : Client
9{
10 public readonly string ServiceUrl;
11
12 public MemberClient(string serviceUrl, CancellationToken cancellationToken = default) : base(cancellationToken)
13 {
14 ServiceUrl = serviceUrl;
15 }
16
17 public MemberClient(string serviceUrl, IHttpClient client, CancellationToken cancellationToken = default) : base(client, cancellationToken)
18 {
19 ServiceUrl = serviceUrl;
20 }
21
22 public MemberClient(string serviceUrl, IHttpClientOptions options, CancellationToken cancellationToken = default) : base(options, cancellationToken)
23 {
24 ServiceUrl = serviceUrl;
25 }
26
27 public MemberClient(string serviceUrl, IHttpClientFactory factory, CancellationToken cancellationToken = default) : base(factory, cancellationToken)
28 {
29 ServiceUrl = serviceUrl;
30 }
31
32 [Obsolete("Use GetPagedAsync instead.")]
33 public async Task<List<Account>> GetAsync(string conversationId, CancellationToken cancellationToken = default)
34 {
35 var token = cancellationToken != default ? cancellationToken : _cancellationToken;
36 var request = HttpRequest.Get($"{ServiceUrl}v3/conversations/{conversationId}/members");
37 var response = await _http.SendAsync<List<Account>>(request, token).ConfigureAwait(false);
38 foreach (var account in response.Body)
39 {
40 if (string.IsNullOrEmpty(account.AadObjectId) && !string.IsNullOrEmpty(account.ObjectId))
41 {
42 account.AadObjectId = account.ObjectId;
43 }
44 }
45 return response.Body;
46 }
47
48 public async Task<PagedMembersResult> GetPagedAsync(string conversationId, int? pageSize = null, string? continuationToken = null, CancellationToken cancellationToken = default)
49 {
50 var token = cancellationToken != default ? cancellationToken : _cancellationToken;
51 var url = $"{ServiceUrl}v3/conversations/{conversationId}/pagedmembers";
52 var queryParts = new List<string>();
53 if (pageSize.HasValue)
54 {
55 queryParts.Add($"pageSize={pageSize.Value}");
56 }
57 if (continuationToken is not null)
58 {
59 queryParts.Add($"continuationToken={Uri.EscapeDataString(continuationToken)}");
60 }
61 if (queryParts.Count > 0)
62 {
63 url = $"{url}?{string.Join("&", queryParts)}";
64 }
65 var request = HttpRequest.Get(url);
66 var response = await _http.SendAsync<PagedMembersResult>(request, token).ConfigureAwait(false);
67 if (response.Body.Members is not null)
68 {
69 foreach (var account in response.Body.Members)
70 {
71 if (string.IsNullOrEmpty(account.AadObjectId) && !string.IsNullOrEmpty(account.ObjectId))
72 {
73 account.AadObjectId = account.ObjectId;
74 }
75 }
76 }
77 return response.Body;
78 }
79
80 public async Task<Account> GetByIdAsync(string conversationId, string memberId, CancellationToken cancellationToken = default)
81 {
82 var token = cancellationToken != default ? cancellationToken : _cancellationToken;
83 var request = HttpRequest.Get($"{ServiceUrl}v3/conversations/{conversationId}/members/{memberId}");
84 var response = await _http.SendAsync<Account>(request, token).ConfigureAwait(false);
85 return response.Body;
86 }
87
88 [Obsolete("This will be removed by end of summer 2026.")]
89 public async Task DeleteAsync(string conversationId, string memberId, CancellationToken cancellationToken = default)
90 {
91 var token = cancellationToken != default ? cancellationToken : _cancellationToken;
92 var request = HttpRequest.Delete($"{ServiceUrl}v3/conversations/{conversationId}/members/{memberId}");
93 await _http.SendAsync(request, token).ConfigureAwait(false);
94 }
95}