[MOD/WIP] Separate DB entries for the txns
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:
LDA 2024-08-17 01:08:09 +02:00
parent dc0e463c27
commit 4918932a0e

View file

@ -977,39 +977,57 @@ HashMap *
UserGetTransaction(User *user, char *transaction, char *path) UserGetTransaction(User *user, char *transaction, char *path)
{ {
HashMap *devices; HashMap *devices;
DbRef *ref;
if (!user || !transaction || !path) if (!user || !transaction || !path)
{ {
return NULL; return NULL;
} }
devices = JsonValueAsObject( ref = DbLock(user->db,
HashMapGet(UserGetDevices(user), UserGetDeviceId(user)) 4,
"users", user->name,
"txns", UserGetDeviceId(user)
); );
return JsonDuplicate(JsonValueAsObject( devices = DbJson(ref);
JsonGet(devices, 3, "transactions", path, transaction) devices = JsonValueAsObject(JsonGet(devices, 2, path, transaction));
)); devices = JsonDuplicate(devices);
DbUnlock(user->db, ref);
return devices;
} }
void void
UserSetTransaction(User *user, char *transaction, char *path, HashMap *resp) UserSetTransaction(User *user, char *transaction, char *path, HashMap *resp)
{ {
HashMap *devices; HashMap *devices;
DbRef *ref;
if (!user || !transaction || !path || !resp) if (!user || !transaction || !path || !resp)
{ {
return; return;
} }
devices = JsonValueAsObject( if (!(ref = DbLock(user->db,
HashMapGet(UserGetDevices(user), UserGetDeviceId(user)) 4,
); "users", user->name,
"txns", UserGetDeviceId(user)
)))
{
ref = DbCreate(user->db,
4,
"users", user->name,
"txns", UserGetDeviceId(user)
);
}
devices = DbJson(ref);
/* Overwrite the transaction */ /* Overwrite the transaction */
JsonValueFree(JsonSet( JsonValueFree(JsonSet(
devices, JsonValueObject(JsonDuplicate(resp)), devices, JsonValueObject(JsonDuplicate(resp)),
3, "transactions", path, transaction 2, path, transaction
)); ));
DbUnlock(user->db, ref);
} }
void void
UserAddInvite(User *user, char *roomId) UserAddInvite(User *user, char *roomId)