forked from lda/telodendria
Just here to fix old code issues with #28. (we really need CI back, don't we?) --- Please review the developer certificate of origin: 1. The contribution was created in whole or in part by me, and I have the right to submit it under the open source licenses of the Telodendria project; or 1. The contribution is based upon a previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the Telodendria project license; or 1. The contribution was provided directly to me by some other person who certified (1), (2), or (3), and I have not modified it. 1. I understand and agree that this project and the contribution are made public and that a record of the contribution—including all personal information I submit with it—is maintained indefinitely and may be redistributed consistent with this project or the open source licenses involved. - [x] I have read the Telodendria Project development certificate of origin, and I certify that I have permission to submit this patch under the conditions specified in it. Co-authored-by: LDA <lda@ari.lt> Reviewed-on: Telodendria/Telodendria#55 Co-authored-by: lda <lda@freetards.xyz> Co-committed-by: lda <lda@freetards.xyz>
This commit is contained in:
parent
ac9372a30a
commit
e263eca5dc
1 changed files with 12 additions and 11 deletions
|
@ -45,7 +45,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
|
||||||
|
|
||||||
Db *db = args->matrixArgs->db;
|
Db *db = args->matrixArgs->db;
|
||||||
|
|
||||||
Config *config = NULL;
|
Config config = { .ok = 0 };
|
||||||
|
|
||||||
User *user = NULL;
|
User *user = NULL;
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
|
||||||
(void) path;
|
(void) path;
|
||||||
|
|
||||||
dirRequest.search_term = NULL;
|
dirRequest.search_term = NULL;
|
||||||
dirRequest.limit = Int64Create(0, 10);
|
dirRequest.limit = 10;
|
||||||
|
|
||||||
|
|
||||||
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
if (HttpRequestMethodGet(args->context) != HTTP_POST)
|
||||||
|
@ -116,17 +116,17 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
|
||||||
* local server. */
|
* local server. */
|
||||||
users = DbList(db, 1, "users");
|
users = DbList(db, 1, "users");
|
||||||
|
|
||||||
config = ConfigLock(db);
|
ConfigLock(db, &config);
|
||||||
if (!config)
|
if (!config.ok)
|
||||||
{
|
{
|
||||||
Log(LOG_ERR, "Directory endpoint failed to lock configuration.");
|
Log(LOG_ERR, "Directory endpoint failed to lock configuration.");
|
||||||
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
|
||||||
response = MatrixErrorCreate(M_UNKNOWN, NULL);
|
response = MatrixErrorCreate(M_UNKNOWN, config.err);
|
||||||
|
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define IncludedLtLimit (Int64Lt(Int64Create(0, included), dirRequest.limit))
|
#define IncludedLtLimit ((int64_t) included < dirRequest.limit)
|
||||||
for (i = 0, included = 0; i < ArraySize(users) && IncludedLtLimit; i++)
|
for (i = 0, included = 0; i < ArraySize(users) && IncludedLtLimit; i++)
|
||||||
#undef IncludedLtLimit
|
#undef IncludedLtLimit
|
||||||
{
|
{
|
||||||
|
@ -168,7 +168,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
|
||||||
}
|
}
|
||||||
if (name)
|
if (name)
|
||||||
{
|
{
|
||||||
char *uID = StrConcat(4, "@", name, ":", config->serverName);
|
char *uID = StrConcat(4, "@", name, ":", config.serverName);
|
||||||
JsonSet(obj, JsonValueString(uID), 1, "user_id");
|
JsonSet(obj, JsonValueString(uID), 1, "user_id");
|
||||||
Free(uID);
|
Free(uID);
|
||||||
}
|
}
|
||||||
|
@ -184,15 +184,16 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JsonSet(response, JsonValueArray(results), 1, "results");
|
JsonSet(response, JsonValueArray(results), 1, "results");
|
||||||
JsonSet(response, JsonValueBoolean(
|
JsonSet(response,
|
||||||
Int64Eq(Int64Create(0, included), dirRequest.limit)), 1,
|
JsonValueBoolean((int64_t) included == dirRequest.limit),
|
||||||
"limited");
|
1, "limited"
|
||||||
|
);
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
UserUnlock(user);
|
UserUnlock(user);
|
||||||
JsonFree(request);
|
JsonFree(request);
|
||||||
DbListFree(users);
|
DbListFree(users);
|
||||||
ConfigUnlock(config);
|
ConfigUnlock(&config);
|
||||||
UserDirectoryRequestFree(&dirRequest);
|
UserDirectoryRequestFree(&dirRequest);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue