aboutsummaryrefslogtreecommitdiffstats
path: root/facebook/facebook.c
diff options
context:
space:
mode:
Diffstat (limited to 'facebook/facebook.c')
-rw-r--r--facebook/facebook.c80
1 files changed, 61 insertions, 19 deletions
diff --git a/facebook/facebook.c b/facebook/facebook.c
index ae4ba63..15dd6c6 100644
--- a/facebook/facebook.c
+++ b/facebook/facebook.c
@@ -513,6 +513,32 @@ fb_cb_api_presences(FbApi *api, GSList *press, gpointer data)
}
}
+static gchar *
+fb_thread_topic_gen(FbApiThread *thrd)
+{
+ GSList *l;
+ GString *gstr;
+ FbApiUser *user;
+
+ if (thrd->topic != NULL) {
+ return g_strdup(thrd->topic);
+ }
+
+ gstr = g_string_new(NULL);
+
+ for (l = thrd->users; l != NULL; l = l->next) {
+ user = l->data;
+
+ if (gstr->len > 0) {
+ g_string_append(gstr, ", ");
+ }
+
+ g_string_append(gstr, user->name);
+ }
+
+ return g_string_free(gstr, FALSE);
+}
+
static void
fb_cb_api_thread(FbApi *api, FbApiThread *thrd, gpointer data)
{
@@ -520,9 +546,9 @@ fb_cb_api_thread(FbApi *api, FbApiThread *thrd, gpointer data)
FbApiUser *user;
FbData *fata = data;
gchar id[FB_ID_STRMAX];
+ gchar *topic;
GList *h;
GSList *l;
- GString *gstr;
struct groupchat *gc;
struct im_connection *ic;
@@ -534,24 +560,9 @@ fb_cb_api_thread(FbApi *api, FbApiThread *thrd, gpointer data)
return;
}
- if (thrd->topic == NULL) {
- gstr = g_string_new(NULL);
-
- for (l = thrd->users; l != NULL; l = l->next) {
- user = l->data;
-
- if (gstr->len > 0) {
- g_string_append(gstr, ", ");
- }
-
- g_string_append(gstr, user->name);
- }
-
- imcb_chat_topic(gc, NULL, gstr->str, 0);
- g_string_free(gstr, TRUE);
- } else {
- imcb_chat_topic(gc, NULL, (gchar *) thrd->topic, 0);
- }
+ topic = fb_thread_topic_gen(thrd);
+ imcb_chat_topic(gc, NULL, topic, 0);
+ g_free(topic);
for (l = thrd->users; l != NULL; l = l->next) {
user = l->data;
@@ -590,6 +601,33 @@ fb_cb_api_thread_create(FbApi *api, FbId tid, gpointer data)
}
static void
+fb_cb_api_thread_kicked(FbApi *api, FbApiThread *thrd, gpointer data)
+{
+ FbData *fata = data;
+ gchar id[FB_ID_STRMAX];
+ gchar *topic;
+ struct groupchat *gc;
+ struct im_connection *ic;
+
+ FB_ID_TO_STR(thrd->tid, id);
+ ic = fb_data_get_connection(fata);
+ gc = bee_chat_by_title(ic->bee, ic, id);
+
+ if (G_UNLIKELY(gc == NULL)) {
+ return;
+ }
+
+ topic = fb_thread_topic_gen(thrd);
+ imcb_chat_topic(gc, NULL, topic, 0);
+ g_free(topic);
+
+ imcb_chat_log(gc, "You have been removed from this chat");
+
+ fb_data_remove_groupchat(fata, gc);
+ imcb_chat_free(gc);
+}
+
+static void
fb_cb_api_threads(FbApi *api, GSList *thrds, gpointer data)
{
FbApiThread *thrd;
@@ -763,6 +801,10 @@ fb_login(account_t *acc)
G_CALLBACK(fb_cb_api_thread_create),
fata);
g_signal_connect(api,
+ "thread-kicked",
+ G_CALLBACK(fb_cb_api_thread_kicked),
+ fata);
+ g_signal_connect(api,
"threads",
G_CALLBACK(fb_cb_api_threads),
fata);