allow joining by snowflake
This commit is contained in:
parent
d86a386edd
commit
f51e371f23
@ -76,6 +76,8 @@ 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);
|
||||
|
||||
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
|
||||
* these recipients already exists.
|
||||
|
@ -346,6 +346,12 @@ dc_account_t dc_session_account_fullname(dc_session_t s, char const *f)
|
||||
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)
|
||||
{
|
||||
return_if_true(s == NULL || u == NULL,);
|
||||
|
@ -6,11 +6,12 @@ ncdc_cmd_join(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f)
|
||||
{
|
||||
char *guild = NULL;
|
||||
char *channel = NULL;
|
||||
char *id = NULL;
|
||||
bool ret = true;
|
||||
dc_guild_t g = NULL;
|
||||
dc_channel_t c = NULL;
|
||||
|
||||
if (ac <= 2) {
|
||||
if (ac <= 1) {
|
||||
LOG(n, L"join: not enough arguments given");
|
||||
return false;
|
||||
}
|
||||
@ -19,6 +20,7 @@ ncdc_cmd_join(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ac == 2) {
|
||||
guild = w_convert(av[1]);
|
||||
channel = w_convert(av[2]);
|
||||
|
||||
@ -33,6 +35,15 @@ 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) {
|
||||
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) {
|
||||
bool ret = false;
|
||||
@ -42,7 +53,9 @@ ncdc_cmd_join(ncdc_mainwindow_t n, size_t ac, wchar_t **av, wchar_t const *f)
|
||||
c
|
||||
);
|
||||
if (!ret) {
|
||||
LOG(n, L"join: failed to fetch messages for channel %s", channel);
|
||||
LOG(n, L"join: failed to fetch messages for channel %s",
|
||||
dc_channel_name(c)
|
||||
);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
@ -57,6 +70,7 @@ cleanup:
|
||||
|
||||
free(guild);
|
||||
free(channel);
|
||||
free(id);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user