forked from Telodendria/Telodendria
[MOD] Use keyed schemas for the sync
Some checks are pending
Compile Telodendria / Compile Telodendria (x86, alpine-v3.19) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, debian-v12.4) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, freebsd-v14.0) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, netbsd-v9.3) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, alpine-v3.19) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, debian-v12.4) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, freebsd-v14.0) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, netbsd-v9.3) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, openbsd-v7.4) (push) Waiting to run
Some checks are pending
Compile Telodendria / Compile Telodendria (x86, alpine-v3.19) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, debian-v12.4) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, freebsd-v14.0) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86, netbsd-v9.3) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, alpine-v3.19) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, debian-v12.4) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, freebsd-v14.0) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, netbsd-v9.3) (push) Waiting to run
Compile Telodendria / Compile Telodendria (x86_64, openbsd-v7.4) (push) Waiting to run
This commit is contained in:
parent
0a45cebbfe
commit
dfb950bc7f
3 changed files with 23 additions and 25 deletions
|
@ -88,8 +88,8 @@
|
|||
},
|
||||
"Rooms": {
|
||||
"fields": {
|
||||
"invite": { "type": "object" },
|
||||
"join": { "type": "object" }
|
||||
"invite": { "type": "{InvitedRooms}" },
|
||||
"join": { "type": "{JoinedRooms}" }
|
||||
},
|
||||
"type": "struct"
|
||||
},
|
||||
|
|
|
@ -155,22 +155,19 @@ ROUTE_IMPL(RouteSync, path, argp)
|
|||
for (i = 0; i < ArraySize(invites); i++)
|
||||
{
|
||||
char *roomId = ArrayGet(invites, i);
|
||||
InvitedRooms invited = { 0 };
|
||||
HashMap *invitedObject;
|
||||
InvitedRooms *invited;
|
||||
|
||||
if (IsRoomFiltered(filterData, roomId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
invited.invite_state.events = ArrayCreate();
|
||||
invitedObject = InvitedRoomsToJson(&invited);
|
||||
JsonSet(
|
||||
sync.rooms.invite,
|
||||
JsonValueObject(invitedObject),
|
||||
1, roomId
|
||||
);
|
||||
InvitedRoomsFree(&invited);
|
||||
invited = Malloc(sizeof(*invited));
|
||||
memset(invited, 0, sizeof(*invited));
|
||||
|
||||
/* TODO: Populate the invitestate */
|
||||
invited->invite_state.events = ArrayCreate();
|
||||
HashMapSet(sync.rooms.invite, roomId, invited);
|
||||
}
|
||||
UserFreeList(invites);
|
||||
|
||||
|
@ -180,10 +177,9 @@ ROUTE_IMPL(RouteSync, path, argp)
|
|||
{
|
||||
/* TODO: Rename these variables */
|
||||
char *roomId = ArrayGet(joins, i);
|
||||
JoinedRooms joined = { 0 };
|
||||
JoinedRooms *joined;
|
||||
char *firstEvent = NULL;
|
||||
char *type, *key, *id;
|
||||
HashMap *joinedObj;
|
||||
State *state;
|
||||
Array *el;
|
||||
size_t j;
|
||||
|
@ -194,12 +190,14 @@ ROUTE_IMPL(RouteSync, path, argp)
|
|||
continue;
|
||||
}
|
||||
|
||||
joined = Malloc(sizeof(*joined));
|
||||
memset(joined, 0, sizeof(*joined));
|
||||
|
||||
el = UserGetEvents(user, currBatch, roomId);
|
||||
r = RoomLock(db, roomId);
|
||||
state = StateCurrent(r);
|
||||
|
||||
joined.timeline.events = ArrayCreate();
|
||||
|
||||
joined->timeline.events = ArrayCreate();
|
||||
for (j = 0; j < ArraySize(el); j++)
|
||||
{
|
||||
char *event = ArrayGet(el, j);
|
||||
|
@ -217,18 +215,18 @@ ROUTE_IMPL(RouteSync, path, argp)
|
|||
firstEvent = c->event_id;
|
||||
}
|
||||
|
||||
ArrayAdd(joined.timeline.events, c);
|
||||
ArrayAdd(joined->timeline.events, c);
|
||||
}
|
||||
|
||||
JsonFree(eventObj);
|
||||
JsonFree(filteredObj);
|
||||
}
|
||||
joined.timeline.prev_batch = UserNewMessageToken(
|
||||
joined->timeline.prev_batch = UserNewMessageToken(
|
||||
user, roomId, firstEvent
|
||||
);
|
||||
/* TODO: Don't shove the entire state.
|
||||
* That's a recipe for disaster, especially on large rooms. */
|
||||
joined.state.events = ArrayCreate();
|
||||
joined->state.events = ArrayCreate();
|
||||
while (StateIterate(state, &type, &key, (void **) &id))
|
||||
{
|
||||
HashMap *e = RoomEventFetch(r, id);
|
||||
|
@ -238,7 +236,7 @@ ROUTE_IMPL(RouteSync, path, argp)
|
|||
|
||||
JsonFree(e);
|
||||
|
||||
ArrayAdd(joined.state.events, s);
|
||||
ArrayAdd(joined->state.events, s);
|
||||
Free(type);
|
||||
Free(key);
|
||||
}
|
||||
|
@ -247,9 +245,7 @@ ROUTE_IMPL(RouteSync, path, argp)
|
|||
RoomUnlock(r);
|
||||
UserFreeList(el);
|
||||
|
||||
joinedObj = JoinedRoomsToJson(&joined);
|
||||
HashMapSet(sync.rooms.join, roomId, JsonValueObject(joinedObj));
|
||||
JoinedRoomsFree(&joined);
|
||||
HashMapSet(sync.rooms.join, roomId, joined);
|
||||
}
|
||||
UserFreeList(joins);
|
||||
|
||||
|
|
|
@ -77,10 +77,12 @@ V1Cmp(void *a, void *b)
|
|||
JsonValueAsString(JsonGet(e1, 1, "event_id"));
|
||||
char *e2id =
|
||||
JsonValueAsString(JsonGet(e2, 1, "event_id"));
|
||||
|
||||
/* Matrix, *seriously*? */
|
||||
unsigned char *sha1 = Sha1(e1id);
|
||||
unsigned char *sha2 = Sha1(e2id);
|
||||
char *str1 = ShaToHex(sha1);
|
||||
char *str2 = ShaToHex(sha2);
|
||||
char *str1 = ShaToHex(sha1, HASH_SHA1);
|
||||
char *str2 = ShaToHex(sha2, HASH_SHA1);
|
||||
int ret = strcmp(str1, str2) * -1;
|
||||
|
||||
Free(str1);
|
||||
|
|
Loading…
Reference in a new issue