From 1d0a7e62f2e6438bc9d1cdac78910f5b5ea42829 Mon Sep 17 00:00:00 2001 From: LDA Date: Sat, 23 Nov 2024 14:20:32 +0100 Subject: [PATCH] [FIX] Make Telodendria play ball with Schildi The web versions worked fine, but the old Android ones tend to be strict, which is a great tool for testing. --- Schema/SyncResponse.json | 2 +- src/Routes/RouteMessages.c | 13 +++++++++++++ src/Routes/RouteSync.c | 16 +--------------- src/User.c | 7 +------ 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/Schema/SyncResponse.json b/Schema/SyncResponse.json index 364e25c..c074f00 100644 --- a/Schema/SyncResponse.json +++ b/Schema/SyncResponse.json @@ -29,7 +29,7 @@ }, "States": { "fields": { - "events": { "type": "[StrippedStateEvent]" } + "events": { "type": "array" } }, "type": "struct" }, diff --git a/src/Routes/RouteMessages.c b/src/Routes/RouteMessages.c index 8ba3f9b..47efa36 100644 --- a/src/Routes/RouteMessages.c +++ b/src/Routes/RouteMessages.c @@ -60,6 +60,8 @@ ROUTE_IMPL(RouteMessages, path, argp) int limit = strtol(limitStr, NULL, 10); Array *messages = NULL; + Array *state = NULL; + size_t i; Room *room = NULL; @@ -136,7 +138,18 @@ ROUTE_IMPL(RouteMessages, path, argp) Free(startId); } response = HashMapCreate(); + state = ArrayCreate(); JsonSet(response, JsonValueArray(messages), 1, "chunk"); + for (i = 0; i < ArraySize(messages); i++) + { + HashMap *e = JsonValueAsObject(ArrayGet(messages, i)); + if (HashMapGet(e, "state_key")) + { + ArrayAdd(state, JsonValueDuplicate(ArrayGet(messages, i))); + } + } + JsonSet(response, JsonValueArray(state), 1, "state"); + JsonSet(response, JsonValueString(from), 1, "start"); if (end) { JsonSet(response, JsonValueString(end), 1, "end"); diff --git a/src/Routes/RouteSync.c b/src/Routes/RouteSync.c index 0434991..3343078 100644 --- a/src/Routes/RouteSync.c +++ b/src/Routes/RouteSync.c @@ -50,15 +50,6 @@ ClientfyEventSync(HashMap *pdu) return ret; } -static StrippedStateEvent -StripStateEventSync(HashMap *pdu) -{ - StrippedStateEvent ret = { 0 }; - char *ignored; - StrippedStateEventFromJson(pdu, &ret, &ignored); - - return ret; -} ROUTE_IMPL(RouteSync, path, argp) { @@ -245,13 +236,8 @@ ROUTE_IMPL(RouteSync, path, argp) while (StateIterate(state, &type, &key, (void **) &id)) { HashMap *e = RoomEventFetch(r, id, true); - StrippedStateEvent rs = StripStateEventSync(e); - StrippedStateEvent *s = Malloc(sizeof(*s)); - memcpy(s, &rs, sizeof(*s)); - JsonFree(e); - - ArrayAdd(joined->state.events, s); + ArrayAdd(joined->state.events, JsonValueObject(e)); Free(type); Free(key); } diff --git a/src/User.c b/src/User.c index 75a20fd..ffef0c9 100644 --- a/src/User.c +++ b/src/User.c @@ -1318,13 +1318,11 @@ UserPushAccountData(User *user, char *key) JsonValueFree(HashMapSet(join, key, JsonValueObject(accountEntry) )); - Log(LOG_INFO, "user=%s's batch=%s", user->name, entry); } DbUnlock(user->db, syncRef); } DbListFree(entries); - Log(LOG_INFO, "You have notified the '%s' about key=%s", user->name, key); UserNotifyUser(user->name); } void @@ -1461,8 +1459,6 @@ UserFillSyncDiff(User *user, char *batch) return; } - Log(LOG_WARNING, "This is an initial sync."); - joins = UserListJoins(user); syncRef = DbLock( user->db, 4, "users", user->name, "sync", batch @@ -1744,8 +1740,7 @@ UserFetchMessages(User *user, int n, char *token, char **next) bool toFree = true; - /* Push event into our message list. - * TODO: Check if the user has the right to see the event/room. */ + /* Push event into our message list, and check if we can use it */ if (RoomIsEventVisible(room, user, curr)) { ArrayAdd(messages, event);