diff options
author | dequis <dx@dxzone.com.ar> | 2017-01-07 12:52:14 -0300 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2017-01-07 12:52:14 -0300 |
commit | 878c1dc70a3a5838e2f2ed18be0643696f5c8b92 (patch) | |
tree | da1b57f735dcf055da098a64a2fcf78fdf94e63f /facebook | |
parent | 62291d6a8d4cd4f6aea86d73749ea7f59ad99bb8 (diff) | |
download | bitlbee-facebook-878c1dc70a3a5838e2f2ed18be0643696f5c8b92.tar.gz bitlbee-facebook-878c1dc70a3a5838e2f2ed18be0643696f5c8b92.tar.bz2 bitlbee-facebook-878c1dc70a3a5838e2f2ed18be0643696f5c8b92.tar.xz |
Refactor, split chat topic string generation to a separate function
Diffstat (limited to 'facebook')
-rw-r--r-- | facebook/facebook.c | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/facebook/facebook.c b/facebook/facebook.c index cf3e8c1..55f9c37 100644 --- a/facebook/facebook.c +++ b/facebook/facebook.c @@ -483,6 +483,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) { @@ -490,9 +516,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; @@ -504,24 +530,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; |