forked from Telodendria/Telodendria
[MOD/WIP] Start work for event sending
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
b0c3d6ce31
commit
39c4af8d4d
7 changed files with 196 additions and 10 deletions
18
src/Room.c
18
src/Room.c
|
@ -2034,3 +2034,21 @@ RoomGetDB(Room *room)
|
||||||
}
|
}
|
||||||
return room->db;
|
return room->db;
|
||||||
}
|
}
|
||||||
|
bool
|
||||||
|
RoomContainsUser(Room *room, char *user)
|
||||||
|
{
|
||||||
|
HashMap *state;
|
||||||
|
bool ret;
|
||||||
|
if (!room || !user)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
state = StateCurrent(room);
|
||||||
|
|
||||||
|
ret = RoomUserHasMembership(room, state, user, "join");
|
||||||
|
|
||||||
|
StateFree(state);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
57
src/Routes.c
57
src/Routes.c
|
@ -91,6 +91,63 @@ RouterBuild(void)
|
||||||
R("/_telodendria/admin/v1/tokens/(.*)", RouteAdminTokens);
|
R("/_telodendria/admin/v1/tokens/(.*)", RouteAdminTokens);
|
||||||
R("/_telodendria/admin/v1/tokens", RouteAdminTokens);
|
R("/_telodendria/admin/v1/tokens", RouteAdminTokens);
|
||||||
|
|
||||||
|
R("/_matrix/client/r0/capabilities", RouteCapabilities);
|
||||||
|
R("/_matrix/client/r0/login", RouteLogin);
|
||||||
|
R("/_matrix/client/r0/logout", RouteLogout);
|
||||||
|
R("/_matrix/client/r0/logout/(all)", RouteLogout);
|
||||||
|
R("/_matrix/client/r0/register", RouteRegister);
|
||||||
|
R("/_matrix/client/r0/register/(available)", RouteRegister);
|
||||||
|
R("/_matrix/client/r0/refresh", RouteRefresh);
|
||||||
|
|
||||||
|
R("/_matrix/client/r0/account/whoami", RouteWhoami);
|
||||||
|
R("/_matrix/client/r0/account/password", RouteChangePwd);
|
||||||
|
R("/_matrix/client/r0/account/deactivate", RouteDeactivate);
|
||||||
|
|
||||||
|
R("/_matrix/client/v1/register/m.login.registration_token/validity", RouteTokenValid);
|
||||||
|
|
||||||
|
R("/_matrix/client/r0/account/password/(email|msisdn)/requestToken", RouteRequestToken);
|
||||||
|
R("/_matrix/client/r0/register/(email|msisdn)/requestToken", RouteRequestToken);
|
||||||
|
|
||||||
|
R("/_matrix/client/r0/profile/(.*)", RouteUserProfile);
|
||||||
|
R("/_matrix/client/r0/profile/(.*)/(avatar_url|displayname)", RouteUserProfile);
|
||||||
|
|
||||||
|
R("/_matrix/client/r0/user/(.*)/filter", RouteFilter);
|
||||||
|
R("/_matrix/client/r0/user/(.*)/filter/(.*)", RouteFilter);
|
||||||
|
|
||||||
|
R("/_matrix/client/r0/createRoom", RouteCreateRoom);
|
||||||
|
|
||||||
|
R("/_matrix/client/r0/directory/room/(.*)", RouteAliasDirectory);
|
||||||
|
R("/_matrix/client/r0/rooms/(.*)/aliases", RouteRoomAliases);
|
||||||
|
|
||||||
|
|
||||||
|
R("/_matrix/client/v3/capabilities", RouteCapabilities);
|
||||||
|
R("/_matrix/client/v3/login", RouteLogin);
|
||||||
|
R("/_matrix/client/v3/logout", RouteLogout);
|
||||||
|
R("/_matrix/client/v3/logout/(all)", RouteLogout);
|
||||||
|
R("/_matrix/client/v3/register", RouteRegister);
|
||||||
|
R("/_matrix/client/v3/register/(available)", RouteRegister);
|
||||||
|
R("/_matrix/client/v3/refresh", RouteRefresh);
|
||||||
|
|
||||||
|
R("/_matrix/client/v3/account/whoami", RouteWhoami);
|
||||||
|
R("/_matrix/client/v3/account/password", RouteChangePwd);
|
||||||
|
R("/_matrix/client/v3/account/deactivate", RouteDeactivate);
|
||||||
|
|
||||||
|
R("/_matrix/client/v1/register/m.login.registration_token/validity", RouteTokenValid);
|
||||||
|
|
||||||
|
R("/_matrix/client/v3/account/password/(email|msisdn)/requestToken", RouteRequestToken);
|
||||||
|
R("/_matrix/client/v3/register/(email|msisdn)/requestToken", RouteRequestToken);
|
||||||
|
|
||||||
|
R("/_matrix/client/v3/profile/(.*)", RouteUserProfile);
|
||||||
|
R("/_matrix/client/v3/profile/(.*)/(avatar_url|displayname)", RouteUserProfile);
|
||||||
|
|
||||||
|
R("/_matrix/client/v3/user/(.*)/filter", RouteFilter);
|
||||||
|
R("/_matrix/client/v3/user/(.*)/filter/(.*)", RouteFilter);
|
||||||
|
|
||||||
|
R("/_matrix/client/v3/createRoom", RouteCreateRoom);
|
||||||
|
|
||||||
|
R("/_matrix/client/v3/directory/room/(.*)", RouteAliasDirectory);
|
||||||
|
R("/_matrix/client/v3/rooms/(.*)/aliases", RouteRoomAliases);
|
||||||
|
|
||||||
#undef R
|
#undef R
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
|
|
71
src/State.c
71
src/State.c
|
@ -237,6 +237,23 @@ StateResolveV2(Array * states)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HashMap *
|
||||||
|
StateFromPrevs(Room *room, Array *states)
|
||||||
|
{
|
||||||
|
HashMap *ret_state;
|
||||||
|
switch (RoomVersionGet(room))
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
ret_state = StateResolveV1(room, states);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ret_state = StateResolveV2(states);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret_state;
|
||||||
|
}
|
||||||
|
|
||||||
HashMap *
|
HashMap *
|
||||||
StateResolve(Room * room, HashMap * event)
|
StateResolve(Room * room, HashMap * event)
|
||||||
{
|
{
|
||||||
|
@ -303,16 +320,7 @@ StateResolve(Room * room, HashMap * event)
|
||||||
JsonFree(prevEvent);
|
JsonFree(prevEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret_state = NULL;
|
ret_state = StateFromPrevs(room, states);
|
||||||
switch (RoomVersionGet(room))
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
ret_state = StateResolveV1(room, states);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ret_state = StateResolveV2(states);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < ArraySize(states); i++)
|
for (i = 0; i < ArraySize(states); i++)
|
||||||
{
|
{
|
||||||
|
@ -332,6 +340,49 @@ StateResolve(Room * room, HashMap * event)
|
||||||
|
|
||||||
return ret_state;
|
return ret_state;
|
||||||
}
|
}
|
||||||
|
HashMap *
|
||||||
|
StateCurrent(Room *room)
|
||||||
|
{
|
||||||
|
Array *prevEvents;
|
||||||
|
Array *states;
|
||||||
|
size_t i;
|
||||||
|
HashMap *ret;
|
||||||
|
if (!room)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
prevEvents = RoomPrevEventsGet(room);
|
||||||
|
states = ArrayCreate();
|
||||||
|
for (i = 0; i < ArraySize(prevEvents); i++)
|
||||||
|
{
|
||||||
|
HashMap *event =
|
||||||
|
RoomEventFetch(room, JsonValueAsString(ArrayGet(prevEvents, i)));
|
||||||
|
HashMap *state = StateResolve(room, event);
|
||||||
|
|
||||||
|
if (HashMapGet(event, "state_key"))
|
||||||
|
{
|
||||||
|
StateSet(
|
||||||
|
state,
|
||||||
|
JsonValueAsString(HashMapGet(event, "type")),
|
||||||
|
JsonValueAsString(HashMapGet(event, "state_key")),
|
||||||
|
JsonValueAsString(HashMapGet(event, "event_id")));
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayAdd(states, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = StateFromPrevs(room, states);
|
||||||
|
|
||||||
|
for (i = 0; i < ArraySize(states); i++)
|
||||||
|
{
|
||||||
|
HashMap *state = ArrayGet(states, i);
|
||||||
|
StateFree(state);
|
||||||
|
}
|
||||||
|
ArrayFree(states);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
bool StateIterate(HashMap *state, char **type, char **key, void **event)
|
bool StateIterate(HashMap *state, char **type, char **key, void **event)
|
||||||
{
|
{
|
||||||
char *tuple;
|
char *tuple;
|
||||||
|
|
39
src/User.c
39
src/User.c
|
@ -945,3 +945,42 @@ UserIdFree(CommonID * id)
|
||||||
Free(id);
|
Free(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HashMap *
|
||||||
|
UserGetTransaction(User *user, char *transaction, char *path)
|
||||||
|
{
|
||||||
|
HashMap *devices;
|
||||||
|
|
||||||
|
if (!user || !transaction || !path)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
devices = JsonValueAsObject(
|
||||||
|
HashMapGet(UserGetDevices(user), UserGetDeviceId(user))
|
||||||
|
);
|
||||||
|
|
||||||
|
return JsonDuplicate(JsonValueAsObject(
|
||||||
|
JsonGet(devices, 3, "transactions", path, transaction)
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UserSetTransaction(User *user, char *transaction, char *path, HashMap *resp)
|
||||||
|
{
|
||||||
|
HashMap *devices;
|
||||||
|
if (!user || !transaction || !path || !resp)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
devices = JsonValueAsObject(
|
||||||
|
HashMapGet(UserGetDevices(user), UserGetDeviceId(user))
|
||||||
|
);
|
||||||
|
|
||||||
|
/* Overwrite the transaction */
|
||||||
|
JsonValueFree(JsonSet(
|
||||||
|
devices, JsonValueObject(JsonDuplicate(resp)),
|
||||||
|
3, "transactions", path, transaction
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
|
@ -206,6 +206,11 @@ extern Array * RoomReverseAlias(Db *, char *);
|
||||||
*/
|
*/
|
||||||
extern void RoomFreeReverse(Array *);
|
extern void RoomFreeReverse(Array *);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whenever a room contains a specific user.
|
||||||
|
*/
|
||||||
|
extern bool RoomContainsUser(Room *, char *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds or overwrites a room alias.
|
* Adds or overwrites a room alias.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -63,6 +63,11 @@ extern bool StateIterate(HashMap *, char **, char **, void **);
|
||||||
*/
|
*/
|
||||||
extern HashMap * StateResolve(Room *, HashMap *);
|
extern HashMap * StateResolve(Room *, HashMap *);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes the current state from the room's leaves.
|
||||||
|
*/
|
||||||
|
extern HashMap * StateCurrent(Room *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frees an entire state table from the heap.
|
* Frees an entire state table from the heap.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -303,6 +303,17 @@ extern int UserDecodePrivilege(const char *);
|
||||||
*/
|
*/
|
||||||
extern CommonID * UserIdParse(char *, char *);
|
extern CommonID * UserIdParse(char *, char *);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the reply sent to the user from a transaction ID, and an opaque
|
||||||
|
* ""path"" ID, which is unique per route.
|
||||||
|
*/
|
||||||
|
extern HashMap * UserGetTransaction(User *, char *, char *);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores a transaction for a path with a given response JSON.
|
||||||
|
*/
|
||||||
|
extern void UserSetTransaction(User *, char *, char *, HashMap *);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frees the user's common ID and the memory allocated for it.
|
* Frees the user's common ID and the memory allocated for it.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue