mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
jabber: tidy groupchat message handler
This commit is contained in:
parent
d2a923126b
commit
82e65734c0
58
src/jabber.c
58
src/jabber.c
@ -379,10 +379,32 @@ _jabber_roster_request(void)
|
||||
static int
|
||||
_groupchat_message_handler(xmpp_stanza_t * const stanza)
|
||||
{
|
||||
gchar *room_jid = xmpp_stanza_get_attribute(stanza, "from");
|
||||
char *room = NULL;
|
||||
char *nick = NULL;
|
||||
|
||||
if (room_is_active(room_jid)) {
|
||||
gchar *room_jid = xmpp_stanza_get_attribute(stanza, "from");
|
||||
if (!room_parse_room_jid(room_jid, &room, &nick)) {
|
||||
log_error("Could not parse room jid: %s", room_jid);
|
||||
g_free(room);
|
||||
g_free(nick);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!room_is_active(room_jid)) {
|
||||
log_error("Message recieved for inactive groupchat: %s", room_jid);
|
||||
g_free(room);
|
||||
g_free(nick);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *message = NULL;
|
||||
xmpp_stanza_t *delay = xmpp_stanza_get_child_by_name(stanza, "delay");
|
||||
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, "body");
|
||||
if (body != NULL) {
|
||||
message = xmpp_stanza_get_text(body);
|
||||
}
|
||||
|
||||
// handle chat room history
|
||||
if (delay != NULL) {
|
||||
@ -390,21 +412,8 @@ _groupchat_message_handler(xmpp_stanza_t * const stanza)
|
||||
GTimeVal tv_stamp;
|
||||
|
||||
if (g_time_val_from_iso8601(utc_stamp, &tv_stamp)) {
|
||||
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, "body");
|
||||
|
||||
if (body != NULL) {
|
||||
char *room = NULL;
|
||||
char *nick = NULL;
|
||||
gboolean parse_success = room_parse_room_jid(room_jid, &room, &nick);
|
||||
|
||||
if (parse_success) {
|
||||
char *message = xmpp_stanza_get_text(body);
|
||||
if (message != NULL) {
|
||||
prof_handle_room_history(room, nick, tv_stamp, message);
|
||||
g_free(room);
|
||||
g_free(nick);
|
||||
} else {
|
||||
log_error("Could not parse room jid: %s", room_jid);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log_error("Couldn't parse datetime string receiving room history: %s", utc_stamp);
|
||||
@ -412,25 +421,10 @@ _groupchat_message_handler(xmpp_stanza_t * const stanza)
|
||||
|
||||
// handle regular chat room message
|
||||
} else {
|
||||
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, "body");
|
||||
if (body != NULL) {
|
||||
char *room = NULL;
|
||||
char *nick = NULL;
|
||||
gboolean parse_success = room_parse_room_jid(room_jid, &room, &nick);
|
||||
|
||||
if (parse_success) {
|
||||
char *message = xmpp_stanza_get_text(body);
|
||||
if (message != NULL) {
|
||||
prof_handle_room_message(room, nick, message);
|
||||
g_free(room);
|
||||
g_free(nick);
|
||||
} else {
|
||||
log_error("Could not parse room jid: %s", room_jid);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log_error("Message recieved for inactive groupchat: %s", room_jid);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user