Compare commits

..

No commits in common. "08d1fcc15df840aa4da9a0d0861adb0f69dfd318" and "d86a386edd35764aa50e871add208cb8e5be93b7" have entirely different histories.

9 changed files with 31 additions and 128 deletions

View File

@ -76,8 +76,6 @@ dc_account_t dc_session_account_fullname(dc_session_t s, char const *f);
*/ */
void dc_session_add_channel(dc_session_t s, dc_channel_t u); void dc_session_add_channel(dc_session_t s, dc_channel_t u);
dc_channel_t dc_session_channel_by_id(dc_session_t s, char const *snowflake);
/** /**
* Creates a new channel, or returns an existing channel if a channel with * Creates a new channel, or returns an existing channel if a channel with
* these recipients already exists. * these recipients already exists.

View File

@ -83,7 +83,7 @@ static void dc_session_handle_ready(dc_session_t s, dc_event_t e)
json_t *user = NULL; json_t *user = NULL;
json_t *relationships = NULL; json_t *relationships = NULL;
json_t *presences = NULL; json_t *presences = NULL;
size_t idx = 0, i = 0; size_t idx = 0;
json_t *c = NULL; json_t *c = NULL;
json_t *channels = NULL; json_t *channels = NULL;
json_t *guilds = NULL; json_t *guilds = NULL;
@ -143,13 +143,6 @@ static void dc_session_handle_ready(dc_session_t s, dc_event_t e)
dc_guild_t guild = dc_guild_from_json(c); dc_guild_t guild = dc_guild_from_json(c);
continue_if_true(guild == NULL); continue_if_true(guild == NULL);
dc_session_add_guild(s, guild); 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);
}
} }
} }
@ -353,12 +346,6 @@ dc_account_t dc_session_account_fullname(dc_session_t s, char const *f)
return NULL; return NULL;
} }
dc_channel_t dc_session_channel_by_id(dc_session_t s, char const *snowflake)
{
return_if_true(s == NULL || snowflake == NULL, NULL);
return (dc_channel_t)g_hash_table_lookup(s->channels, snowflake);
}
void dc_session_add_channel(dc_session_t s, dc_channel_t u) void dc_session_add_channel(dc_session_t s, dc_channel_t u)
{ {
return_if_true(s == NULL || u == NULL,); return_if_true(s == NULL || u == NULL,);

View File

@ -16,7 +16,6 @@ void ncdc_treeitem_set_label(ncdc_treeitem_t i, wchar_t const *s);
void *ncdc_treeitem_tag(ncdc_treeitem_t i); void *ncdc_treeitem_tag(ncdc_treeitem_t i);
void ncdc_treeitem_set_tag(ncdc_treeitem_t i, void *t); 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); size_t ncdc_treeitem_size(ncdc_treeitem_t i);
void ncdc_treeitem_clear(ncdc_treeitem_t i); void ncdc_treeitem_clear(ncdc_treeitem_t i);
@ -28,7 +27,6 @@ typedef struct ncdc_treeview_ *ncdc_treeview_t;
ncdc_treeview_t ncdc_treeview_new(void); ncdc_treeview_t ncdc_treeview_new(void);
ncdc_treeitem_t ncdc_treeview_root(ncdc_treeview_t t); 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); void ncdc_treeview_render(ncdc_treeview_t t, WINDOW *w, int lines, int cols);
/* move the cursor around, and collapse/expand items /* move the cursor around, and collapse/expand items

View File

@ -136,11 +136,9 @@ bool ncdc_dispatch(ncdc_mainwindow_t n, wchar_t const *s)
*/ */
len = wcslen(s); len = wcslen(s);
cmdlen = wcslen(it->name); cmdlen = wcslen(it->name);
f = wcsdup(s); f = wcsdup(s);
return_if_true(f == NULL, false); return_if_true(f == NULL, false);
memmove(f, f+cmdlen, (len-cmdlen) * sizeof(wchar_t)); memmove(f, f+cmdlen, len-cmdlen);
f[len-cmdlen] = '\0';
item = calloc(1, sizeof(queue_item)); item = calloc(1, sizeof(queue_item));

View File

@ -6,12 +6,11 @@ ncdc_cmd_join(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f)
{ {
char *guild = NULL; char *guild = NULL;
char *channel = NULL; char *channel = NULL;
char *id = NULL;
bool ret = true; bool ret = true;
dc_guild_t g = NULL; dc_guild_t g = NULL;
dc_channel_t c = NULL; dc_channel_t c = NULL;
if (ac <= 1) { if (ac <= 2) {
LOG(n, L"join: not enough arguments given"); LOG(n, L"join: not enough arguments given");
return false; return false;
} }
@ -20,29 +19,19 @@ ncdc_cmd_join(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f)
return false; return false;
} }
if (ac == 3) { guild = w_convert(av[1]);
guild = w_convert(av[1]); channel = w_convert(av[2]);
channel = w_convert(av[2]);
g = dc_session_guild_by_name(current_session, guild); g = dc_session_guild_by_name(current_session, guild);
if (g == NULL) { if (g == NULL) {
LOG(n, L"join: no such guild: %s", guild); LOG(n, L"join: no such guild: %s", guild);
goto cleanup; goto cleanup;
} }
c = dc_guild_channel_by_name(g, channel); c = dc_guild_channel_by_name(g, channel);
if (c == NULL) { if (c == NULL) {
LOG(n, L"join: no such channel %s in guild %s", channel, guild); LOG(n, L"join: no such channel %s in guild %s", channel, guild);
goto cleanup; goto cleanup;
}
} else if (ac == 2) {
id = w_convert(av[1]);
c = dc_session_channel_by_id(current_session, id);
if (c == NULL) {
LOG(n, L"join: no channel found with that snowflake: %s", id);
goto cleanup;
}
} }
if (dc_channel_messages(c) == 0) { if (dc_channel_messages(c) == 0) {
@ -53,9 +42,7 @@ ncdc_cmd_join(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f)
c c
); );
if (!ret) { if (!ret) {
LOG(n, L"join: failed to fetch messages for channel %s", LOG(n, L"join: failed to fetch messages for channel %s", channel);
dc_channel_name(c)
);
goto cleanup; goto cleanup;
} }
} }
@ -70,7 +57,6 @@ cleanup:
free(guild); free(guild);
free(channel); free(channel);
free(id);
return ret; return ret;
} }

View File

@ -40,16 +40,19 @@ ncdc_keybinding_t keys_guilds[] = {
}; };
ncdc_keybinding_t keys_chat[] = { ncdc_keybinding_t keys_chat[] = {
/* ALT+KEY_RIGHT
*/
NCDC_BINDING(L"\x1B[1;3C", L"right-window", ncdc_mainwindow_rightview),
NCDC_BINDING(L"\x1B0C", L"right-window", ncdc_mainwindow_rightview),
/* ALT+KEY_LEFT
*/
NCDC_BINDING(L"\x1B[1;3D", L"left-window", ncdc_mainwindow_leftview),
NCDC_BINDING(L"\x1B0D", L"left-window", ncdc_mainwindow_leftview),
NCDC_BINDEND() NCDC_BINDEND()
}; };
ncdc_keybinding_t keys_global[] = { ncdc_keybinding_t keys_global[] = {
/* ALT+KEY_RIGHT
*/
NCDC_BINDING(L"\x1B[1;3C", L"right-window", ncdc_mainwindow_rightview),
/* ALT+KEY_LEFT
*/
NCDC_BINDING(L"\x1B[1;3D", L"left-window", ncdc_mainwindow_leftview),
/* F1 /* F1
*/ */
NCDC_BINDING(L"\x1BOP", L"select-input", ncdc_mainwindow_switch_input), NCDC_BINDING(L"\x1BOP", L"select-input", ncdc_mainwindow_switch_input),

View File

@ -126,9 +126,11 @@ ncdc_mainwindow_callback(ncdc_input_t i, wchar_t const *s,
if (s[0] == '/') { if (s[0] == '/') {
ret = ncdc_dispatch(mainwin, s); ret = ncdc_dispatch(mainwin, s);
} else { } else {
wchar_t *post = NULL; wchar_t *post = calloc(wcslen(s)+7, sizeof(wchar_t));
wcscat(post, L"/post ");
wcscat(post, s);
aswprintf(&post, L"/post %ls", s);
ret = ncdc_dispatch(mainwin, post); ret = ncdc_dispatch(mainwin, post);
free(post); free(post);
} }
@ -247,34 +249,6 @@ static void ncdc_mainwindow_render_status(ncdc_mainwindow_t n)
free(status); 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) void ncdc_mainwindow_update_guilds(ncdc_mainwindow_t n)
{ {
GHashTableIter iter; GHashTableIter iter;
@ -404,7 +378,7 @@ void ncdc_mainwindow_input_ready(ncdc_mainwindow_t n)
{ {
if (key != NULL && if (key != NULL &&
(k = ncdc_find_keybinding(keys_chat, key, keylen)) != NULL) { (k = ncdc_find_keybinding(keys_chat, key, keylen)) != NULL) {
k->handler(n->chat); k->handler(n->guildview);
} }
} break; } break;
@ -413,8 +387,6 @@ void ncdc_mainwindow_input_ready(ncdc_mainwindow_t n)
if (key != NULL && if (key != NULL &&
(k = ncdc_find_keybinding(keys_guilds, key, keylen)) != NULL) { (k = ncdc_find_keybinding(keys_guilds, key, keylen)) != NULL) {
k->handler(n->guildview); k->handler(n->guildview);
} else if (i == '\r') {
ncdc_mainwindow_open_guildchat(n);
} }
} break; } break;
@ -500,7 +472,6 @@ ncdc_textview_t
ncdc_mainwindow_switch_or_add(ncdc_mainwindow_t n, dc_channel_t c) ncdc_mainwindow_switch_or_add(ncdc_mainwindow_t n, dc_channel_t c)
{ {
ncdc_textview_t v = NULL; ncdc_textview_t v = NULL;
wchar_t *name = NULL;
return_if_true(n == NULL || c == NULL, NULL); return_if_true(n == NULL || c == NULL, NULL);
return_if_true(!is_logged_in(), NULL); return_if_true(!is_logged_in(), NULL);
@ -515,32 +486,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_account(v, dc_session_me(current_session));
ncdc_textview_set_channel(v, c); 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); g_ptr_array_add(n->views, v);
ncdc_mainwindow_switch_view(n, v); ncdc_mainwindow_switch_view(n, v);
} }

View File

@ -122,12 +122,6 @@ void ncdc_treeitem_set_tag(ncdc_treeitem_t i, void *t)
i->tag = 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) wchar_t const *ncdc_treeitem_label(ncdc_treeitem_t i)
{ {
return_if_true(i == NULL, NULL); return_if_true(i == NULL, NULL);
@ -226,12 +220,6 @@ 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_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) ncdc_treeitem_t ncdc_treeview_root(ncdc_treeview_t t)
{ {
return_if_true(t == NULL, NULL); return_if_true(t == NULL, NULL);

View File

@ -20,8 +20,8 @@ wchar_t *util_readkey(int e)
switch (esc[1]) { switch (esc[1]) {
/* here it depends on the next character we read /* here it depends on the next character we read
*/ */
case L'[': len = 4; break; case L'[': len = 3; break;
/* O codes move the cursor, and have one additional byte after /* O codes move the cursor, and have one additional bit set
*/ */
case L'O': len = 1; break; case L'O': len = 1; break;
default: len = 5; default: len = 5;