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:
parent
236c854419
commit
530c060d2a
@ -154,7 +154,7 @@ sv_ev_room_message(const char * const room_jid, const char * const nick,
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@ -177,7 +177,7 @@ sv_ev_incoming_message(char *barejid, char *resource, char *message)
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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,
|
||||
const char * const 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_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_paused(char *barejid, char *resource);
|
||||
void sv_ev_inactive(char *barejid, char *resource);
|
||||
|
@ -555,6 +555,30 @@ _receipt_received_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza
|
||||
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
|
||||
_chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
|
||||
{
|
||||
@ -616,86 +640,67 @@ _chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * con
|
||||
return 1;
|
||||
}
|
||||
|
||||
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||
gchar *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
|
||||
|
||||
Jid *jid = jid_create(from);
|
||||
|
||||
// private message from chat room use full jid (room/nick)
|
||||
if (muc_active(jid->barejid)) {
|
||||
// determine if the notifications happened whilst offline
|
||||
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;
|
||||
|
||||
// standard chat message, use jid without resource
|
||||
} else {
|
||||
// determine if the notifications happened whilst offline
|
||||
GTimeVal 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);
|
||||
if (body) {
|
||||
char *message = xmpp_stanza_get_text(body);
|
||||
if (message) {
|
||||
if (delayed) {
|
||||
sv_ev_delayed_message(jid->barejid, message, tv_stamp);
|
||||
} else {
|
||||
sv_ev_incoming_message(jid->barejid, jid->resourcepart, message);
|
||||
}
|
||||
if (id && prefs_get_boolean(PREF_RECEIPTS_SEND)) {
|
||||
xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS);
|
||||
if (receipts) {
|
||||
char *receipts_name = xmpp_stanza_get_name(receipts);
|
||||
if (g_strcmp0(receipts_name, "request") == 0) {
|
||||
_message_send_receipt(jid->fulljid, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
xmpp_free(ctx, message);
|
||||
}
|
||||
}
|
||||
|
||||
// handle chat sessions and states
|
||||
if (!delayed && jid->resourcepart) {
|
||||
gboolean gone = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL;
|
||||
gboolean typing = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL;
|
||||
gboolean paused = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL;
|
||||
gboolean inactive = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL;
|
||||
if (gone) {
|
||||
sv_ev_gone(jid->barejid, jid->resourcepart);
|
||||
} else if (typing) {
|
||||
sv_ev_typing(jid->barejid, jid->resourcepart);
|
||||
} else if (paused) {
|
||||
sv_ev_paused(jid->barejid, jid->resourcepart);
|
||||
} else if (inactive) {
|
||||
sv_ev_inactive(jid->barejid, jid->resourcepart);
|
||||
} else if (stanza_contains_chat_state(stanza)) {
|
||||
sv_ev_activity(jid->barejid, jid->resourcepart, TRUE);
|
||||
} else {
|
||||
sv_ev_activity(jid->barejid, jid->resourcepart, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
jid_destroy(jid);
|
||||
_private_chat_handler(stanza, jid->fulljid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// standard chat message, use jid without resource
|
||||
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);
|
||||
if (body) {
|
||||
char *message = xmpp_stanza_get_text(body);
|
||||
if (message) {
|
||||
if (delayed) {
|
||||
sv_ev_delayed_message(jid->barejid, message, tv_stamp);
|
||||
} else {
|
||||
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)) {
|
||||
xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS);
|
||||
if (receipts) {
|
||||
char *receipts_name = xmpp_stanza_get_name(receipts);
|
||||
if (g_strcmp0(receipts_name, "request") == 0) {
|
||||
_message_send_receipt(jid->fulljid, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xmpp_ctx_t *ctx = connection_get_ctx();
|
||||
xmpp_free(ctx, message);
|
||||
}
|
||||
}
|
||||
|
||||
// handle chat sessions and states
|
||||
if (!delayed && jid->resourcepart) {
|
||||
gboolean gone = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL;
|
||||
gboolean typing = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL;
|
||||
gboolean paused = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL;
|
||||
gboolean inactive = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL;
|
||||
if (gone) {
|
||||
sv_ev_gone(jid->barejid, jid->resourcepart);
|
||||
} else if (typing) {
|
||||
sv_ev_typing(jid->barejid, jid->resourcepart);
|
||||
} else if (paused) {
|
||||
sv_ev_paused(jid->barejid, jid->resourcepart);
|
||||
} else if (inactive) {
|
||||
sv_ev_inactive(jid->barejid, jid->resourcepart);
|
||||
} else if (stanza_contains_chat_state(stanza)) {
|
||||
sv_ev_activity(jid->barejid, jid->resourcepart, TRUE);
|
||||
} else {
|
||||
sv_ev_activity(jid->barejid, jid->resourcepart, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
jid_destroy(jid);
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user