[FIX] Ignore unavailable statuses

They aren't that useful, especially in MUCs.
This commit is contained in:
lda 2025-01-25 12:20:47 +00:00
commit 389870c5d3
9 changed files with 108 additions and 9 deletions

View file

@ -30,13 +30,16 @@ JoinMUC(ParseeData *data, HashMap *event, char *jid, char *muc, char *name, char
UnistrFree(uninick);
UnistrFree(filtered);
UnistrFree(filterASCII);
/* TODO: vCards! */
/* TODO: Make sure that we fall back to plain ASCII if it fails too many
* times. */
while (!XMPPJoinMUC(data->jabber, jid, rev, hash, -1, true) && nonce < 32)
{
char *nonce_str = StrInt(nonce);
char *input = StrConcat(3, sender, name, nonce_str);
char *hex = ParseeHMACS(data->id, input);
Unistr *filterASCII = UnistrFilter(uninick, UnistrIsASCII);
if (strlen(hex) >= 8)
{
@ -45,6 +48,7 @@ JoinMUC(ParseeData *data, HashMap *event, char *jid, char *muc, char *name, char
Free(nick);
Free(rev);
Free(revscii);
nick = StrConcat(4, name, "[", hex, "]");
rev = StrConcat(3, muc, "/", nick);
@ -364,13 +368,13 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
StanzaBuilder *builder = NULL;
DbRef *ref = NULL;
HashMap *json = NULL;
char *unedited_id = MatrixGetEdit(event);
char *m_sender = GrabString(event, 1, "sender");
char *unedited_id = NULL;
char *body = GrabString(event, 2, "content", "body");
char *id = GrabString(event, 1, "room_id");
char *ev_id = GrabString(event, 1, "event_id");
char *m_sender = GrabString(event, 1, "sender");
char *chat_id, *muc_id;
char *chat_id = NULL, *muc_id = NULL;
char *reply_id = MatrixGetReply(event);
char *xepd = ParseeXMPPify(event);
char *type, *user, *xmppified_user = NULL, *to = NULL;
@ -381,6 +385,7 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
char *encoded_from = NULL;
bool direct = false;
unedited_id = MatrixGetEdit(event);
if (unedited_id)
{
@ -455,6 +460,7 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
Free(name);
Free(avatar);
}
if (reply_id)
{
/* TODO: Monocles chat DM users HATE this trick!
@ -511,8 +517,8 @@ end:
Free(stanza);
Free(sender);
Free(unauth);
Free(unedited_id);
Free(encoded_from);
Free(unedited_id);
DbUnlock(data->db, ref);
ref = NULL;

View file

@ -210,9 +210,11 @@ XMPPifyElement(HashMap *event, XMLElement *elem, XMPPFlags flags)
static char *
GetRawBody(HashMap *event)
{
if (MatrixGetEdit(event))
void *id;
if ((id = MatrixGetEdit(event)))
{
char *new = GrabString(event, 3, "content", "m.new_content", "body");
Free(id);
if (new)
{
return new;

View file

@ -192,6 +192,16 @@ UnistrGetch(Unistr *unistr, size_t i)
return i < unistr->length ? unistr->codepoints[i] : 0;
}
bool
UnistrIsASCII(uint32_t u)
{
if (u == 0)
{
return NULL;
}
return u < 0x7F;
}
bool
UnistrIsBMP(uint32_t u)
{
if (u == 0)

View file

@ -572,7 +572,7 @@ IQGet(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
else if (XMLookForTKV(stanza, "query", "xmlns", "jabber:iq:version"))
{
XMLElement *iq_reply, *query;
XMLElement *name, *version;
XMLElement *name, *version, *os;
iq_reply = XMLCreateTag("iq");
XMLAddAttr(iq_reply, "to", from);
@ -585,12 +585,15 @@ IQGet(ParseeData *args, XMLElement *stanza, XMPPThread *thr)
{
name = XMLCreateTag("name");
version = XMLCreateTag("version");
os = XMLCreateTag("os");
XMLAddChild(name, XMLCreateText(NAME));
XMLAddChild(version, XMLCreateText(VERSION "[" CODE "]"));
XMLAddChild(os, XMLCreateText(VERSION "POSIX-like"));
}
XMLAddChild(query, name);
XMLAddChild(query, version);
XMLAddChild(query, os);
XMLAddChild(iq_reply, query);
XMPPSendStanza(jabber, iq_reply, args->config->max_stanza_size);

View file

@ -298,7 +298,7 @@ end_item:
Free(room);
FreeStatuses(statuses);
}
if (status)
if (status && !StrEquals(type, "unavailable"))
{
XMLElement *status_data = ArrayGet(status->children, 0);
char *decode_from = ParseeLookupJID(oid);
@ -309,6 +309,8 @@ end_item:
status_str = status_data->data;
}
/* TODO: "The server will automatically set a user's presence to
* unavailable if their last active time was over a threshold value
* (e.g. 5 minutes)."

View file

@ -64,6 +64,12 @@ extern void UnistrFree(Unistr *unistr);
* Returns: whenever the character is within the BMP */
extern bool UnistrIsBMP(uint32_t u);
/** Returns true IFF the character is within the 7-bit ASCII range
* not 0x0000
* ------------------------------------------------------------
* Returns: whenever the character is within ASCII */
extern bool UnistrIsASCII(uint32_t u);
typedef bool (*UnistrFilterFunc)(uint32_t u);
/** "Filters" characters in a Unistring by codepoint, removing
* those with callbacks which return false into a new unistring.