mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 17:05:11 +00:00
[ADD] Shove XML stanza, use show field, rename OOB
Also, https://at.kappach.at/
This commit is contained in:
parent
d71f7d2f49
commit
be15a67cba
1 changed files with 73 additions and 15 deletions
|
|
@ -183,7 +183,7 @@ static char *
|
|||
ParseeGetBridgedRoom(ParseeData *data, XMLElement *stanza)
|
||||
{
|
||||
char *to = ParseeDecodeMXID(HashMapGet(stanza->attrs, "to"));
|
||||
char *from = (HashMapGet(stanza->attrs, "from"));
|
||||
char *from = HashMapGet(stanza->attrs, "from");
|
||||
char *chat_id = ParseeGetFromMUCID(data, from);
|
||||
char *mroom_id = ParseeGetRoomID(data, chat_id);
|
||||
char *ret;
|
||||
|
|
@ -400,6 +400,25 @@ end:
|
|||
DbUnlock(args->db, avatars);
|
||||
}
|
||||
|
||||
static HashMap *
|
||||
ShoveStanza(HashMap *content, XMLElement *stanza)
|
||||
{
|
||||
char *encoded_stanza = NULL;
|
||||
Stream *str_writer = StrStreamWriter(&encoded_stanza);
|
||||
|
||||
XMLEncode(str_writer, stanza);
|
||||
StreamFlush(str_writer);
|
||||
StreamClose(str_writer);
|
||||
|
||||
JsonFree(HashMapSet(content,
|
||||
"at.kappach.at.parsee.stanza",
|
||||
JsonValueString(encoded_stanza)
|
||||
));
|
||||
|
||||
Free(encoded_stanza);
|
||||
return content;
|
||||
}
|
||||
|
||||
static bool
|
||||
MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
||||
{
|
||||
|
|
@ -467,10 +486,8 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
|||
for (i = 0; i < ArraySize(items->children); i++)
|
||||
{
|
||||
ManageProfileItem(
|
||||
args,
|
||||
ArrayGet(items->children, i),
|
||||
stanza,
|
||||
thr
|
||||
args, ArrayGet(items->children, i),
|
||||
stanza, thr
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -630,9 +647,11 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
|||
content = MatrixCreateMedia(mxc, data->data, mime);
|
||||
|
||||
/* Yeah, no, I'm not modifying the media creation code. */
|
||||
HashMapSet(content, "external_url",
|
||||
HashMapSet(content,
|
||||
"at.kappach.at.parsee.external",
|
||||
JsonValueString(oob_data->data)
|
||||
);
|
||||
ShoveStanza(content, stanza);
|
||||
|
||||
event_id = ASSend(
|
||||
args->config, mroom_id, encoded,
|
||||
|
|
@ -657,7 +676,10 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
|||
Free(ASSend(
|
||||
args->config, mroom_id, encoded,
|
||||
"m.reaction",
|
||||
MatrixCreateReact(event_id, react_data->data)
|
||||
ShoveStanza(
|
||||
MatrixCreateReact(event_id, react_data->data),
|
||||
stanza
|
||||
)
|
||||
));
|
||||
}
|
||||
Free(event_id);
|
||||
|
|
@ -687,6 +709,7 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
|||
MatrixSetReply(ev, reply_id);
|
||||
Free(reply_id);
|
||||
}
|
||||
ShoveStanza(ev, stanza);
|
||||
event_id = ASSend(
|
||||
args->config, mroom_id, encoded,
|
||||
"m.room.message", ev
|
||||
|
|
@ -702,7 +725,8 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
|
|||
event_id = ParseeGetEventFromID(args, stanza, replaced);
|
||||
Free(ASSend(
|
||||
args->config, mroom_id, encoded,
|
||||
"m.room.message", MatrixCreateReplace(event_id, data->data)
|
||||
"m.room.message",
|
||||
ShoveStanza(MatrixCreateReplace(event_id, data->data), stanza)
|
||||
));
|
||||
ParseePushAllStanza(args, stanza, event_id);
|
||||
pthread_mutex_unlock(&thr->info->chk_lock);
|
||||
|
|
@ -993,7 +1017,15 @@ static void
|
|||
IQGet(ParseeData *args, XMLElement *stanza)
|
||||
{
|
||||
XMPPComponent *jabber = args->jabber;
|
||||
if (XMLookForTKV(stanza, "query", "xmlns", DISCO))
|
||||
char *from = HashMapGet(stanza->attrs, "from");
|
||||
char *to = HashMapGet(stanza->attrs, "to");
|
||||
char *id = HashMapGet(stanza->attrs, "id");
|
||||
|
||||
if (XMLookForTKV(stanza, "vCard", "xmlns", "vcard-temp"))
|
||||
{
|
||||
Log(LOG_INFO, "vCard information GET for %s", to);
|
||||
}
|
||||
else if (XMLookForTKV(stanza, "query", "xmlns", DISCO))
|
||||
{
|
||||
IQDiscoGet(args, jabber, stanza);
|
||||
}
|
||||
|
|
@ -1001,9 +1033,6 @@ IQGet(ParseeData *args, XMLElement *stanza)
|
|||
{
|
||||
XMLElement *iq_reply, *query;
|
||||
XMLElement *name, *version;
|
||||
char *from = HashMapGet(stanza->attrs, "from");
|
||||
char *to = HashMapGet(stanza->attrs, "to");
|
||||
char *id = HashMapGet(stanza->attrs, "id");
|
||||
|
||||
iq_reply = XMLCreateTag("iq");
|
||||
XMLAddAttr(iq_reply, "to", from);
|
||||
|
|
@ -1085,6 +1114,34 @@ CreateVCardRequest(char *from, char *to)
|
|||
|
||||
return vcard_request;
|
||||
}
|
||||
|
||||
static UserStatus
|
||||
GuessStatus(XMLElement *stanza)
|
||||
{
|
||||
/* C.F RFC3921: XMPP IM */
|
||||
XMLElement *show = XMLookForUnique(stanza, "show");
|
||||
XMLElement *data = show ? ArrayGet(show->children, 0) : NULL;
|
||||
|
||||
if (!show || !data)
|
||||
{
|
||||
return USER_STATUS_ONLINE;
|
||||
}
|
||||
|
||||
if (StrEquals(data->data, "away") ||
|
||||
StrEquals(data->data, "xa"))
|
||||
{
|
||||
return USER_STATUS_OFFLINE;
|
||||
}
|
||||
if (StrEquals(data->data, "chat"))
|
||||
{
|
||||
return USER_STATUS_ONLINE;
|
||||
}
|
||||
if (StrEquals(data->data, "dnd"))
|
||||
{
|
||||
return USER_STATUS_UNAVAILABLE;
|
||||
}
|
||||
return USER_STATUS_ONLINE;
|
||||
}
|
||||
static void
|
||||
PresenceStanza(ParseeData *args, XMLElement *stanza)
|
||||
{
|
||||
|
|
@ -1112,7 +1169,7 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
|
|||
* my own instance (kappach.at) with presence enabled. */
|
||||
ASSetStatus(
|
||||
args->config, from_matrix,
|
||||
USER_STATUS_ONLINE, status_str
|
||||
GuessStatus(stanza), status_str
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -1230,7 +1287,7 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
|
|||
Free(parsee);
|
||||
Free(room);
|
||||
}
|
||||
else if (vc)
|
||||
if (vc)
|
||||
{
|
||||
XMLElement *photo = XMLookForUnique(vc, "photo");
|
||||
XMLElement *p_dat = photo ? ArrayGet(photo->children, 0) : NULL;
|
||||
|
|
@ -1330,9 +1387,10 @@ XMPPDispatcher(void *argp)
|
|||
{
|
||||
XMLElement *stanza = RetrieveStanza(thread);
|
||||
|
||||
/* TODO: I've seen some spikes in some threads. */
|
||||
if (!stanza)
|
||||
{
|
||||
UtilSleepMillis(1);
|
||||
UtilSleepMillis(10);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue