forked from Telodendria/Telodendria
[MOD] Modify join/invite lists to be lazy
Some checks failed
Compile Telodendria / Compile Telodendria (x86, alpine-v3.19) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, debian-v12.4) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, freebsd-v14.0) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, netbsd-v9.3) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, alpine-v3.19) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, debian-v12.4) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, freebsd-v14.0) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, netbsd-v9.3) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, openbsd-v7.4) (push) Has been cancelled
Some checks failed
Compile Telodendria / Compile Telodendria (x86, alpine-v3.19) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, debian-v12.4) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, freebsd-v14.0) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86, netbsd-v9.3) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, alpine-v3.19) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, debian-v12.4) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, freebsd-v14.0) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, netbsd-v9.3) (push) Has been cancelled
Compile Telodendria / Compile Telodendria (x86_64, openbsd-v7.4) (push) Has been cancelled
This commit is contained in:
parent
620cf91ba0
commit
a77be8b437
1 changed files with 46 additions and 13 deletions
59
src/User.c
59
src/User.c
|
@ -130,15 +130,8 @@ UserLock(Db * db, char *name)
|
|||
user->name = StrDuplicate(name);
|
||||
user->deviceId = NULL;
|
||||
|
||||
if (!(user->inviteRef = DbLock(db, 3, "users", user->name, "invites")))
|
||||
{
|
||||
user->inviteRef = DbCreate(db, 3, "users", user->name, "invites");
|
||||
}
|
||||
if (!(user->joinRef = DbLock(db, 3, "users", user->name, "joins")))
|
||||
{
|
||||
user->joinRef = DbCreate(db, 3, "users", user->name, "joins");
|
||||
}
|
||||
|
||||
user->inviteRef = NULL;
|
||||
user->joinRef = NULL;
|
||||
return user;
|
||||
}
|
||||
|
||||
|
@ -1040,6 +1033,7 @@ void
|
|||
UserAddInvite(User *user, char *roomId)
|
||||
{
|
||||
HashMap *data;
|
||||
Db *db = user ? user->db : NULL;
|
||||
if (!user || !roomId)
|
||||
{
|
||||
return;
|
||||
|
@ -1047,9 +1041,10 @@ UserAddInvite(User *user, char *roomId)
|
|||
|
||||
if (!user->inviteRef)
|
||||
{
|
||||
user->inviteRef = DbCreate(user->db,
|
||||
3, "users", user->name, "invites"
|
||||
);
|
||||
if (!(user->inviteRef = DbLock(db, 3, "users", user->name, "invites")))
|
||||
{
|
||||
user->inviteRef = DbCreate(db, 3, "users", user->name, "invites");
|
||||
}
|
||||
}
|
||||
|
||||
data = DbJson(user->inviteRef);
|
||||
|
@ -1061,11 +1056,19 @@ void
|
|||
UserRemoveInvite(User *user, char *roomId)
|
||||
{
|
||||
HashMap *data;
|
||||
Db *db = user ? user->db : NULL;
|
||||
if (!user || !roomId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user->inviteRef)
|
||||
{
|
||||
if (!(user->inviteRef = DbLock(db, 3, "users", user->name, "invites")))
|
||||
{
|
||||
user->inviteRef = DbCreate(db, 3, "users", user->name, "invites");
|
||||
}
|
||||
}
|
||||
data = DbJson(user->inviteRef);
|
||||
|
||||
JsonValueFree(HashMapDelete(data, roomId));
|
||||
|
@ -1075,6 +1078,7 @@ UserListInvites(User *user)
|
|||
{
|
||||
Array *arr;
|
||||
HashMap *data;
|
||||
Db *db = user ? user->db : NULL;
|
||||
|
||||
size_t i;
|
||||
if (!user)
|
||||
|
@ -1082,6 +1086,13 @@ UserListInvites(User *user)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (!user->inviteRef)
|
||||
{
|
||||
if (!(user->inviteRef = DbLock(db, 3, "users", user->name, "invites")))
|
||||
{
|
||||
user->inviteRef = DbCreate(db, 3, "users", user->name, "invites");
|
||||
}
|
||||
}
|
||||
data = DbJson(user->inviteRef);
|
||||
arr = HashMapKeys(data);
|
||||
for (i = 0; i < ArraySize(arr); i++)
|
||||
|
@ -1096,6 +1107,7 @@ void
|
|||
UserAddJoin(User *user, char *roomId)
|
||||
{
|
||||
HashMap *data;
|
||||
Db *db = user ? user->db : NULL;
|
||||
if (!user || !roomId)
|
||||
{
|
||||
return;
|
||||
|
@ -1103,7 +1115,10 @@ UserAddJoin(User *user, char *roomId)
|
|||
|
||||
if (!user->joinRef)
|
||||
{
|
||||
user->joinRef = DbCreate(user->db, 3, "users", user->name, "joins");
|
||||
if (!(user->joinRef = DbLock(db, 3, "users", user->name, "joins")))
|
||||
{
|
||||
user->joinRef = DbCreate(db, 3, "users", user->name, "joins");
|
||||
}
|
||||
}
|
||||
|
||||
data = DbJson(user->joinRef);
|
||||
|
@ -1116,11 +1131,20 @@ void
|
|||
UserRemoveJoin(User *user, char *roomId)
|
||||
{
|
||||
HashMap *data;
|
||||
Db *db = user ? user->db : NULL;
|
||||
if (!user || !roomId || !user->joinRef)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user->joinRef)
|
||||
{
|
||||
if (!(user->joinRef = DbLock(db, 3, "users", user->name, "joins")))
|
||||
{
|
||||
user->joinRef = DbCreate(db, 3, "users", user->name, "joins");
|
||||
}
|
||||
}
|
||||
|
||||
data = DbJson(user->joinRef);
|
||||
|
||||
JsonValueFree(HashMapDelete(data, roomId));
|
||||
|
@ -1131,12 +1155,21 @@ UserListJoins(User *user)
|
|||
{
|
||||
Array *arr;
|
||||
HashMap *data;
|
||||
Db *db = user ? user->db : NULL;
|
||||
|
||||
size_t i;
|
||||
if (!user)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (!user->joinRef)
|
||||
{
|
||||
if (!(user->joinRef = DbLock(db, 3, "users", user->name, "joins")))
|
||||
{
|
||||
user->joinRef = DbCreate(db, 3, "users", user->name, "joins");
|
||||
}
|
||||
}
|
||||
|
||||
data = DbJson(user->joinRef);
|
||||
arr = HashMapKeys(data);
|
||||
|
||||
|
|
Loading…
Reference in a new issue