[ADD/WIP/AYA] Sending errors, voice reqs, Ayawork.

Ayaya!
This commit is contained in:
LDA 2024-08-05 19:45:57 +02:00
commit 8588a6fb5c
7 changed files with 197 additions and 5 deletions

View file

@ -24,7 +24,8 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
char *retracted = XMPPGetRetractedID(stanza);
char *reply_to = XMPPGetReply(stanza);
char *moderated = XMPPGetModeration(stanza);
bool chat = StrEquals(HashMapGet(stanza->attrs, "type"), "chat");
char *type = HashMapGet(stanza->attrs, "type");
bool chat = StrEquals(type, "chat");
size_t i;
to = NULL;
@ -39,6 +40,45 @@ MessageStanza(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
return false;
}
if (StrEquals(type, "error"))
{
char *type, *text, *user, *parsee;
char *message, *room;
from = HashMapGet(stanza->attrs, "from");
to = HashMapGet(stanza->attrs, "to");
/* Tiny little trick. */
XMLAddAttr(stanza, "type", "groupchat");
parsee = ParseeMXID(args);
type = XMPPGetErrtype(stanza);
text = XMPPGetErrtext(stanza);
user = ParseeDecodeMXID(to);
/* Avoid fun hypothetical cases of looping. */
if (StrEquals(parsee, user))
{
goto end_error;
}
message = StrConcat(3, type, ": ", text);
room = ParseeGetBridgedRoom(args, stanza);
Free(ASSend(
args->config, room, parsee,
"m.room.message",
MatrixCreateNotice(message)
));
end_error:
XMLFreeElement(stanza);
Free(message);
Free(parsee);
Free(room);
Free(user);
return false;
}
if (moderated)
{
/* TODO: Parsee MUST check if it is a valid MUC */

View file

@ -79,6 +79,7 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
char *decode_from, *real_matrix;
char *matrix_user_pl = ParseeEncodeJID(args->config, trim, false);
char *affiliation = HashMapGet(item->attrs, "affiliation");
char *role = HashMapGet(item->attrs, "role");
int power_level = 0;
char *parsee = ParseeMXID(args);
@ -117,6 +118,24 @@ PresenceStanza(ParseeData *args, XMLElement *stanza)
power_level = -1;
}
if (StrEquals(role, "visitor"))
{
char *parsee = ParseeJID(args);
if (!StrEquals(HashMapGet(stanza->attrs, "to"), parsee) &&
IsStatus(110))
{
char *muc = ParseeTrimJID(HashMapGet(stanza->attrs, "from"));
char *usr = HashMapGet(stanza->attrs, "to");
/* Ask for voice */
XMPPRequestVoice(args->jabber, usr, muc);
Free(muc);
}
Free(parsee);
}
/* Set the user's PL
* TODO: Do NOT change the PL of *real* people nilly-willy.
* In some scenarios, this is really bad behaviour. */