forked from Telodendria/Telodendria
[MOD/WIP] Try separating joins from the main ref
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
Still need to do that for transactions, as that will easily bloat up.
This commit is contained in:
parent
5e15d73c44
commit
57651df1c7
1 changed files with 24 additions and 29 deletions
53
src/User.c
53
src/User.c
|
@ -43,6 +43,8 @@ struct User
|
||||||
Db *db;
|
Db *db;
|
||||||
DbRef *ref;
|
DbRef *ref;
|
||||||
|
|
||||||
|
DbRef *inviteRef, *joinRef;
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
char *deviceId;
|
char *deviceId;
|
||||||
};
|
};
|
||||||
|
@ -193,7 +195,9 @@ UserUnlock(User * user)
|
||||||
Free(user->name);
|
Free(user->name);
|
||||||
Free(user->deviceId);
|
Free(user->deviceId);
|
||||||
|
|
||||||
ret = DbUnlock(db, ref);
|
ret = DbUnlock(db, ref) &&
|
||||||
|
DbUnlock(db, user->joinRef) &&
|
||||||
|
DbUnlock(db, user->inviteRef);
|
||||||
user->db = NULL;
|
user->db = NULL;
|
||||||
user->ref = NULL;
|
user->ref = NULL;
|
||||||
Free(user);
|
Free(user);
|
||||||
|
@ -211,7 +215,10 @@ UserCreate(Db * db, char *name, char *password)
|
||||||
|
|
||||||
/* TODO: Put some sort of password policy(like for example at least
|
/* TODO: Put some sort of password policy(like for example at least
|
||||||
* 8 chars, or maybe check it's entropy)? */
|
* 8 chars, or maybe check it's entropy)? */
|
||||||
if (!db || (name && UserExists(db, name)) || !password || !strlen(password))
|
if (!db ||
|
||||||
|
(name && UserExists(db, name)) ||
|
||||||
|
!password ||
|
||||||
|
!strlen(password))
|
||||||
{
|
{
|
||||||
/* User exists or cannot be registered, therefore, do NOT
|
/* User exists or cannot be registered, therefore, do NOT
|
||||||
* bother */
|
* bother */
|
||||||
|
@ -246,8 +253,8 @@ UserCreate(Db * db, char *name, char *password)
|
||||||
HashMapSet(json, "createdOn", JsonValueInteger(ts));
|
HashMapSet(json, "createdOn", JsonValueInteger(ts));
|
||||||
HashMapSet(json, "deactivated", JsonValueBoolean(false));
|
HashMapSet(json, "deactivated", JsonValueBoolean(false));
|
||||||
|
|
||||||
HashMapSet(json, "invites", JsonValueObject(HashMapCreate()));
|
user->inviteRef = DbCreate(db, 3, "users", user->name, "invites");
|
||||||
HashMapSet(json, "joins", JsonValueObject(HashMapCreate()));
|
user->joinRef = DbCreate(db, 3, "users", user->name, "joins");
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
@ -1005,49 +1012,43 @@ void
|
||||||
UserAddInvite(User *user, char *roomId)
|
UserAddInvite(User *user, char *roomId)
|
||||||
{
|
{
|
||||||
HashMap *data;
|
HashMap *data;
|
||||||
HashMap *invites;
|
|
||||||
if (!user || !roomId)
|
if (!user || !roomId)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = DbJson(user->ref);
|
data = DbJson(user->inviteRef);
|
||||||
invites = JsonValueAsObject(HashMapGet(data, "invites"));
|
|
||||||
|
|
||||||
JsonFree(HashMapSet(invites, roomId, JsonValueNull()));
|
JsonFree(HashMapSet(data, roomId, JsonValueNull()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
UserRemoveInvite(User *user, char *roomId)
|
UserRemoveInvite(User *user, char *roomId)
|
||||||
{
|
{
|
||||||
HashMap *data;
|
HashMap *data;
|
||||||
HashMap *invites;
|
|
||||||
if (!user || !roomId)
|
if (!user || !roomId)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = DbJson(user->ref);
|
data = DbJson(user->inviteRef);
|
||||||
invites = JsonValueAsObject(HashMapGet(data, "invites"));
|
|
||||||
|
|
||||||
JsonFree(HashMapDelete(invites, roomId));
|
JsonFree(HashMapDelete(data, roomId));
|
||||||
}
|
}
|
||||||
Array *
|
Array *
|
||||||
UserListInvites(User *user)
|
UserListInvites(User *user)
|
||||||
{
|
{
|
||||||
Array *arr;
|
Array *arr;
|
||||||
HashMap *data;
|
HashMap *data;
|
||||||
HashMap *invites;
|
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
if (!user)
|
if (!user)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
data = DbJson(user->ref);
|
|
||||||
invites = JsonValueAsObject(HashMapGet(data, "invites"));
|
|
||||||
arr = HashMapKeys(invites);
|
|
||||||
|
|
||||||
|
data = DbJson(user->inviteRef);
|
||||||
|
arr = HashMapKeys(data);
|
||||||
for (i = 0; i < ArraySize(arr); i++)
|
for (i = 0; i < ArraySize(arr); i++)
|
||||||
{
|
{
|
||||||
ArraySet(arr, i, StrDuplicate(ArrayGet(arr, i)));
|
ArraySet(arr, i, StrDuplicate(ArrayGet(arr, i)));
|
||||||
|
@ -1060,18 +1061,16 @@ void
|
||||||
UserAddJoin(User *user, char *roomId)
|
UserAddJoin(User *user, char *roomId)
|
||||||
{
|
{
|
||||||
HashMap *data;
|
HashMap *data;
|
||||||
HashMap *joins;
|
|
||||||
if (!user || !roomId)
|
if (!user || !roomId)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = DbJson(user->ref);
|
data = DbJson(user->joinRef);
|
||||||
joins = JsonValueAsObject(HashMapGet(data, "joins"));
|
|
||||||
|
|
||||||
if (!HashMapGet(joins, roomId))
|
if (!HashMapGet(data, roomId))
|
||||||
{
|
{
|
||||||
JsonFree(HashMapSet(joins, roomId, JsonValueNull()));
|
JsonFree(HashMapSet(data, roomId, JsonValueNull()));
|
||||||
}
|
}
|
||||||
UserNotifyUser(user);
|
UserNotifyUser(user);
|
||||||
}
|
}
|
||||||
|
@ -1080,16 +1079,14 @@ void
|
||||||
UserRemoveJoin(User *user, char *roomId)
|
UserRemoveJoin(User *user, char *roomId)
|
||||||
{
|
{
|
||||||
HashMap *data;
|
HashMap *data;
|
||||||
HashMap *joins;
|
|
||||||
if (!user || !roomId)
|
if (!user || !roomId)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = DbJson(user->ref);
|
data = DbJson(user->joinRef);
|
||||||
joins = JsonValueAsObject(HashMapGet(data, "joins"));
|
|
||||||
|
|
||||||
JsonFree(HashMapDelete(joins, roomId));
|
JsonFree(HashMapDelete(data, roomId));
|
||||||
UserNotifyUser(user);
|
UserNotifyUser(user);
|
||||||
}
|
}
|
||||||
Array *
|
Array *
|
||||||
|
@ -1097,16 +1094,14 @@ UserListJoins(User *user)
|
||||||
{
|
{
|
||||||
Array *arr;
|
Array *arr;
|
||||||
HashMap *data;
|
HashMap *data;
|
||||||
HashMap *joins;
|
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
if (!user)
|
if (!user)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
data = DbJson(user->ref);
|
data = DbJson(user->joinRef);
|
||||||
joins = JsonValueAsObject(HashMapGet(data, "joins"));
|
arr = HashMapKeys(data);
|
||||||
arr = HashMapKeys(joins);
|
|
||||||
|
|
||||||
for (i = 0; i < ArraySize(arr); i++)
|
for (i = 0; i < ArraySize(arr); i++)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue