fix join, and implement joining from guild view
This commit is contained in:
parent
e1f796d053
commit
08d1fcc15d
@ -83,7 +83,7 @@ static void dc_session_handle_ready(dc_session_t s, dc_event_t e)
|
||||
json_t *user = NULL;
|
||||
json_t *relationships = NULL;
|
||||
json_t *presences = NULL;
|
||||
size_t idx = 0;
|
||||
size_t idx = 0, i = 0;
|
||||
json_t *c = NULL;
|
||||
json_t *channels = NULL;
|
||||
json_t *guilds = NULL;
|
||||
@ -143,6 +143,13 @@ static void dc_session_handle_ready(dc_session_t s, dc_event_t e)
|
||||
dc_guild_t guild = dc_guild_from_json(c);
|
||||
continue_if_true(guild == NULL);
|
||||
dc_session_add_guild(s, guild);
|
||||
|
||||
/* add their channels to our own thing
|
||||
*/
|
||||
for (i = 0; i < dc_guild_channels(guild); i++) {
|
||||
dc_channel_t chan = dc_guild_nth_channel(guild, i);
|
||||
dc_session_add_channel(s, chan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ void ncdc_treeitem_set_label(ncdc_treeitem_t i, wchar_t const *s);
|
||||
|
||||
void *ncdc_treeitem_tag(ncdc_treeitem_t i);
|
||||
void ncdc_treeitem_set_tag(ncdc_treeitem_t i, void *t);
|
||||
ncdc_treeitem_t ncdc_treeitem_parent(ncdc_treeitem_t i);
|
||||
|
||||
size_t ncdc_treeitem_size(ncdc_treeitem_t i);
|
||||
void ncdc_treeitem_clear(ncdc_treeitem_t i);
|
||||
@ -27,6 +28,7 @@ typedef struct ncdc_treeview_ *ncdc_treeview_t;
|
||||
|
||||
ncdc_treeview_t ncdc_treeview_new(void);
|
||||
ncdc_treeitem_t ncdc_treeview_root(ncdc_treeview_t t);
|
||||
ncdc_treeitem_t ncdc_treeview_current(ncdc_treeview_t t);
|
||||
void ncdc_treeview_render(ncdc_treeview_t t, WINDOW *w, int lines, int cols);
|
||||
|
||||
/* move the cursor around, and collapse/expand items
|
||||
|
@ -20,7 +20,7 @@ ncdc_cmd_join(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ac == 2) {
|
||||
if (ac == 3) {
|
||||
guild = w_convert(av[1]);
|
||||
channel = w_convert(av[2]);
|
||||
|
||||
@ -35,7 +35,7 @@ ncdc_cmd_join(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f)
|
||||
LOG(n, L"join: no such channel %s in guild %s", channel, guild);
|
||||
goto cleanup;
|
||||
}
|
||||
} else if (ac == 1) {
|
||||
} else if (ac == 2) {
|
||||
id = w_convert(av[1]);
|
||||
|
||||
c = dc_session_channel_by_id(current_session, id);
|
||||
|
@ -126,11 +126,9 @@ ncdc_mainwindow_callback(ncdc_input_t i, wchar_t const *s,
|
||||
if (s[0] == '/') {
|
||||
ret = ncdc_dispatch(mainwin, s);
|
||||
} else {
|
||||
wchar_t *post = calloc(wcslen(s)+7, sizeof(wchar_t));
|
||||
|
||||
wcscat(post, L"/post ");
|
||||
wcscat(post, s);
|
||||
wchar_t *post = NULL;
|
||||
|
||||
aswprintf(&post, L"/post %ls", s);
|
||||
ret = ncdc_dispatch(mainwin, post);
|
||||
free(post);
|
||||
}
|
||||
@ -249,6 +247,34 @@ static void ncdc_mainwindow_render_status(ncdc_mainwindow_t n)
|
||||
free(status);
|
||||
}
|
||||
|
||||
static void ncdc_mainwindow_open_guildchat(ncdc_mainwindow_t n)
|
||||
{
|
||||
ncdc_treeitem_t cur = ncdc_treeview_current(n->guildview);
|
||||
dc_channel_t channel = NULL;
|
||||
wchar_t *cmd = NULL;
|
||||
|
||||
return_if_true(cur == NULL ||
|
||||
/* not the root, thanks
|
||||
*/
|
||||
cur == ncdc_treeview_root(n->guildview) ||
|
||||
/* not one root (again)
|
||||
*/
|
||||
ncdc_treeitem_parent(cur) == NULL ||
|
||||
/* not a guild who are the first level after root
|
||||
*/
|
||||
ncdc_treeitem_parent(cur) == ncdc_treeview_root(n->guildview),
|
||||
);
|
||||
|
||||
channel = ncdc_treeitem_tag(cur);
|
||||
return_if_true(channel == NULL,);
|
||||
|
||||
aswprintf(&cmd, L"/join %s", dc_channel_id(channel));
|
||||
return_if_true(cmd == NULL,);
|
||||
|
||||
ncdc_dispatch(n, cmd);
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
void ncdc_mainwindow_update_guilds(ncdc_mainwindow_t n)
|
||||
{
|
||||
GHashTableIter iter;
|
||||
@ -378,7 +404,7 @@ void ncdc_mainwindow_input_ready(ncdc_mainwindow_t n)
|
||||
{
|
||||
if (key != NULL &&
|
||||
(k = ncdc_find_keybinding(keys_chat, key, keylen)) != NULL) {
|
||||
k->handler(n->guildview);
|
||||
k->handler(n->chat);
|
||||
}
|
||||
} break;
|
||||
|
||||
@ -387,6 +413,8 @@ void ncdc_mainwindow_input_ready(ncdc_mainwindow_t n)
|
||||
if (key != NULL &&
|
||||
(k = ncdc_find_keybinding(keys_guilds, key, keylen)) != NULL) {
|
||||
k->handler(n->guildview);
|
||||
} else if (i == '\r') {
|
||||
ncdc_mainwindow_open_guildchat(n);
|
||||
}
|
||||
} break;
|
||||
|
||||
@ -472,6 +500,7 @@ 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);
|
||||
@ -486,6 +515,32 @@ 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);
|
||||
}
|
||||
|
@ -122,6 +122,12 @@ void ncdc_treeitem_set_tag(ncdc_treeitem_t i, void *t)
|
||||
i->tag = t;
|
||||
}
|
||||
|
||||
ncdc_treeitem_t ncdc_treeitem_parent(ncdc_treeitem_t i)
|
||||
{
|
||||
return_if_true(i == NULL, NULL);
|
||||
return i->parent;
|
||||
}
|
||||
|
||||
wchar_t const *ncdc_treeitem_label(ncdc_treeitem_t i)
|
||||
{
|
||||
return_if_true(i == NULL, NULL);
|
||||
@ -220,6 +226,12 @@ void ncdc_treeview_render(ncdc_treeview_t t, WINDOW *w, int lines, int cols)
|
||||
ncdc_treeitem_render(t->root, w, lines, cols, 0, 0);
|
||||
}
|
||||
|
||||
ncdc_treeitem_t ncdc_treeview_current(ncdc_treeview_t t)
|
||||
{
|
||||
return_if_true(t == NULL, NULL);
|
||||
return t->current;
|
||||
}
|
||||
|
||||
ncdc_treeitem_t ncdc_treeview_root(ncdc_treeview_t t)
|
||||
{
|
||||
return_if_true(t == NULL, NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user