Commit 8332e99a authored by Andrea Schaefer's avatar Andrea Schaefer

Add folks contact handling ro blist

parent e2265a86
......@@ -23,9 +23,9 @@
#include "chatty-conversation.h"
#include "chatty-history.h"
#include "chatty-utils.h"
#include "chatty-folks.h"
#define HANDY_USE_UNSTABLE_API
#include <handy.h>
#include <libebook-contacts/libebook-contacts.h>
static void chatty_blist_new_node (PurpleBlistNode *node);
......@@ -61,12 +61,23 @@ row_selected_cb (GtkListBox *box,
PurpleBlistNode *node;
PurpleAccount *account;
PurpleChat *chat;
const char *chat_name;
GdkPixbuf *avatar;
const char *chat_name;
const char *number;
chatty_data_t *chatty = chatty_get_data ();
if (row == NULL)
if (row == NULL) {
return;
}
g_object_get (row, "phone_number", &number, NULL);
if (number != NULL) {
chatty_blist_add_buddy_from_uri (number);
return;
}
g_object_get (row, "data", &node, NULL);
......@@ -105,9 +116,9 @@ row_selected_cb (GtkListBox *box,
avatar = chatty_icon_get_buddy_icon (node,
NULL,
CHATTY_ICON_SIZE_MEDIUM,
CHATTY_COLOR_GREY,
FALSE);
CHATTY_ICON_SIZE_MEDIUM,
CHATTY_COLOR_GREY,
FALSE);
chatty_window_update_sub_header_titlebar (avatar, chat_name);
chatty_window_change_view (CHATTY_VIEW_MESSAGE_LIST);
......@@ -500,6 +511,24 @@ cb_do_autojoin (PurpleConnection *gc, gpointer null)
return TRUE;
}
static gint
cb_chatty_blist_sort_contacts (GtkListBoxRow *row1,
GtkListBoxRow *row2,
gpointer user_data)
{
const char *name1, *name2;
g_object_get (row1, "name", &name1, NULL);
g_object_get (row2, "name", &name2, NULL);
if (g_strcmp0 (name1, name2) > 0) {
return TRUE;
}
return 0;
}
// *** end callbacks
......@@ -517,6 +546,23 @@ chatty_get_selected_node (void) {
}
gboolean
chatty_blist_protocol_is_sms (PurpleAccount *account)
{
const gchar *protocol_id;
g_return_val_if_fail (account != NULL, FALSE);
protocol_id = purple_account_get_protocol_id (account);
if (g_strcmp0 (protocol_id, "prpl-mm-sms") == 0) {
return TRUE;
} else {
return FALSE;
}
}
/**
* chatty_blist_buddy_is_displayable:
* @buddy: a PurpleBuddy
......@@ -600,14 +646,15 @@ chatty_blist_chat_list_set_row (void)
void
chatty_blist_add_buddy_from_uri (const char *uri)
{
PurpleAccount *account;
PurpleBuddy *buddy;
GdkPixbuf *avatar;
EPhoneNumber *number;
GtkWindow *window;
char *region;
char *who;
g_autoptr(GError) err = NULL;
PurpleAccount *account;
PurpleBuddy *buddy;
GdkPixbuf *avatar;
GtkWindow *window;
char *who = NULL;
const char *folks_id;
const char *alias;
chatty_data_t *chatty = chatty_get_data ();
account = purple_accounts_find ("SMS", "prpl-mm-sms");
......@@ -615,24 +662,17 @@ chatty_blist_add_buddy_from_uri (const char *uri)
return;
}
region = e_phone_number_get_default_region (NULL);
number = e_phone_number_from_string (uri, region, &err);
who = chatty_utils_format_phonenumber (uri);
if (!number || !e_phone_number_is_supported ()) {
g_warning ("failed to parse %s: %s", uri, err->message);
folks_id = chatty_folks_has_individual_with_phonenumber (uri);
alias = chatty_folks_get_individual_name_by_id (folks_id);
return;
} else {
who = e_phone_number_to_string (number, E_PHONE_NUMBER_FORMAT_E164);
}
g_free (region);
e_phone_number_free (number);
g_return_if_fail (who != NULL);
buddy = purple_find_buddy (account, who);
if (!buddy) {
buddy = purple_buddy_new (account, who, NULL);
buddy = purple_buddy_new (account, who, alias);
purple_blist_add_buddy (buddy, NULL, NULL, NULL);
}
......@@ -647,11 +687,13 @@ chatty_blist_add_buddy_from_uri (const char *uri)
if (avatar) {
chatty_window_update_sub_header_titlebar (avatar,
who);
alias ? alias : who);
}
chatty_window_change_view (CHATTY_VIEW_MESSAGE_LIST);
gtk_widget_hide (GTK_WIDGET(chatty->dialog_new_chat));
window = gtk_application_get_active_window (GTK_APPLICATION (g_application_get_default ()));
gtk_window_present (window);
......@@ -926,7 +968,7 @@ chatty_blist_chat_list_select_first (void)
/**
* chatty_blist_contacts_remove_node:
* @node: a PurpleBlistNode
* @node: a PurpleBlistNode
*
* Removes a node in the contacts list
*
......@@ -1084,7 +1126,7 @@ chatty_blist_create_contact_list (void)
listbox);
gtk_list_box_set_filter_func (GTK_LIST_BOX (listbox), filter_chat_list_cb, chatty->search_entry_contacts, NULL);
gtk_list_box_set_sort_func (GTK_LIST_BOX (listbox), chatty_blist_sort, NULL, NULL);
gtk_list_box_set_sort_func (GTK_LIST_BOX (listbox), cb_chatty_blist_sort_contacts, NULL, NULL);
g_signal_connect (listbox,
"row-activated",
......@@ -1093,6 +1135,12 @@ chatty_blist_create_contact_list (void)
gtk_box_pack_start (GTK_BOX (chatty->pane_view_new_chat), GTK_WIDGET (listbox), TRUE, TRUE, 0);
gtk_widget_show_all (GTK_WIDGET(chatty->pane_view_new_chat));
if (purple_accounts_find ("SMS", "prpl-mm-sms")) {
chatty_folks_init (chatty_get_contacts_list ());
}
}
......@@ -1257,6 +1305,8 @@ chatty_blist_contacts_update_node (PurpleBuddy *buddy,
alias,
account_name,
NULL,
NULL,
NULL,
NULL));
gtk_list_box_row_set_selectable (GTK_LIST_BOX_ROW (chatty_node->row_contact), FALSE);
......@@ -1328,6 +1378,8 @@ chatty_blist_contacts_update_group_chat (PurpleBlistNode *node)
chat_name,
account_name,
NULL,
NULL,
NULL,
NULL));
gtk_widget_show (GTK_WIDGET (chatty_node->row_contact));
gtk_container_add (GTK_CONTAINER (listbox), GTK_WIDGET (chatty_node->row_contact));
......@@ -1459,7 +1511,9 @@ chatty_blist_chats_update_node (PurpleBuddy *buddy,
name,
last_msg_text,
last_msg_ts,
unread_messages));
unread_messages,
NULL,
NULL));
gtk_widget_show (GTK_WIDGET (chatty_node->row_chat));
gtk_container_add (GTK_CONTAINER (listbox), GTK_WIDGET (chatty_node->row_chat));
......@@ -1555,7 +1609,9 @@ chatty_blist_chats_update_group_chat (PurpleBlistNode *node)
chat_name,
last_msg_text,
last_msg_ts,
unread_messages));
unread_messages,
NULL,
NULL));
gtk_widget_show (GTK_WIDGET (chatty_node->row_chat));
gtk_container_add (GTK_CONTAINER (listbox), GTK_WIDGET (chatty_node->row_chat));
......@@ -1636,7 +1692,15 @@ chatty_blist_update_buddy (PurpleBuddyList *list,
chatty_blist_chats_remove_node (node);
}
chatty_blist_contacts_update_node (buddy, node);
if (chatty_blist_protocol_is_sms (account)) {
if (chatty_folks_has_individual_with_phonenumber (who)) {
chatty_blist_contacts_remove_node (node);
} else {
chatty_blist_contacts_update_node (buddy, node);
}
} else {
chatty_blist_contacts_update_node (buddy, node);
}
}
......
......@@ -89,6 +89,7 @@ void chatty_blist_contact_list_add_buddy (void);
void chatty_blist_chat_list_leave_chat (void);
void chatty_blist_chat_list_remove_buddy (void);
int chatty_blist_list_has_children (int list_type);
gboolean chatty_blist_protocol_is_sms (PurpleAccount *account);
void chatty_blist_add_buddy_from_uri (const char *uri);
void chatty_blist_join_group_chat (PurpleAccount *account,
const char *group_chat_id,
......
......@@ -24,6 +24,7 @@
#include "chatty-buddy-list.h"
#include "chatty-connection.h"
#include "chatty-conversation.h"
#include "chatty-folks.h"
static GHashTable *ui_info = NULL;
......@@ -156,6 +157,8 @@ chatty_purple_quit (void)
chatty_xeps_close ();
chatty_folks_close ();
g_application_quit (g_application_get_default ());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment