From d2a2e5a39223272bcb7eb5a61d31b2b65a4efabb Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Mon, 22 Jul 2019 16:01:23 +0200 Subject: [PATCH] move chat window title code where it belongs --- ncdc/src/mainwindow.c | 27 --------------------------- ncdc/src/textview.c | 23 +++++++++++++++-------- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/ncdc/src/mainwindow.c b/ncdc/src/mainwindow.c index c152652..41f43aa 100644 --- a/ncdc/src/mainwindow.c +++ b/ncdc/src/mainwindow.c @@ -512,7 +512,6 @@ ncdc_textview_t ncdc_mainwindow_switch_or_add(ncdc_mainwindow_t n, dc_channel_t c) { ncdc_textview_t v = NULL; - wchar_t *name = NULL; return_if_true(n == NULL || c == NULL, NULL); return_if_true(!is_logged_in(), NULL); @@ -527,32 +526,6 @@ ncdc_mainwindow_switch_or_add(ncdc_mainwindow_t n, dc_channel_t c) ncdc_textview_set_account(v, dc_session_me(current_session)); ncdc_textview_set_channel(v, c); - if (dc_channel_type(c) == CHANNEL_TYPE_GUILD_TEXT) { - aswprintf(&name, L"#%s", dc_channel_name(c)); - } else if (dc_channel_type(c) == CHANNEL_TYPE_GUILD_VOICE) { - aswprintf(&name, L">%s", dc_channel_name(c)); - } else if (dc_channel_is_dm(c)) { - size_t namelen = 0, i = 0; - FILE *f = open_wmemstream(&name, &namelen); - - for (i = 0; i < dc_channel_recipients(c); i++) { - dc_account_t rec = dc_channel_nth_recipient(c, i); - if (dc_account_fullname(rec) != NULL) { - fwprintf(f, L"%s", dc_account_fullname(rec)); - if (i < dc_channel_recipients(c)-1) { - fputwc('/', f); - } - } - } - - fclose(f); - } - - if (name != NULL) { - ncdc_textview_set_title(v, name); - free(name); - } - g_ptr_array_add(n->views, v); ncdc_mainwindow_switch_view(n, v); } diff --git a/ncdc/src/textview.c b/ncdc/src/textview.c index 1383ad6..9bea80d 100644 --- a/ncdc/src/textview.c +++ b/ncdc/src/textview.c @@ -50,18 +50,25 @@ static void ncdc_textview_maketitle(ncdc_textview_t v) size_t i = 0; wchar_t *buf = NULL; size_t buflen = 0; - FILE *f = open_wmemstream(&buf, &buflen); size_t rlen = dc_channel_recipients(v->channel); + int type = dc_channel_type(v->channel); - for (i = 0; i < rlen; i++) { - dc_account_t r = dc_channel_nth_recipient(v->channel, i); - fwprintf(f, L"%s", dc_account_fullname(r)); - if (i < (rlen-1)) { - fwprintf(f, L","); + if (type == CHANNEL_TYPE_GUILD_TEXT) { + aswprintf(&buf, L"#%s", dc_channel_name(v->channel)); + } else if (type == CHANNEL_TYPE_GUILD_VOICE) { + aswprintf(&buf, L">%s", dc_channel_name(v->channel)); + } else if (dc_channel_is_dm(v->channel)) { + FILE *f = open_wmemstream(&buf, &buflen); + for (i = 0; i < rlen; i++) { + dc_account_t r = dc_channel_nth_recipient(v->channel, i); + fwprintf(f, L"%s", dc_account_fullname(r)); + if (i < (rlen-1)) { + fwprintf(f, L"/"); + } } - } - fclose(f); + fclose(f); + } free(v->title); v->title = buf;