move chat window title code where it belongs

This commit is contained in:
Florian Stinglmayr 2019-07-22 16:01:23 +02:00
parent 2776503fac
commit d2a2e5a392
2 changed files with 15 additions and 35 deletions

View File

@ -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);
}

View File

@ -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;