about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKayra Uylar <k.uylar@outlook.com>2025-04-01 13:05:47 +0300
committerRory& <root@rory.gay>2025-04-01 12:36:11 +0200
commit7a834ccefb3572762e6aeeafb4206c57acc34116 (patch)
tree439ec97984418e7bcb42e1c8164fbdecaeff06b1
parentPropagate more HTTP errors, sync error handling callback (diff)
downloadLibMatrix-7a834ccefb3572762e6aeeafb4206c57acc34116.tar.xz
Add methods for typing notifications and read receipts
-rw-r--r--LibMatrix/RoomTypes/GenericRoom.cs35
1 files changed, 35 insertions, 0 deletions
diff --git a/LibMatrix/RoomTypes/GenericRoom.cs b/LibMatrix/RoomTypes/GenericRoom.cs

index 55fa42c..f8a3ff8 100644 --- a/LibMatrix/RoomTypes/GenericRoom.cs +++ b/LibMatrix/RoomTypes/GenericRoom.cs
@@ -455,6 +455,41 @@ public class GenericRoom { #endregion +#region Ephemeral Events + + /// <summary> + /// This tells the server that the user is typing for the next N milliseconds where + /// N is the value specified in the timeout key. Alternatively, if typing is false, + /// it tells the server that the user has stopped typing. + /// </summary> + /// <param name="typing">Whether the user is typing or not.</param> + /// <param name="timeout">The length of time in milliseconds to mark this user as typing.</param> + public async Task SendTypingNotificationAsync(bool typing, int timeout = 30000) { + await Homeserver.ClientHttpClient.PutAsJsonAsync( + $"/_matrix/client/v3/rooms/{RoomId}/typing/{Homeserver.UserId}", new JsonObject { + ["timeout"] = typing ? timeout : null, + ["typing"] = typing + }, new JsonSerializerOptions { + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull + }); + } + + /// <summary> + /// Updates the marker for the given receipt type to the event ID specified. + /// </summary> + public async Task SendReadReceiptAsync(string eventId, string? threadId = null, bool isPrivate = false) { + var request = new JsonObject(); + if (threadId != null) + request.Add("thread_id", threadId); + await Homeserver.ClientHttpClient.PostAsJsonAsync( + $"/_matrix/client/v3/rooms/{RoomId}/receipt/m.read{(isPrivate ? ".private" : "")}/{eventId}", request, + new JsonSerializerOptions { + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull + }); + } + +#endregion + #region Utilities public async Task<Dictionary<string, List<string>>> GetMembersByHomeserverAsync(bool joinedOnly = true) {