aboutsummaryrefslogtreecommitdiffstats
path: root/facebook/facebook.c
diff options
context:
space:
mode:
authorjgeboski <jgeboski@gmail.com>2016-01-14 17:32:47 -0500
committerjgeboski <jgeboski@gmail.com>2016-01-14 17:32:47 -0500
commitc18f6b62513b14b54e28743e25dc5f81d35452e3 (patch)
tree5928ce09f85ca40d65e026f73b2c00fec8f4a10c /facebook/facebook.c
parentd503f03278e549270fc053e612aea8d5c2f3b595 (diff)
downloadbitlbee-facebook-c18f6b62513b14b54e28743e25dc5f81d35452e3.tar.gz
bitlbee-facebook-c18f6b62513b14b54e28743e25dc5f81d35452e3.tar.bz2
bitlbee-facebook-c18f6b62513b14b54e28743e25dc5f81d35452e3.tar.xz
Refactored the fbchats printing
Diffstat (limited to 'facebook/facebook.c')
-rw-r--r--facebook/facebook.c39
1 files changed, 14 insertions, 25 deletions
diff --git a/facebook/facebook.c b/facebook/facebook.c
index c060a57..f490feb 100644
--- a/facebook/facebook.c
+++ b/facebook/facebook.c
@@ -541,10 +541,9 @@ fb_cb_api_threads(FbApi *api, GSList *thrds, gpointer data)
FbApiThread *thrd;
FbApiUser *user;
FbData *fata = data;
- GSList *phrds = NULL;
GSList *l;
GSList *m;
- GString *lines;
+ GString *line;
guint i;
guint j;
struct im_connection *ic;
@@ -552,55 +551,45 @@ fb_cb_api_threads(FbApi *api, GSList *thrds, gpointer data)
ic = fb_data_get_connection(fata);
fb_data_clear_threads(fata);
- for (l = thrds, i = 0; (l != NULL) && (i < 25); l = l->next, i++) {
- thrd = l->data;
-
- if (g_slist_length(thrd->users) >= 2) {
- phrds = g_slist_prepend(phrds, thrd);
- }
- }
-
- if (phrds == NULL) {
+ if (thrds == NULL) {
imcb_log(ic, "No chats to display.");
return;
}
- lines = g_string_new(NULL);
+ line = g_string_new(NULL);
imcb_log(ic, "%2s %-20s %s", "ID", "Topic", "Participants");
- phrds = g_slist_reverse(phrds);
- for (l = phrds, i = 1; l != NULL; l = l->next, i++) {
+ for (l = thrds, i = 1; l != NULL; l = l->next, i++) {
thrd = l->data;
fb_data_add_thread_tail(fata, thrd->tid);
- g_string_printf(lines, "%2d", i);
+ g_string_printf(line, "%2d", i);
if (thrd->topic != NULL) {
if (strlen(thrd->topic) > 20) {
for (j = 16; g_ascii_isspace(thrd->topic[j]) && (j > 0); j--);
- g_string_append_printf(lines, " %-.*s...", ++j, thrd->topic);
- g_string_append_printf(lines, "%*s", 17 - j, "");
+ g_string_append_printf(line, " %-.*s...", ++j, thrd->topic);
+ g_string_append_printf(line, "%*s", 17 - j, "");
} else {
- g_string_append_printf(lines, " %-20s", thrd->topic);
+ g_string_append_printf(line, " %-20s", thrd->topic);
}
} else {
- g_string_append_printf(lines, " %20s", "");
+ g_string_append_printf(line, " %20s", "");
}
for (m = thrd->users, j = 0; (m != NULL) && (j < 3); m = m->next, j++) {
user = m->data;
- g_string_append(lines, (j != 0) ? ", " : " ");
- g_string_append(lines, user->name);
+ g_string_append(line, (j != 0) ? ", " : " ");
+ g_string_append(line, user->name);
}
if (m != NULL) {
- g_string_append(lines, "...");
+ g_string_append(line, ", ...");
}
- imcb_log(ic, "%s", lines->str);
+ imcb_log(ic, "%s", line->str);
}
- g_string_free(lines, TRUE);
- g_slist_free(phrds);
+ g_string_free(line, TRUE);
}
static void