1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Inlined ui_contact_online and ui_contact_offline

This commit is contained in:
James Booth 2014-01-19 17:51:32 +00:00
parent 69f2f4a16f
commit 5610f70b35
3 changed files with 55 additions and 73 deletions

View File

@ -21,6 +21,7 @@
*/
#include <string.h>
#include <stdlib.h>
#include "chat_session.h"
#include "log.h"
@ -28,6 +29,9 @@
#include "config/preferences.h"
#include "roster_list.h"
#include "ui/ui.h"
#include "ui/windows.h"
#ifdef HAVE_LIBOTR
#include "otr.h"
#endif
@ -288,16 +292,35 @@ handle_subscription(const char *from, jabber_subscr_t type)
}
void
handle_contact_offline(char *contact, char *resource, char *status)
handle_contact_offline(char *barejid, char *resource, char *status)
{
gboolean updated = roster_contact_offline(contact, resource, status);
gboolean updated = roster_contact_offline(barejid, 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);
Jid *jid = jid_create_from_bare_and_resource(barejid, resource);
PContact contact = roster_get_contact(barejid);
if (p_contact_subscription(contact) != NULL) {
if (strcmp(p_contact_subscription(contact), "none") != 0) {
char *display_str = p_contact_create_display_string(contact, jid->resourcepart);
ProfWin *console = wins_get_console();
win_show_status_string(console, display_str, "offline", status, NULL, "--",
"offline");
ProfWin *window = wins_get_by_recipient(barejid);
if (window != NULL) {
win_show_status_string(window, display_str, "offline", status, NULL, "--",
"offline");
}
free(display_str);
if (wins_is_current(console)) {
wins_refresh_current();
} else if ((window != NULL) && (wins_is_current(window))) {
wins_refresh_current();
}
ui_current_page_off();
}
}
@ -306,17 +329,36 @@ handle_contact_offline(char *contact, char *resource, char *status)
}
void
handle_contact_online(char *contact, Resource *resource,
handle_contact_online(char *barejid, Resource *resource,
GDateTime *last_activity)
{
gboolean updated = roster_update_presence(contact, resource, last_activity);
gboolean updated = roster_update_presence(barejid, 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) {
PContact contact = roster_get_contact(barejid);
if (p_contact_subscription(contact) != NULL) {
if (strcmp(p_contact_subscription(contact), "none") != 0) {
const char *show = string_from_resource_presence(resource->presence);
ui_contact_online(contact, resource->name, show, resource->status, last_activity);
char *display_str = p_contact_create_display_string(contact, resource->name);
ProfWin *console = wins_get_console();
win_show_status_string(console, display_str, show, resource->status, last_activity,
"++", "online");
ProfWin *window = wins_get_by_recipient(barejid);
if (window != NULL) {
win_show_status_string(window, display_str, show, resource->status,
last_activity, "++", "online");
}
free(display_str);
if (wins_is_current(console)) {
wins_refresh_current();
} else if ((window != NULL) && (wins_is_current(window))) {
wins_refresh_current();
}
ui_current_page_off();
}
}

View File

@ -354,60 +354,6 @@ _ui_handle_error_message(const char * const from, const char * const err_msg)
ui_print_error_from_recipient(from, err_msg);
}
static void
_ui_contact_online(const char * const barejid, const char * const resource,
const char * const show, const char * const status, GDateTime *last_activity)
{
PContact contact = roster_get_contact(barejid);
char *display_str = p_contact_create_display_string(contact, resource);
ProfWin *console = wins_get_console();
win_show_status_string(console, display_str, show, status, last_activity,
"++", "online");
ProfWin *window = wins_get_by_recipient(barejid);
if (window != NULL) {
win_show_status_string(window, display_str, show, status,
last_activity, "++", "online");
}
free(display_str);
if (wins_is_current(console)) {
wins_refresh_current();
} else if ((window != NULL) && (wins_is_current(window))) {
wins_refresh_current();
}
}
static void
_ui_contact_offline(const char * const from, const char * const show,
const char * const status)
{
Jid *jidp = jid_create(from);
PContact contact = roster_get_contact(jidp->barejid);
char *display_str = p_contact_create_display_string(contact, jidp->resourcepart);
ProfWin *console = wins_get_console();
win_show_status_string(console, display_str, show, status, NULL, "--",
"offline");
ProfWin *window = wins_get_by_recipient(jidp->barejid);
if (window != NULL) {
win_show_status_string(window, display_str, show, status, NULL, "--",
"offline");
}
jid_destroy(jidp);
free(display_str);
if (wins_is_current(console)) {
wins_refresh_current();
} else if ((window != NULL) && (wins_is_current(window))) {
wins_refresh_current();
}
}
static void
_ui_disconnected(void)
{
@ -1675,8 +1621,6 @@ ui_init_module(void)
ui_group_added = _ui_group_added;
ui_group_removed = _ui_group_removed;
ui_handle_error_message = _ui_handle_error_message;
ui_contact_online = _ui_contact_online;
ui_contact_offline = _ui_contact_offline;
ui_disconnected = _ui_disconnected;
ui_handle_special_keys = _ui_handle_special_keys;
ui_close_connected_win = _ui_close_connected_win;

View File

@ -100,10 +100,6 @@ char * (*ui_ask_password)(void);
void (*ui_contact_typing)(const char * const from);
void (*ui_incoming_msg)(const char * const from, const char * const message,
GTimeVal *tv_stamp, gboolean priv);
void (*ui_contact_online)(const char * const barejid, const char * const resource,
const char * const show, const char * const status, GDateTime *last_activity);
void (*ui_contact_offline)(const char * const from, const char * const show,
const char * const status);
void (*ui_disconnected)(void);
void (*ui_recipient_gone)(const char * const barejid);
void (*ui_outgoing_msg)(const char * const from, const char * const to,