mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Move message sent by us logic in own function
This commit is contained in:
parent
3bd5c9f535
commit
06f300a42c
@ -304,19 +304,11 @@ sv_ev_room_message(ProfMessage *message)
|
||||
|
||||
char *mynick = muc_nick(mucwin->roomjid);
|
||||
|
||||
// messages from ourselves
|
||||
if (g_strcmp0(mynick, message->jid->resourcepart) == 0 && message->id != NULL) {
|
||||
// test if message was sent from this client
|
||||
// we check the </origin-id> for this we calculate a hash into it so we can detect
|
||||
// whether this client sent it. See connection_create_stanza_id()
|
||||
gsize tmp_len;
|
||||
char *tmp = (char*)g_base64_decode(message->id, &tmp_len);
|
||||
// log if not from this client. our client sents at least 10 for the identifier + random message bytes
|
||||
if ((tmp_len < 11) || (g_strcmp0(&tmp[10], connection_get_profanity_identifier()) != 0)) {
|
||||
_log_muc(message);
|
||||
}
|
||||
// messages from others
|
||||
// messages from ourselves (account and this client)
|
||||
if (g_strcmp0(mynick, message->jid->resourcepart) == 0 && message_is_sent_by_us(message)) {
|
||||
_log_muc(message);
|
||||
} else {
|
||||
// messages from others
|
||||
_log_muc(message);
|
||||
}
|
||||
|
||||
|
@ -1158,3 +1158,19 @@ _send_message_stanza(xmpp_stanza_t *const stanza)
|
||||
}
|
||||
xmpp_free(connection_get_ctx(), text);
|
||||
}
|
||||
|
||||
bool message_is_sent_by_us(ProfMessage *message) {
|
||||
// we check the </origin-id> for this we calculate a hash into it so we can detect
|
||||
// whether this client sent it. See connection_create_stanza_id()
|
||||
if (message->id != NULL) {
|
||||
gsize tmp_len;
|
||||
char *tmp = (char*)g_base64_decode(message->id, &tmp_len);
|
||||
|
||||
// our client sents at least 10 for the identifier + random message bytes
|
||||
if ((tmp_len > 10) || (g_strcmp0(&tmp[10], connection_get_profanity_identifier()) == 0)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -67,5 +67,6 @@ void message_free(ProfMessage *message);
|
||||
void message_handlers_init(void);
|
||||
void message_handlers_clear(void);
|
||||
void message_pubsub_event_handler_add(const char *const node, ProfMessageCallback func, ProfMessageFreeCallback free_func, void *userdata);
|
||||
bool message_is_sent_by_us(ProfMessage *message);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user