Fix build issues with #28 (#55)

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:
lda 2024-08-21 14:32:42 -04:00 committed by Jordan Bancino
parent ac9372a30a
commit e263eca5dc

View file

@ -45,7 +45,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
Db *db = args->matrixArgs->db;
Config *config = NULL;
Config config = { .ok = 0 };
User *user = NULL;
@ -60,7 +60,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
(void) path;
dirRequest.search_term = NULL;
dirRequest.limit = Int64Create(0, 10);
dirRequest.limit = 10;
if (HttpRequestMethodGet(args->context) != HTTP_POST)
@ -116,17 +116,17 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
* local server. */
users = DbList(db, 1, "users");
config = ConfigLock(db);
if (!config)
ConfigLock(db, &config);
if (!config.ok)
{
Log(LOG_ERR, "Directory endpoint failed to lock configuration.");
HttpResponseStatus(args->context, HTTP_INTERNAL_SERVER_ERROR);
response = MatrixErrorCreate(M_UNKNOWN, NULL);
response = MatrixErrorCreate(M_UNKNOWN, config.err);
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++)
#undef IncludedLtLimit
{
@ -168,7 +168,7 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
}
if (name)
{
char *uID = StrConcat(4, "@", name, ":", config->serverName);
char *uID = StrConcat(4, "@", name, ":", config.serverName);
JsonSet(obj, JsonValueString(uID), 1, "user_id");
Free(uID);
}
@ -184,15 +184,16 @@ ROUTE_IMPL(RouteUserDirectory, path, argp)
}
}
JsonSet(response, JsonValueArray(results), 1, "results");
JsonSet(response, JsonValueBoolean(
Int64Eq(Int64Create(0, included), dirRequest.limit)), 1,
"limited");
JsonSet(response,
JsonValueBoolean((int64_t) included == dirRequest.limit),
1, "limited"
);
finish:
UserUnlock(user);
JsonFree(request);
DbListFree(users);
ConfigUnlock(config);
ConfigUnlock(&config);
UserDirectoryRequestFree(&dirRequest);
return response;
}