mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Moved presence handlers to server_events
This commit is contained in:
parent
a54518f2d4
commit
4bcd766d34
131
src/profanity.c
131
src/profanity.c
@ -149,38 +149,6 @@ prof_handle_group_remove(const char * const contact,
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_subscription(const char *from, jabber_subscr_t type)
|
||||
{
|
||||
switch (type) {
|
||||
case PRESENCE_SUBSCRIBE:
|
||||
/* TODO: auto-subscribe if needed */
|
||||
cons_show("Received authorization request from %s", from);
|
||||
log_info("Received authorization request from %s", from);
|
||||
ui_print_system_msg_from_recipient(from, "Authorization request, type '/sub allow' to accept or '/sub deny' to reject");
|
||||
ui_current_page_off();
|
||||
if (prefs_get_boolean(PREF_NOTIFY_SUB)) {
|
||||
notify_subscription(from);
|
||||
}
|
||||
break;
|
||||
case PRESENCE_SUBSCRIBED:
|
||||
cons_show("Subscription received from %s", from);
|
||||
log_info("Subscription received from %s", from);
|
||||
ui_print_system_msg_from_recipient(from, "Subscribed");
|
||||
ui_current_page_off();
|
||||
break;
|
||||
case PRESENCE_UNSUBSCRIBED:
|
||||
cons_show("%s deleted subscription", from);
|
||||
log_info("%s deleted subscription", from);
|
||||
ui_print_system_msg_from_recipient(from, "Unsubscribed");
|
||||
ui_current_page_off();
|
||||
break;
|
||||
default:
|
||||
/* unknown type */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_roster_add(const char * const barejid, const char * const name)
|
||||
{
|
||||
@ -207,105 +175,6 @@ prof_handle_disconnect(const char * const jid)
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_room_roster_complete(const char * const room)
|
||||
{
|
||||
muc_set_roster_received(room);
|
||||
GList *roster = muc_get_roster(room);
|
||||
ui_room_roster(room, roster, NULL);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_room_member_presence(const char * const room,
|
||||
const char * const nick, const char * const show,
|
||||
const char * const status, const char * const caps_str)
|
||||
{
|
||||
gboolean updated = muc_add_to_roster(room, nick, show, status, caps_str);
|
||||
|
||||
if (updated) {
|
||||
ui_room_member_presence(room, nick, show, status);
|
||||
ui_current_page_off();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_room_member_online(const char * const room, const char * const nick,
|
||||
const char * const show, const char * const status,
|
||||
const char * const caps_str)
|
||||
{
|
||||
muc_add_to_roster(room, nick, show, status, caps_str);
|
||||
ui_room_member_online(room, nick, show, status);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_room_member_offline(const char * const room, const char * const nick,
|
||||
const char * const show, const char * const status)
|
||||
{
|
||||
muc_remove_from_roster(room, nick);
|
||||
ui_room_member_offline(room, nick);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_leave_room(const char * const room)
|
||||
{
|
||||
muc_leave_room(room);
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_contact_online(char *contact, Resource *resource,
|
||||
GDateTime *last_activity)
|
||||
{
|
||||
gboolean updated = roster_update_presence(contact, resource, last_activity);
|
||||
|
||||
if (updated && prefs_get_boolean(PREF_STATUSES)) {
|
||||
PContact result = roster_get_contact(contact);
|
||||
if (p_contact_subscription(result) != NULL) {
|
||||
if (strcmp(p_contact_subscription(result), "none") != 0) {
|
||||
const char *show = string_from_resource_presence(resource->presence);
|
||||
ui_contact_online(contact, resource->name, show, resource->status, last_activity);
|
||||
ui_current_page_off();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_contact_offline(char *contact, char *resource, char *status)
|
||||
{
|
||||
gboolean updated = roster_contact_offline(contact, resource, status);
|
||||
|
||||
if (resource != NULL && updated && prefs_get_boolean(PREF_STATUSES)) {
|
||||
Jid *jid = jid_create_from_bare_and_resource(contact, resource);
|
||||
PContact result = roster_get_contact(contact);
|
||||
if (p_contact_subscription(result) != NULL) {
|
||||
if (strcmp(p_contact_subscription(result), "none") != 0) {
|
||||
ui_contact_offline(jid->fulljid, "offline", status);
|
||||
ui_current_page_off();
|
||||
}
|
||||
}
|
||||
jid_destroy(jid);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_room_member_nick_change(const char * const room,
|
||||
const char * const old_nick, const char * const nick)
|
||||
{
|
||||
ui_room_member_nick_change(room, old_nick, nick);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_room_nick_change(const char * const room,
|
||||
const char * const nick)
|
||||
{
|
||||
ui_room_nick_change(room, nick);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
prof_handle_idle(void)
|
||||
{
|
||||
|
@ -30,25 +30,7 @@ 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_contact_online(char *contact, Resource *resource,
|
||||
GDateTime *last_activity);
|
||||
void prof_handle_contact_offline(char *contact, char *show, char *status);
|
||||
void prof_handle_subscription(const char *from, jabber_subscr_t type);
|
||||
void prof_handle_roster(GSList *roster);
|
||||
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,
|
||||
const char * const caps_str);
|
||||
void prof_handle_room_member_offline(const char * const room,
|
||||
const char * const nick, const char * const show, const char * const status);
|
||||
void prof_handle_room_member_presence(const char * const room,
|
||||
const char * const nick, const char * const show,
|
||||
const char * const status, const char * const caps_str);
|
||||
void prof_handle_leave_room(const char * const room);
|
||||
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_idle(void);
|
||||
void prof_handle_activity(void);
|
||||
void prof_handle_duck_help(const char * const result);
|
||||
|
@ -20,6 +20,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "chat_session.h"
|
||||
#include "log.h"
|
||||
#include "muc.h"
|
||||
@ -210,3 +212,134 @@ handle_gone(const char * const from)
|
||||
ui_recipient_gone(from);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
handle_subscription(const char *from, jabber_subscr_t type)
|
||||
{
|
||||
switch (type) {
|
||||
case PRESENCE_SUBSCRIBE:
|
||||
/* TODO: auto-subscribe if needed */
|
||||
cons_show("Received authorization request from %s", from);
|
||||
log_info("Received authorization request from %s", from);
|
||||
ui_print_system_msg_from_recipient(from, "Authorization request, type '/sub allow' to accept or '/sub deny' to reject");
|
||||
ui_current_page_off();
|
||||
if (prefs_get_boolean(PREF_NOTIFY_SUB)) {
|
||||
notify_subscription(from);
|
||||
}
|
||||
break;
|
||||
case PRESENCE_SUBSCRIBED:
|
||||
cons_show("Subscription received from %s", from);
|
||||
log_info("Subscription received from %s", from);
|
||||
ui_print_system_msg_from_recipient(from, "Subscribed");
|
||||
ui_current_page_off();
|
||||
break;
|
||||
case PRESENCE_UNSUBSCRIBED:
|
||||
cons_show("%s deleted subscription", from);
|
||||
log_info("%s deleted subscription", from);
|
||||
ui_print_system_msg_from_recipient(from, "Unsubscribed");
|
||||
ui_current_page_off();
|
||||
break;
|
||||
default:
|
||||
/* unknown type */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handle_contact_offline(char *contact, char *resource, char *status)
|
||||
{
|
||||
gboolean updated = roster_contact_offline(contact, resource, status);
|
||||
|
||||
if (resource != NULL && updated && prefs_get_boolean(PREF_STATUSES)) {
|
||||
Jid *jid = jid_create_from_bare_and_resource(contact, resource);
|
||||
PContact result = roster_get_contact(contact);
|
||||
if (p_contact_subscription(result) != NULL) {
|
||||
if (strcmp(p_contact_subscription(result), "none") != 0) {
|
||||
ui_contact_offline(jid->fulljid, "offline", status);
|
||||
ui_current_page_off();
|
||||
}
|
||||
}
|
||||
jid_destroy(jid);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handle_contact_online(char *contact, Resource *resource,
|
||||
GDateTime *last_activity)
|
||||
{
|
||||
gboolean updated = roster_update_presence(contact, resource, last_activity);
|
||||
|
||||
if (updated && prefs_get_boolean(PREF_STATUSES)) {
|
||||
PContact result = roster_get_contact(contact);
|
||||
if (p_contact_subscription(result) != NULL) {
|
||||
if (strcmp(p_contact_subscription(result), "none") != 0) {
|
||||
const char *show = string_from_resource_presence(resource->presence);
|
||||
ui_contact_online(contact, resource->name, show, resource->status, last_activity);
|
||||
ui_current_page_off();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handle_leave_room(const char * const room)
|
||||
{
|
||||
muc_leave_room(room);
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_nick_change(const char * const room,
|
||||
const char * const nick)
|
||||
{
|
||||
ui_room_nick_change(room, nick);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_roster_complete(const char * const room)
|
||||
{
|
||||
muc_set_roster_received(room);
|
||||
GList *roster = muc_get_roster(room);
|
||||
ui_room_roster(room, roster, NULL);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_member_presence(const char * const room,
|
||||
const char * const nick, const char * const show,
|
||||
const char * const status, const char * const caps_str)
|
||||
{
|
||||
gboolean updated = muc_add_to_roster(room, nick, show, status, caps_str);
|
||||
|
||||
if (updated) {
|
||||
ui_room_member_presence(room, nick, show, status);
|
||||
ui_current_page_off();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_member_online(const char * const room, const char * const nick,
|
||||
const char * const show, const char * const status,
|
||||
const char * const caps_str)
|
||||
{
|
||||
muc_add_to_roster(room, nick, show, status, caps_str);
|
||||
ui_room_member_online(room, nick, show, status);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_member_offline(const char * const room, const char * const nick,
|
||||
const char * const show, const char * const status)
|
||||
{
|
||||
muc_remove_from_roster(room, nick);
|
||||
ui_room_member_offline(room, nick);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
||||
void
|
||||
handle_room_member_nick_change(const char * const room,
|
||||
const char * const old_nick, const char * const nick)
|
||||
{
|
||||
ui_room_member_nick_change(room, old_nick, nick);
|
||||
ui_current_page_off();
|
||||
}
|
||||
|
@ -48,5 +48,23 @@ 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);
|
||||
void handle_subscription(const char *from, jabber_subscr_t type);
|
||||
void handle_contact_offline(char *contact, char *resource, char *status);
|
||||
void handle_contact_online(char *contact, Resource *resource,
|
||||
GDateTime *last_activity);
|
||||
void handle_leave_room(const char * const room);
|
||||
void handle_room_nick_change(const char * const room,
|
||||
const char * const nick);
|
||||
void handle_room_roster_complete(const char * const room);
|
||||
void handle_room_member_presence(const char * const room,
|
||||
const char * const nick, const char * const show,
|
||||
const char * const status, const char * const caps_str);
|
||||
void handle_room_member_online(const char * const room, const char * const nick,
|
||||
const char * const show, const char * const status,
|
||||
const char * const caps_str);
|
||||
void handle_room_member_offline(const char * const room, const char * const nick,
|
||||
const char * const show, const char * const status);
|
||||
void handle_room_member_nick_change(const char * const room,
|
||||
const char * const old_nick, const char * const nick);
|
||||
|
||||
#endif
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "log.h"
|
||||
#include "muc.h"
|
||||
#include "profanity.h"
|
||||
#include "server_events.h"
|
||||
#include "xmpp/capabilities.h"
|
||||
#include "xmpp/connection.h"
|
||||
#include "xmpp/stanza.h"
|
||||
@ -336,7 +337,7 @@ _unsubscribed_handler(xmpp_conn_t * const conn,
|
||||
Jid *from_jid = jid_create(from);
|
||||
log_debug("Unsubscribed presence handler fired for %s", from);
|
||||
|
||||
prof_handle_subscription(from_jid->barejid, PRESENCE_UNSUBSCRIBED);
|
||||
handle_subscription(from_jid->barejid, PRESENCE_UNSUBSCRIBED);
|
||||
autocomplete_remove(sub_requests_ac, from_jid->barejid);
|
||||
|
||||
jid_destroy(from_jid);
|
||||
@ -352,7 +353,7 @@ _subscribed_handler(xmpp_conn_t * const conn,
|
||||
Jid *from_jid = jid_create(from);
|
||||
log_debug("Subscribed presence handler fired for %s", from);
|
||||
|
||||
prof_handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBED);
|
||||
handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBED);
|
||||
autocomplete_remove(sub_requests_ac, from_jid->barejid);
|
||||
|
||||
jid_destroy(from_jid);
|
||||
@ -372,7 +373,7 @@ _subscribe_handler(xmpp_conn_t * const conn,
|
||||
return 1;
|
||||
}
|
||||
|
||||
prof_handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBE);
|
||||
handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBE);
|
||||
autocomplete_add(sub_requests_ac, from_jid->barejid);
|
||||
|
||||
jid_destroy(from_jid);
|
||||
@ -400,11 +401,11 @@ _unavailable_handler(xmpp_conn_t * const conn,
|
||||
|
||||
if (strcmp(my_jid->barejid, from_jid->barejid) !=0) {
|
||||
if (from_jid->resourcepart != NULL) {
|
||||
prof_handle_contact_offline(from_jid->barejid, from_jid->resourcepart, status_str);
|
||||
handle_contact_offline(from_jid->barejid, from_jid->resourcepart, status_str);
|
||||
|
||||
// hack for servers that do not send full jid with unavailable presence
|
||||
} else {
|
||||
prof_handle_contact_offline(from_jid->barejid, "__prof_default", status_str);
|
||||
handle_contact_offline(from_jid->barejid, "__prof_default", status_str);
|
||||
}
|
||||
} else {
|
||||
if (from_jid->resourcepart != NULL) {
|
||||
@ -499,7 +500,7 @@ _available_handler(xmpp_conn_t * const conn,
|
||||
|
||||
// contact presence
|
||||
} else {
|
||||
prof_handle_contact_online(from_jid->barejid, resource,
|
||||
handle_contact_online(from_jid->barejid, resource,
|
||||
last_activity);
|
||||
}
|
||||
|
||||
@ -615,17 +616,17 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
if (new_nick != NULL) {
|
||||
muc_set_room_pending_nick_change(room, new_nick);
|
||||
} else {
|
||||
prof_handle_leave_room(room);
|
||||
handle_leave_room(room);
|
||||
}
|
||||
|
||||
// handle self nick change
|
||||
} else if (muc_is_room_pending_nick_change(room)) {
|
||||
muc_complete_room_nick_change(room, nick);
|
||||
prof_handle_room_nick_change(room, nick);
|
||||
handle_room_nick_change(room, nick);
|
||||
|
||||
// handle roster complete
|
||||
} else if (!muc_get_roster_received(room)) {
|
||||
prof_handle_room_roster_complete(room);
|
||||
handle_room_roster_complete(room);
|
||||
|
||||
}
|
||||
|
||||
@ -653,7 +654,7 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
free(new_nick);
|
||||
}
|
||||
} else {
|
||||
prof_handle_room_member_offline(room, nick, "offline", status_str);
|
||||
handle_room_member_offline(room, nick, "offline", status_str);
|
||||
}
|
||||
} else {
|
||||
char *show_str = stanza_get_show(stanza, "online");
|
||||
@ -664,13 +665,13 @@ _room_presence_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
|
||||
|
||||
if (old_nick != NULL) {
|
||||
muc_add_to_roster(room, nick, show_str, status_str, caps_key);
|
||||
prof_handle_room_member_nick_change(room, old_nick, nick);
|
||||
handle_room_member_nick_change(room, old_nick, nick);
|
||||
free(old_nick);
|
||||
} else {
|
||||
if (!muc_nick_in_roster(room, nick)) {
|
||||
prof_handle_room_member_online(room, nick, show_str, status_str, caps_key);
|
||||
handle_room_member_online(room, nick, show_str, status_str, caps_key);
|
||||
} else {
|
||||
prof_handle_room_member_presence(room, nick, show_str, status_str, caps_key);
|
||||
handle_room_member_presence(room, nick, show_str, status_str, caps_key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user