Skip to content

Commit

Permalink
Add set Avatar to room functions
Browse files Browse the repository at this point in the history
  • Loading branch information
DevTown committed Mar 2, 2024
1 parent fa44acd commit 254e938
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ public record ChangeNameRequest(string? name)
{
public string? name { get; } = name;
}

public record ChangeAvatarRequest(string? url)
{
public string? url { get; } = url;
}
}
14 changes: 14 additions & 0 deletions Matrix.Sdk/Core/Infrastructure/Services/RoomService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,19 @@ public async Task<string> GetRoomNameAsync(string accessToken, string roomId, Ca

return await httpClient.PutAsJsonAsync<EventResponse>(path, model, cancellationToken);
}

public async Task<EventResponse> SetAvatarAsync(string accessToken,
string roomId,
string url, CancellationToken cancellationToken)
{
const string eventType = "m.room.avatar";
var model = new ChangeAvatarRequest(url);

HttpClient httpClient = CreateHttpClient(accessToken);

var path = $"{ResourcePath}/rooms/{roomId}/state/{eventType}";

return await httpClient.PutAsJsonAsync<EventResponse>(path, model, cancellationToken);
}
}
}
1 change: 1 addition & 0 deletions Matrix.Sdk/IMatrixClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public interface IMatrixClient
Task<string> GetRoomName(string id);
Task<EventResponse> SetRoomTopicAsync(string roomId, string topic);
Task<EventResponse> SetRoomNameAsync(string roomId, string name);
Task<EventResponse> SetRoomAvatarAsync(string roomId, string url);
Task<MatrixProfile> GetUserProfile(string fullUserId);
Task<byte[]> GetMxcImage(string mxcUrl);
}
Expand Down
6 changes: 5 additions & 1 deletion Matrix.Sdk/MatrixClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ public async Task<EventResponse> SetRoomTopicAsync(string roomId, string topic)
var transactionId = CreateTransactionId();
return await _roomService.SetTopicAsync(_accessToken!, roomId, topic, _cts.Token);
}

public async Task<EventResponse> SetRoomAvatarAsync(string roomId, string url)
{
var transactionId = CreateTransactionId();
return await _roomService.SetAvatarAsync(_accessToken!, roomId, url, _cts.Token);
}
public async Task<EventResponse> SetRoomNameAsync(string roomId, string name)
{
var transactionId = CreateTransactionId();
Expand Down

0 comments on commit 254e938

Please sign in to comment.