mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 21:35:10 +00:00
[ADD/WIP] Continue MUCwerk
oh man this is gonna be painful to do... xmpp is fine iff youre doing DMs isnt it?
This commit is contained in:
parent
3ac11fd269
commit
d3b7f2fee0
19 changed files with 707 additions and 44 deletions
|
|
@ -1,8 +1,11 @@
|
|||
#include <Routes.h>
|
||||
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Log.h>
|
||||
#include <Cytoplasm/Str.h>
|
||||
|
||||
#include <Matrix.h>
|
||||
#include <XMPP.h>
|
||||
#include <AS.h>
|
||||
|
||||
RouteHead(RouteUserAck, arr, argp)
|
||||
|
|
@ -43,8 +46,13 @@ RouteHead(RouteRoomAck, arr, argp)
|
|||
HashMap *response = NULL;
|
||||
Array *events;
|
||||
size_t i;
|
||||
MUCInfo info = { .exists = false };
|
||||
|
||||
char *room = ArrayGet(arr, 0), *muc = NULL, *id = NULL;
|
||||
char *creator = NULL, *muc_name = NULL, *chatid = NULL;
|
||||
|
||||
Log(LOG_INFO, "Ack");
|
||||
|
||||
char *room = ArrayGet(arr, 0);
|
||||
response = ASVerifyRequest(args);
|
||||
if (response)
|
||||
{
|
||||
|
|
@ -60,14 +68,70 @@ RouteHead(RouteRoomAck, arr, argp)
|
|||
goto end;
|
||||
}
|
||||
|
||||
Log(LOG_INFO, "room=%s", room);
|
||||
|
||||
HttpResponseStatus(args->ctx, HTTP_METHOD_NOT_ALLOWED);
|
||||
response = MatrixCreateError(
|
||||
"M_UNRECOGNIZED",
|
||||
"Path /users only accepts GET as a valid method."
|
||||
muc = ParseeDecodeLocalMUC(args->data->config, room);
|
||||
Log(LOG_INFO, "room=%s", muc);
|
||||
if (!XMPPQueryMUC(args->data->jabber, muc, &info))
|
||||
{
|
||||
HttpResponseStatus(args->ctx, HTTP_METHOD_NOT_ALLOWED);
|
||||
response = MatrixCreateError(
|
||||
"M_UNRECOGNIZED",
|
||||
"Room does not map to a real XMPP MUC"
|
||||
);
|
||||
Log(LOG_INFO, "No MUC");
|
||||
goto end;
|
||||
}
|
||||
creator = StrConcat(
|
||||
4,
|
||||
"@", args->data->config->sender_localpart, ":",
|
||||
args->data->config->homeserver_host
|
||||
);
|
||||
id = ASCreateRoom(
|
||||
args->data->config,
|
||||
creator, room
|
||||
);
|
||||
if (!id)
|
||||
{
|
||||
Log(LOG_INFO, "No ID");
|
||||
HttpResponseStatus(args->ctx, HTTP_INTERNAL_SERVER_ERROR);
|
||||
response = MatrixCreateError(
|
||||
"M_UNKNOWN",
|
||||
"Could not create the room."
|
||||
);
|
||||
goto end;
|
||||
}
|
||||
muc_name = XMPPGetMUCName(info);
|
||||
if (muc_name)
|
||||
{
|
||||
ASSetState(
|
||||
args->data->config, id, "m.room.name", "", creator,
|
||||
MatrixCreateNameState(muc_name)
|
||||
);
|
||||
Free(muc_name);
|
||||
}
|
||||
|
||||
/* Creates a mapping */
|
||||
chatid = ParseePushMUC(args->data, id, muc);
|
||||
Log(LOG_INFO, "Chat ID=%s", chatid);
|
||||
|
||||
response = HashMapCreate();
|
||||
end:
|
||||
if (chatid)
|
||||
{
|
||||
Free(chatid);
|
||||
}
|
||||
if (muc)
|
||||
{
|
||||
Free(muc);
|
||||
}
|
||||
if (id)
|
||||
{
|
||||
Free(id);
|
||||
}
|
||||
if (creator)
|
||||
{
|
||||
Free(creator);
|
||||
}
|
||||
XMPPFreeMUCInfo(info);
|
||||
JsonFree(request);
|
||||
return response;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue