mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Moved messages handlers to server_events
This commit is contained in:
parent
d083a5407d
commit
a54518f2d4
104
src/profanity.c
104
src/profanity.c
@ -117,53 +117,6 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
|
||||
g_timer_destroy(timer);
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_typing(char *from)
|
||||
{
|
||||
ui_contact_typing(from);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_incoming_message(char *from, char *message, gboolean priv)
|
||||
{
|
||||
ui_incoming_msg(from, message, NULL, priv);
|
||||
ui_current_page_off();
|
||||
|
||||
if (prefs_get_boolean(PREF_CHLOG) && !priv) {
|
||||
Jid *from_jid = jid_create(from);
|
||||
const char *jid = jabber_get_fulljid();
|
||||
Jid *jidp = jid_create(jid);
|
||||
chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, NULL);
|
||||
jid_destroy(jidp);
|
||||
jid_destroy(from_jid);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_delayed_message(char *from, char *message, GTimeVal tv_stamp,
|
||||
gboolean priv)
|
||||
{
|
||||
ui_incoming_msg(from, message, &tv_stamp, priv);
|
||||
ui_current_page_off();
|
||||
|
||||
if (prefs_get_boolean(PREF_CHLOG) && !priv) {
|
||||
Jid *from_jid = jid_create(from);
|
||||
const char *jid = jabber_get_fulljid();
|
||||
Jid *jidp = jid_create(jid);
|
||||
chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, &tv_stamp);
|
||||
jid_destroy(jidp);
|
||||
jid_destroy(from_jid);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_duck_result(const char * const result)
|
||||
{
|
||||
ui_duck_result(result);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_already_in_group(const char * const contact,
|
||||
const char * const group)
|
||||
@ -242,13 +195,6 @@ prof_handle_roster_remove(const char * const barejid)
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_gone(const char * const from)
|
||||
{
|
||||
ui_recipient_gone(from);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_disconnect(const char * const jid)
|
||||
{
|
||||
@ -261,43 +207,6 @@ prof_handle_disconnect(const char * const jid)
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_room_history(const char * const room_jid, const char * const nick,
|
||||
GTimeVal tv_stamp, const char * const message)
|
||||
{
|
||||
ui_room_history(room_jid, nick, tv_stamp, message);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_room_message(const char * const room_jid, const char * const nick,
|
||||
const char * const message)
|
||||
{
|
||||
ui_room_message(room_jid, nick, message);
|
||||
ui_current_page_off();
|
||||
|
||||
if (prefs_get_boolean(PREF_GRLOG)) {
|
||||
Jid *jid = jid_create(jabber_get_fulljid());
|
||||
groupchat_log_chat(jid->barejid, room_jid, nick, message);
|
||||
jid_destroy(jid);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_room_subject(const char * const room_jid, const char * const subject)
|
||||
{
|
||||
ui_room_subject(room_jid, subject);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_room_broadcast(const char *const room_jid,
|
||||
const char * const message)
|
||||
{
|
||||
ui_room_broadcast(room_jid, message);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_room_roster_complete(const char * const room)
|
||||
{
|
||||
@ -345,19 +254,6 @@ prof_handle_leave_room(const char * const room)
|
||||
muc_leave_room(room);
|
||||
}
|
||||
|
||||
void prof_handle_room_invite(jabber_invite_t invite_type,
|
||||
const char * const invitor, const char * const room,
|
||||
const char * const reason)
|
||||
{
|
||||
Jid *room_jid = jid_create(room);
|
||||
if (!muc_room_is_active(room_jid) && !muc_invites_include(room)) {
|
||||
cons_show_room_invite(invitor, room, reason);
|
||||
muc_add_invite(room);
|
||||
ui_current_page_off();
|
||||
}
|
||||
jid_destroy(room_jid);
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_contact_online(char *contact, Resource *resource,
|
||||
GDateTime *last_activity)
|
||||
|
@ -30,22 +30,11 @@ void prof_run(const int disable_tls, char *log_level, char *account_name);
|
||||
|
||||
void prof_handle_login_success(const char *jid, const char *altdomain);
|
||||
void prof_handle_disconnect(const char * const jid);
|
||||
void prof_handle_typing(char *from);
|
||||
void prof_handle_contact_online(char *contact, Resource *resource,
|
||||
GDateTime *last_activity);
|
||||
void prof_handle_contact_offline(char *contact, char *show, char *status);
|
||||
void prof_handle_incoming_message(char *from, char *message, gboolean priv);
|
||||
void prof_handle_delayed_message(char *from, char *message, GTimeVal tv_stamp,
|
||||
gboolean priv);
|
||||
void prof_handle_subscription(const char *from, jabber_subscr_t type);
|
||||
void prof_handle_roster(GSList *roster);
|
||||
void prof_handle_gone(const char * const from);
|
||||
void prof_handle_room_history(const char * const room_jid,
|
||||
const char * const nick, GTimeVal tv_stamp, const char * const message);
|
||||
void prof_handle_room_message(const char * const room_jid, const char * const nick,
|
||||
const char * const message);
|
||||
void prof_handle_room_subject(const char * const room_jid,
|
||||
const char * const subject);
|
||||
void prof_handle_room_roster_complete(const char * const room);
|
||||
void prof_handle_room_member_online(const char * const room,
|
||||
const char * const nick, const char * const show, const char * const status,
|
||||
@ -60,15 +49,9 @@ void prof_handle_room_member_nick_change(const char * const room,
|
||||
const char * const old_nick, const char * const nick);
|
||||
void prof_handle_room_nick_change(const char * const room,
|
||||
const char * const nick);
|
||||
void prof_handle_room_broadcast(const char *const room_jid,
|
||||
const char * const message);
|
||||
void prof_handle_room_invite(jabber_invite_t invite_type,
|
||||
const char * const invitor, const char * const room,
|
||||
const char * const reason);
|
||||
void prof_handle_idle(void);
|
||||
void prof_handle_activity(void);
|
||||
void prof_handle_duck_help(const char * const result);
|
||||
void prof_handle_duck_result(const char * const result);
|
||||
void prof_handle_roster_add(const char * const barejid, const char * const name);
|
||||
void prof_handle_roster_remove(const char * const barejid);
|
||||
void prof_handle_already_in_group(const char * const contact, const char * const group);
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "chat_session.h"
|
||||
#include "log.h"
|
||||
#include "muc.h"
|
||||
#include "config/preferences.h"
|
||||
#include "roster_list.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
@ -104,3 +105,108 @@ handle_disco_items(GSList *items, const char *jid)
|
||||
cons_show_disco_items(items, jid);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_invite(jabber_invite_t invite_type,
|
||||
const char * const invitor, const char * const room,
|
||||
const char * const reason)
|
||||
{
|
||||
Jid *room_jid = jid_create(room);
|
||||
if (!muc_room_is_active(room_jid) && !muc_invites_include(room)) {
|
||||
cons_show_room_invite(invitor, room, reason);
|
||||
muc_add_invite(room);
|
||||
ui_current_page_off();
|
||||
}
|
||||
jid_destroy(room_jid);
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_broadcast(const char *const room_jid,
|
||||
const char * const message)
|
||||
{
|
||||
ui_room_broadcast(room_jid, message);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_subject(const char * const room_jid, const char * const subject)
|
||||
{
|
||||
ui_room_subject(room_jid, subject);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_history(const char * const room_jid, const char * const nick,
|
||||
GTimeVal tv_stamp, const char * const message)
|
||||
{
|
||||
ui_room_history(room_jid, nick, tv_stamp, message);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_message(const char * const room_jid, const char * const nick,
|
||||
const char * const message)
|
||||
{
|
||||
ui_room_message(room_jid, nick, message);
|
||||
ui_current_page_off();
|
||||
|
||||
if (prefs_get_boolean(PREF_GRLOG)) {
|
||||
Jid *jid = jid_create(jabber_get_fulljid());
|
||||
groupchat_log_chat(jid->barejid, room_jid, nick, message);
|
||||
jid_destroy(jid);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handle_duck_result(const char * const result)
|
||||
{
|
||||
ui_duck_result(result);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
handle_incoming_message(char *from, char *message, gboolean priv)
|
||||
{
|
||||
ui_incoming_msg(from, message, NULL, priv);
|
||||
ui_current_page_off();
|
||||
|
||||
if (prefs_get_boolean(PREF_CHLOG) && !priv) {
|
||||
Jid *from_jid = jid_create(from);
|
||||
const char *jid = jabber_get_fulljid();
|
||||
Jid *jidp = jid_create(jid);
|
||||
chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, NULL);
|
||||
jid_destroy(jidp);
|
||||
jid_destroy(from_jid);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handle_delayed_message(char *from, char *message, GTimeVal tv_stamp,
|
||||
gboolean priv)
|
||||
{
|
||||
ui_incoming_msg(from, message, &tv_stamp, priv);
|
||||
ui_current_page_off();
|
||||
|
||||
if (prefs_get_boolean(PREF_CHLOG) && !priv) {
|
||||
Jid *from_jid = jid_create(from);
|
||||
const char *jid = jabber_get_fulljid();
|
||||
Jid *jidp = jid_create(jid);
|
||||
chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, &tv_stamp);
|
||||
jid_destroy(jidp);
|
||||
jid_destroy(from_jid);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handle_typing(char *from)
|
||||
{
|
||||
ui_contact_typing(from);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
handle_gone(const char * const from)
|
||||
{
|
||||
ui_recipient_gone(from);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
@ -32,5 +32,21 @@ void handle_software_version_result(const char * const jid, const char * const
|
||||
void handle_disco_info(const char *from, GSList *identities, GSList *features);
|
||||
void handle_room_list(GSList *rooms, const char *conference_node);
|
||||
void handle_disco_items(GSList *items, const char *jid);
|
||||
void handle_room_invite(jabber_invite_t invite_type,
|
||||
const char * const invitor, const char * const room,
|
||||
const char * const reason);
|
||||
void handle_room_broadcast(const char *const room_jid,
|
||||
const char * const message);
|
||||
void handle_room_subject(const char * const room_jid, const char * const subject);
|
||||
void handle_room_history(const char * const room_jid, const char * const nick,
|
||||
GTimeVal tv_stamp, const char * const message);
|
||||
void handle_room_message(const char * const room_jid, const char * const nick,
|
||||
const char * const message);
|
||||
void handle_duck_result(const char * const result);
|
||||
void handle_incoming_message(char *from, char *message, gboolean priv);
|
||||
void handle_delayed_message(char *from, char *message, GTimeVal tv_stamp,
|
||||
gboolean priv);
|
||||
void handle_typing(char *from);
|
||||
void handle_gone(const char * const from);
|
||||
|
||||
#endif
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "log.h"
|
||||
#include "muc.h"
|
||||
#include "profanity.h"
|
||||
#include "server_events.h"
|
||||
#include "xmpp/connection.h"
|
||||
#include "xmpp/message.h"
|
||||
#include "xmpp/roster.h"
|
||||
@ -222,7 +223,7 @@ _conference_message_handler(xmpp_conn_t * const conn,
|
||||
reason = xmpp_stanza_get_text(reason_st);
|
||||
}
|
||||
|
||||
prof_handle_room_invite(INVITE_MEDIATED, invitor, room, reason);
|
||||
handle_room_invite(INVITE_MEDIATED, invitor, room, reason);
|
||||
jid_destroy(jidp);
|
||||
if (reason != NULL) {
|
||||
xmpp_free(ctx, reason);
|
||||
@ -243,7 +244,7 @@ _conference_message_handler(xmpp_conn_t * const conn,
|
||||
|
||||
reason = xmpp_stanza_get_attribute(x_groupchat, STANZA_ATTR_REASON);
|
||||
|
||||
prof_handle_room_invite(INVITE_DIRECT, invitor, room, reason);
|
||||
handle_room_invite(INVITE_DIRECT, invitor, room, reason);
|
||||
|
||||
jid_destroy(jidp);
|
||||
|
||||
@ -253,7 +254,7 @@ _conference_message_handler(xmpp_conn_t * const conn,
|
||||
if (body != NULL) {
|
||||
char *message = xmpp_stanza_get_text(body);
|
||||
if (message != NULL) {
|
||||
prof_handle_room_broadcast(from, message);
|
||||
handle_room_broadcast(from, message);
|
||||
xmpp_free(ctx, message);
|
||||
}
|
||||
}
|
||||
@ -279,7 +280,7 @@ _groupchat_message_handler(xmpp_conn_t * const conn,
|
||||
if (subject != NULL) {
|
||||
message = xmpp_stanza_get_text(subject);
|
||||
if (message != NULL) {
|
||||
prof_handle_room_subject(jid->barejid, message);
|
||||
handle_room_subject(jid->barejid, message);
|
||||
xmpp_free(ctx, message);
|
||||
}
|
||||
|
||||
@ -292,7 +293,7 @@ _groupchat_message_handler(xmpp_conn_t * const conn,
|
||||
if (body != NULL) {
|
||||
message = xmpp_stanza_get_text(body);
|
||||
if (message != NULL) {
|
||||
prof_handle_room_broadcast(room_jid, message);
|
||||
handle_room_broadcast(room_jid, message);
|
||||
xmpp_free(ctx, message);
|
||||
}
|
||||
}
|
||||
@ -326,9 +327,9 @@ _groupchat_message_handler(xmpp_conn_t * const conn,
|
||||
message = xmpp_stanza_get_text(body);
|
||||
if (message != NULL) {
|
||||
if (delayed) {
|
||||
prof_handle_room_history(jid->barejid, jid->resourcepart, tv_stamp, message);
|
||||
handle_room_history(jid->barejid, jid->resourcepart, tv_stamp, message);
|
||||
} else {
|
||||
prof_handle_room_message(jid->barejid, jid->resourcepart, message);
|
||||
handle_room_message(jid->barejid, jid->resourcepart, message);
|
||||
}
|
||||
xmpp_free(ctx, message);
|
||||
}
|
||||
@ -353,7 +354,7 @@ _chat_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
if (body != NULL) {
|
||||
char *message = xmpp_stanza_get_text(body);
|
||||
if (message != NULL) {
|
||||
prof_handle_duck_result(message);
|
||||
handle_duck_result(message);
|
||||
xmpp_free(ctx, message);
|
||||
}
|
||||
}
|
||||
@ -373,9 +374,9 @@ _chat_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
char *message = xmpp_stanza_get_text(body);
|
||||
if (message != NULL) {
|
||||
if (delayed) {
|
||||
prof_handle_delayed_message(jid->str, message, tv_stamp, TRUE);
|
||||
handle_delayed_message(jid->str, message, tv_stamp, TRUE);
|
||||
} else {
|
||||
prof_handle_incoming_message(jid->str, message, TRUE);
|
||||
handle_incoming_message(jid->str, message, TRUE);
|
||||
}
|
||||
xmpp_free(ctx, message);
|
||||
}
|
||||
@ -407,10 +408,10 @@ _chat_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
if (recipient_supports && (!delayed)) {
|
||||
if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_COMPOSING) != NULL) {
|
||||
if (prefs_get_boolean(PREF_NOTIFY_TYPING) || prefs_get_boolean(PREF_INTYPE)) {
|
||||
prof_handle_typing(jid->barejid);
|
||||
handle_typing(jid->barejid);
|
||||
}
|
||||
} else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_GONE) != NULL) {
|
||||
prof_handle_gone(jid->barejid);
|
||||
handle_gone(jid->barejid);
|
||||
} else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_PAUSED) != NULL) {
|
||||
// do something
|
||||
} else if (xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_INACTIVE) != NULL) {
|
||||
@ -426,9 +427,9 @@ _chat_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
char *message = xmpp_stanza_get_text(body);
|
||||
if (message != NULL) {
|
||||
if (delayed) {
|
||||
prof_handle_delayed_message(jid->barejid, message, tv_stamp, FALSE);
|
||||
handle_delayed_message(jid->barejid, message, tv_stamp, FALSE);
|
||||
} else {
|
||||
prof_handle_incoming_message(jid->barejid, message, FALSE);
|
||||
handle_incoming_message(jid->barejid, message, FALSE);
|
||||
}
|
||||
xmpp_free(ctx, message);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user