1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Extract private message hanlding in message.c

This commit is contained in:
James Booth 2015-05-03 01:25:33 +01:00
parent 236c854419
commit 530c060d2a
3 changed files with 84 additions and 79 deletions

View File

@ -154,7 +154,7 @@ sv_ev_room_message(const char * const room_jid, const char * const nick,
} }
void void
sv_ev_incoming_private_message(char *fulljid, char *message) sv_ev_incoming_private_message(const char * const fulljid, char *message)
{ {
ui_incoming_private_msg(fulljid, message, NULL); ui_incoming_private_msg(fulljid, message, NULL);
} }
@ -177,7 +177,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message)
} }
void void
sv_ev_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp) sv_ev_delayed_private_message(const char * const fulljid, char *message, GTimeVal tv_stamp)
{ {
ui_incoming_private_msg(fulljid, message, &tv_stamp); ui_incoming_private_msg(fulljid, message, &tv_stamp);
} }

View File

@ -51,9 +51,9 @@ void sv_ev_room_history(const char * const room_jid, const char * const nick,
void sv_ev_room_message(const char * const room_jid, const char * const nick, void sv_ev_room_message(const char * const room_jid, const char * const nick,
const char * const message); const char * const message);
void sv_ev_incoming_message(char *barejid, char *resource, char *message); void sv_ev_incoming_message(char *barejid, char *resource, char *message);
void sv_ev_incoming_private_message(char *fulljid, char *message); void sv_ev_incoming_private_message(const char * const fulljid, char *message);
void sv_ev_delayed_message(char *fulljid, char *message, GTimeVal tv_stamp); void sv_ev_delayed_message(char *fulljid, char *message, GTimeVal tv_stamp);
void sv_ev_delayed_private_message(char *fulljid, char *message, GTimeVal tv_stamp); void sv_ev_delayed_private_message(const char * const fulljid, char *message, GTimeVal tv_stamp);
void sv_ev_typing(char *barejid, char *resource); void sv_ev_typing(char *barejid, char *resource);
void sv_ev_paused(char *barejid, char *resource); void sv_ev_paused(char *barejid, char *resource);
void sv_ev_inactive(char *barejid, char *resource); void sv_ev_inactive(char *barejid, char *resource);

View File

@ -555,6 +555,30 @@ _receipt_received_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza
return 1; return 1;
} }
void _private_chat_handler(xmpp_stanza_t * const stanza, const char * const fulljid)
{
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
if (!body) {
return;
}
char *message = xmpp_stanza_get_text(body);
if (!message) {
return;
}
GTimeVal tv_stamp;
gboolean delayed = stanza_get_delay(stanza, &tv_stamp);
if (delayed) {
sv_ev_delayed_private_message(fulljid, message, tv_stamp);
} else {
sv_ev_incoming_private_message(fulljid, message);
}
xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_free(ctx, message);
}
static int static int
_chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
{ {
@ -616,42 +640,19 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con
return 1; return 1;
} }
xmpp_ctx_t *ctx = connection_get_ctx();
gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
Jid *jid = jid_create(from); Jid *jid = jid_create(from);
// private message from chat room use full jid (room/nick) // private message from chat room use full jid (room/nick)
if (muc_active(jid->barejid)) { if (muc_active(jid->barejid)) {
// determine if the notifications happened whilst offline _private_chat_handler(stanza, jid->fulljid);
GTimeVal tv_stamp;
gboolean delayed = stanza_get_delay(stanza, &tv_stamp);
// check for and deal with message
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
if (body) {
char *message = xmpp_stanza_get_text(body);
if (message) {
if (delayed) {
sv_ev_delayed_private_message(jid->str, message, tv_stamp);
} else {
sv_ev_incoming_private_message(jid->str, message);
}
xmpp_free(ctx, message);
}
}
jid_destroy(jid);
return 1; return 1;
}
// standard chat message, use jid without resource // standard chat message, use jid without resource
} else {
// determine if the notifications happened whilst offline
GTimeVal tv_stamp; GTimeVal tv_stamp;
gboolean delayed = stanza_get_delay(stanza, &tv_stamp); gboolean delayed = stanza_get_delay(stanza, &tv_stamp);
char *id = xmpp_stanza_get_id(stanza);
// check for and deal with message
xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY); xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
if (body) { if (body) {
char *message = xmpp_stanza_get_text(body); char *message = xmpp_stanza_get_text(body);
@ -661,6 +662,9 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con
} else { } else {
sv_ev_incoming_message(jid->barejid, jid->resourcepart, message); sv_ev_incoming_message(jid->barejid, jid->resourcepart, message);
} }
// send receipt if configured
char *id = xmpp_stanza_get_id(stanza);
if (id && prefs_get_boolean(PREF_RECEIPTS_SEND)) { if (id && prefs_get_boolean(PREF_RECEIPTS_SEND)) {
xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS); xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS);
if (receipts) { if (receipts) {
@ -670,6 +674,8 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con
} }
} }
} }
xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_free(ctx, message); xmpp_free(ctx, message);
} }
} }
@ -697,5 +703,4 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con
jid_destroy(jid); jid_destroy(jid);
return 1; return 1;
}
} }