mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Handle legacy delayed messages in chat rooms
This commit is contained in:
parent
645d1b74d5
commit
2cdd1b3810
28
src/jabber.c
28
src/jabber.c
@ -458,29 +458,17 @@ _groupchat_message_handler(xmpp_stanza_t * const stanza)
|
||||
return 1;
|
||||
}
|
||||
|
||||
xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_DELAY);
|
||||
// determine if the notifications happened whilst offline
|
||||
GTimeVal tv_stamp;
|
||||
gboolean delayed = stanza_get_delay(stanza, &tv_stamp);
|
||||
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
|
||||
|
||||
// check for and deal with message
|
||||
if (body != NULL) {
|
||||
message = xmpp_stanza_get_text(body);
|
||||
}
|
||||
|
||||
// handle chat room history
|
||||
if (delay != NULL) {
|
||||
char *utc_stamp = xmpp_stanza_get_attribute(delay, STANZA_ATTR_STAMP);
|
||||
GTimeVal tv_stamp;
|
||||
|
||||
if (g_time_val_from_iso8601(utc_stamp, &tv_stamp)) {
|
||||
if (message != NULL) {
|
||||
prof_handle_room_history(room, nick, tv_stamp, message);
|
||||
}
|
||||
char *message = xmpp_stanza_get_text(body);
|
||||
if (delayed) {
|
||||
prof_handle_room_history(room, nick, tv_stamp, message);
|
||||
} else {
|
||||
log_error("Couldn't parse datetime string receiving room history: %s", utc_stamp);
|
||||
}
|
||||
|
||||
// handle regular chat room message
|
||||
} else {
|
||||
if (message != NULL) {
|
||||
prof_handle_room_message(room, nick, message);
|
||||
}
|
||||
}
|
||||
@ -707,7 +695,7 @@ _room_presence_handler(const char * const jid, xmpp_stanza_t * const stanza)
|
||||
}
|
||||
|
||||
// handle self presence
|
||||
if (stanza_is_muc_self_presence(stanza)) {
|
||||
if (stanza_is_muc_self_presence(stanza, jabber_get_jid())) {
|
||||
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
|
||||
gboolean nick_change = stanza_is_room_nick_change(stanza);
|
||||
|
||||
|
16
src/stanza.c
16
src/stanza.c
@ -238,7 +238,8 @@ stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp)
|
||||
}
|
||||
|
||||
gboolean
|
||||
stanza_is_muc_self_presence(xmpp_stanza_t * const stanza)
|
||||
stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
|
||||
const char * const self_jid)
|
||||
{
|
||||
if (stanza == NULL) {
|
||||
return FALSE;
|
||||
@ -276,6 +277,19 @@ stanza_is_muc_self_presence(xmpp_stanza_t * const stanza)
|
||||
x_children = xmpp_stanza_get_next(x_children);
|
||||
}
|
||||
|
||||
// for older server that don't send status 110
|
||||
while (x_children != NULL) {
|
||||
if (strcmp(xmpp_stanza_get_name(x_children), STANZA_NAME_ITEM) == 0) {
|
||||
char *jid = xmpp_stanza_get_attribute(x_children, STANZA_ATTR_JID);
|
||||
if (jid != NULL) {
|
||||
if (g_str_has_prefix(jid, self_jid)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
x_children = xmpp_stanza_get_next(x_children);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,8 @@ gboolean stanza_contains_chat_state(xmpp_stanza_t *stanza);
|
||||
|
||||
gboolean stanza_get_delay(xmpp_stanza_t * const stanza, GTimeVal *tv_stamp);
|
||||
|
||||
gboolean stanza_is_muc_self_presence(xmpp_stanza_t * const stanza);
|
||||
gboolean stanza_is_muc_self_presence(xmpp_stanza_t * const stanza,
|
||||
const char * const self_jid);
|
||||
gboolean stanza_is_room_nick_change(xmpp_stanza_t * const stanza);
|
||||
|
||||
char* stanza_get_new_nick(xmpp_stanza_t * const stanza);
|
||||
|
Loading…
Reference in New Issue
Block a user