about summary refs log tree commit diff
path: root/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs
diff options
context:
space:
mode:
authorEmma [it/its]@Rory& <root@rory.gay>2024-02-23 12:33:45 +0100
committerEmma [it/its]@Rory& <root@rory.gay>2024-02-23 12:33:55 +0100
commitc7b7dbe3d929d787fe0c76015082a117c4222278 (patch)
treedb765a9655f875d751f061e1000e199dd209d841 /LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs
parentHS emulator (diff)
downloadLibMatrix-c7b7dbe3d929d787fe0c76015082a117c4222278.tar.xz
Unknown changes
Diffstat (limited to 'LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs')
-rw-r--r--LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs24
1 files changed, 22 insertions, 2 deletions
diff --git a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs
index 02f3e3a..1c93235 100644
--- a/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs
+++ b/LibMatrix/Homeservers/AuthenticatedHomeserverGeneric.cs
@@ -295,6 +295,27 @@ public class AuthenticatedHomeserverGeneric(string serverName, string accessToke
     }
 
     public async Task<FilterIdResponse> UploadFilterAsync(SyncFilter filter) {
+        List<List<string>?> senderLists = [
+            filter.AccountData?.Senders,
+            filter.AccountData?.NotSenders,
+            filter.Presence?.Senders,
+            filter.Presence?.NotSenders,
+            filter.Room?.AccountData?.Senders,
+            filter.Room?.AccountData?.NotSenders,
+            filter.Room?.Ephemeral?.Senders,
+            filter.Room?.Ephemeral?.NotSenders,
+            filter.Room?.State?.Senders,
+            filter.Room?.State?.NotSenders,
+            filter.Room?.Timeline?.Senders,
+            filter.Room?.Timeline?.NotSenders
+        ];
+        
+        foreach (var list in senderLists)
+            if (list is { Count: > 0 } && list.Contains("@me")) {
+                list.Remove("@me");
+                list.Add(UserId);
+            }
+        
         var resp = await ClientHttpClient.PostAsJsonAsync("/_matrix/client/v3/user/" + UserId + "/filter", filter);
         return await resp.Content.ReadFromJsonAsync<FilterIdResponse>() ?? throw new Exception("Failed to upload filter?");
     }
@@ -327,8 +348,7 @@ public class AuthenticatedHomeserverGeneric(string serverName, string accessToke
     /// <returns>Filter ID response</returns>
     /// <exception cref="Exception"></exception>
     public async Task<FilterIdResponse> UploadNamedFilterAsync(string filterName, SyncFilter filter) {
-        var resp = await ClientHttpClient.PostAsJsonAsync("/_matrix/client/v3/user/" + UserId + "/filter", filter);
-        var idResp = await resp.Content.ReadFromJsonAsync<FilterIdResponse>() ?? throw new Exception("Failed to upload filter?");
+        var idResp = await UploadFilterAsync(filter);
 
         var filterList = await GetNamedFilterListOrNullAsync() ?? new Dictionary<string, string>();
         filterList[filterName] = idResp.FilterId;