From 7a834ccefb3572762e6aeeafb4206c57acc34116 Mon Sep 17 00:00:00 2001 From: Kayra Uylar Date: Tue, 1 Apr 2025 13:05:47 +0300 Subject: Add methods for typing notifications and read receipts --- LibMatrix/RoomTypes/GenericRoom.cs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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 + + /// + /// 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. + /// + /// Whether the user is typing or not. + /// The length of time in milliseconds to mark this user as typing. + 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 + }); + } + + /// + /// Updates the marker for the given receipt type to the event ID specified. + /// + 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>> GetMembersByHomeserverAsync(bool joinedOnly = true) { -- cgit 1.5.1