mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 18:25:10 +00:00
[ADD/WIP] Start having MUCwork half-decent
Still lots of things required(like using the users JIDs whenever possible, otherwise dropping to occupant ID), images, replies, rich data with HTML and whatever XMPP has, etc...
This commit is contained in:
parent
d3b7f2fee0
commit
a84ce05b9d
12 changed files with 329 additions and 40 deletions
|
|
@ -13,7 +13,7 @@
|
|||
#include <AS.h>
|
||||
|
||||
|
||||
static pthread_mutex_t cond_var_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t cond_var_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_cond_t cond_var = PTHREAD_COND_INITIALIZER;
|
||||
|
||||
void
|
||||
|
|
@ -27,7 +27,6 @@ ParseeWakeupThread(void)
|
|||
static void
|
||||
ParseeDMHandler(char *room, char *from, XMLElement *data, const ParseeConfig *c)
|
||||
{
|
||||
Log(LOG_INFO, "Trying to send %s %s", room, from);
|
||||
ASSend(
|
||||
c, room, from,
|
||||
"m.room.message", MatrixCreateMessage(data->data)
|
||||
|
|
@ -42,9 +41,9 @@ ParseeXMPPThread(void *argp)
|
|||
XMLElement *stanza = NULL;
|
||||
while (true)
|
||||
{
|
||||
/* TODO: pthread cancelation points */
|
||||
XMLElement *body = NULL;
|
||||
XMLElement *data = NULL;
|
||||
XMLElement *stanza_id = NULL;
|
||||
char *to, *room, *from, *from_matrix;
|
||||
char *chat_id, *mroom_id;
|
||||
|
||||
|
|
@ -59,7 +58,7 @@ ParseeXMPPThread(void *argp)
|
|||
XMLFreeElement(stanza);
|
||||
continue;
|
||||
}
|
||||
if (StrEquals(stanza->name, "message"))
|
||||
else if (StrEquals(stanza->name, "message"))
|
||||
{
|
||||
size_t i;
|
||||
if (XMPPIsKiller(stanza))
|
||||
|
|
@ -69,7 +68,6 @@ ParseeXMPPThread(void *argp)
|
|||
from = HashMapGet(stanza->attrs, "from");
|
||||
if (!strncmp(from, killer, strlen(killer)))
|
||||
{
|
||||
Log(LOG_INFO, "Dropping thread...");
|
||||
XMLFreeElement(stanza);
|
||||
break;
|
||||
}
|
||||
|
|
@ -82,40 +80,50 @@ ParseeXMPPThread(void *argp)
|
|||
continue;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < ArraySize(stanza->children); i++)
|
||||
{
|
||||
XMLElement *child = ArrayGet(stanza->children, i);
|
||||
if (StrEquals(child->name, "body"))
|
||||
{
|
||||
body = child;
|
||||
break;
|
||||
}
|
||||
}
|
||||
body = XMLookForUnique(stanza, "body");
|
||||
if (!body)
|
||||
{
|
||||
XMLFreeElement(stanza);
|
||||
continue;
|
||||
}
|
||||
stanza_id = XMLookForUnique(stanza, "stanza-id");
|
||||
|
||||
/* TODO: Check the type */
|
||||
to = ParseeDecodeMXID(HashMapGet(stanza->attrs, "to"));
|
||||
from = HashMapGet(stanza->attrs, "from");
|
||||
from_matrix = ParseeEncodeJID(args->config, from);
|
||||
from_matrix = ParseeEncodeJID(args->config, from, true);
|
||||
room = ParseeFindDMRoom(args, to, from);
|
||||
data = ArrayGet(body->children, 0);
|
||||
|
||||
/* TODO: Consider having rich messages */
|
||||
/* TODO: Consider having rich messages, and move that out
|
||||
* to separate functions */
|
||||
chat_id = ParseeGetFromMUCID(args, from);
|
||||
mroom_id = ParseeGetRoomID(args, chat_id);
|
||||
if (room)
|
||||
{
|
||||
ParseeDMHandler(room, from_matrix, data, args->config);
|
||||
}
|
||||
if (mroom_id)
|
||||
if (mroom_id && !ParseeIsJabberPuppet(args->config, from))
|
||||
{
|
||||
Log(LOG_INFO, "Send to %s", mroom_id);
|
||||
/* TODO: Grab username, create a puppet, and go from
|
||||
* there */
|
||||
char *res = ParseeGetResource(from);
|
||||
char *encoded = ParseeEncodeJID(args->config, from, false);
|
||||
char *s_id_str = HashMapGet(stanza_id->attrs, "id");
|
||||
|
||||
/* TODO: Create smarter puppet names, and send presence
|
||||
* in every room at Parsee's bootup. */
|
||||
if (ParseeVerifyStanza(args, chat_id, s_id_str))
|
||||
{
|
||||
ASRegisterUser(args->config, encoded);
|
||||
ASJoin(args->config, mroom_id, encoded);
|
||||
ASSetName(args->config, encoded, res);
|
||||
ASSend(
|
||||
args->config, mroom_id, encoded,
|
||||
"m.room.message", MatrixCreateMessage(data->data)
|
||||
);
|
||||
ParseePushStanza(args, chat_id, s_id_str);
|
||||
}
|
||||
|
||||
Free(res);
|
||||
Free(encoded);
|
||||
}
|
||||
Free(chat_id);
|
||||
Free(mroom_id);
|
||||
|
|
@ -123,6 +131,13 @@ ParseeXMPPThread(void *argp)
|
|||
Free(room);
|
||||
Free(to);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(LOG_WARNING, "Unknown stanza '%s':", stanza->name);
|
||||
XMLEncode(StreamStdout(), stanza);
|
||||
StreamPrintf(StreamStdout(), "\n");
|
||||
StreamFlush(StreamStdout());
|
||||
}
|
||||
XMLFreeElement(stanza);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue