mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 09:13:24 +01:00
Add topic lock command and callbacks
This commit is contained in:
parent
1d8aafba3b
commit
e9f8293a0a
@ -128,6 +128,7 @@ static struct cmd_func groupchat_commands[] = {
|
||||
{ "/ignore", cmd_ignore },
|
||||
{ "/kick", cmd_kick },
|
||||
{ "/list", cmd_list },
|
||||
{ "/locktopic", cmd_set_topic_lock },
|
||||
{ "/mod", cmd_mod },
|
||||
{ "/passwd", cmd_set_passwd },
|
||||
{ "/peerlimit", cmd_set_peerlimit },
|
||||
|
@ -444,6 +444,56 @@ void cmd_set_privacy(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_set_topic_lock(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
TOX_GROUP_TOPIC_LOCK topic_lock;
|
||||
const char *tlock_str = NULL;
|
||||
|
||||
if (argc < 1) {
|
||||
TOX_ERR_GROUP_STATE_QUERIES err;
|
||||
topic_lock = tox_group_get_topic_lock(m, self->num, &err);
|
||||
|
||||
if (err != TOX_ERR_GROUP_STATE_QUERIES_OK) {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve topic lock (error %d).", err);
|
||||
return;
|
||||
}
|
||||
|
||||
tlock_str = topic_lock == TOX_GROUP_TOPIC_LOCK_ENABLED ? "Enabled" : "Disabled";
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Topic lock is %s.", tlock_str);
|
||||
return;
|
||||
}
|
||||
|
||||
tlock_str = argv[1];
|
||||
|
||||
if (strcasecmp(tlock_str, "on") != 0 && strcasecmp(tlock_str, "off") != 0) {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Topic lock must be \"on\" or \"off\".");
|
||||
return;
|
||||
}
|
||||
|
||||
topic_lock = strcasecmp(tlock_str, "on") == 0 ? TOX_GROUP_TOPIC_LOCK_ENABLED : TOX_GROUP_TOPIC_LOCK_DISABLED;
|
||||
const char *display_str = (topic_lock == TOX_GROUP_TOPIC_LOCK_ENABLED) ? "enabled" : "disabled";
|
||||
|
||||
TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK err;
|
||||
tox_group_founder_set_topic_lock(m, self->num, topic_lock, &err);
|
||||
|
||||
switch (err) {
|
||||
case TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK: {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Topic lock has been %s.", display_str);
|
||||
return;
|
||||
}
|
||||
|
||||
case TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_PERMISSIONS: {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to set the topic lock.");
|
||||
return;
|
||||
}
|
||||
|
||||
default: {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Error setting topic lock (error %d).", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_silence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
if (argc < 1) {
|
||||
|
@ -36,6 +36,7 @@ void cmd_prune(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
|
||||
void cmd_set_passwd(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_set_peerlimit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_set_privacy(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_set_topic_lock(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_rejoin(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_silence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
|
@ -89,6 +89,7 @@ static const char *group_cmd_list[] = {
|
||||
"/join",
|
||||
"/kick",
|
||||
"/list",
|
||||
"/locktopic",
|
||||
"/log",
|
||||
"/mod",
|
||||
"/myid",
|
||||
@ -790,6 +791,23 @@ static void groupchat_onGroupPrivacyState(ToxWindow *self, Tox *m, uint32_t grou
|
||||
write_to_log(tmp_event, "The founder", ctx->log, true);
|
||||
}
|
||||
|
||||
static void groupchat_onGroupTopicLock(ToxWindow *self, Tox *m, uint32_t groupnumber, TOX_GROUP_TOPIC_LOCK topic_lock)
|
||||
{
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
if (self->num != groupnumber || !get_groupchat(groupnumber)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char *tlock_str = topic_lock == TOX_GROUP_TOPIC_LOCK_ENABLED ? "locked" : "unlocked";
|
||||
|
||||
line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE, "-!- The group founder has %s the topic.", tlock_str);
|
||||
|
||||
char tmp_event[MAX_STR_SIZE];
|
||||
snprintf(tmp_event, sizeof(tmp_event), " %s the topic.", tlock_str);
|
||||
write_to_log(tmp_event, "The founder", ctx->log, true);
|
||||
}
|
||||
|
||||
static void groupchat_onGroupPassword(ToxWindow *self, Tox *m, uint32_t groupnumber, const char *password,
|
||||
size_t length)
|
||||
{
|
||||
@ -1662,6 +1680,7 @@ static ToxWindow *new_group_chat(Tox *m, uint32_t groupnumber, const char *group
|
||||
ret->onGroupTopicChange = &groupchat_onGroupTopicChange;
|
||||
ret->onGroupPeerLimit = &groupchat_onGroupPeerLimit;
|
||||
ret->onGroupPrivacyState = &groupchat_onGroupPrivacyState;
|
||||
ret->onGroupTopicLock = &groupchat_onGroupTopicLock;
|
||||
ret->onGroupPassword = &groupchat_onGroupPassword;
|
||||
ret->onGroupNickChange = &groupchat_onGroupNickChange;
|
||||
ret->onGroupStatusChange = &groupchat_onGroupStatusChange;
|
||||
|
@ -303,6 +303,7 @@ static void help_draw_groupchats(ToxWindow *self)
|
||||
wprintw(win, " /unignore <name> : Unignore an ignored peer\n");
|
||||
wprintw(win, " /kick <name> : Remove a peer from the group\n");
|
||||
wprintw(win, " /list : Print a list of peers currently in the group\n");
|
||||
wprintw(win, " /locktopic : Set the topic lock: on | off\n");
|
||||
wprintw(win, " /mod <name> : Promote a peer to moderator\n");
|
||||
wprintw(win, " /passwd <s> : Set a password needed to join the group\n");
|
||||
wprintw(win, " /peerlimit <n> : Set the maximum number of peers that can join\n");
|
||||
@ -489,7 +490,7 @@ void help_onKey(ToxWindow *self, wint_t key)
|
||||
break;
|
||||
|
||||
case L'r':
|
||||
help_init_window(self, 24, 80);
|
||||
help_init_window(self, 25, 80);
|
||||
self->help->type = HELP_GROUP;
|
||||
break;
|
||||
}
|
||||
|
@ -837,6 +837,7 @@ static void init_tox_callbacks(Tox *m)
|
||||
tox_callback_group_topic(m, on_group_topic_change);
|
||||
tox_callback_group_peer_limit(m, on_group_peer_limit);
|
||||
tox_callback_group_privacy_state(m, on_group_privacy_state);
|
||||
tox_callback_group_topic_lock(m, on_group_topic_lock);
|
||||
tox_callback_group_password(m, on_group_password);
|
||||
tox_callback_group_self_join(m, on_group_self_join);
|
||||
tox_callback_group_join_fail(m, on_group_rejected);
|
||||
|
@ -164,6 +164,7 @@ void on_group_topic_change(Tox *m, uint32_t groupnumber, uint32_t peernumber, co
|
||||
void *userdata);
|
||||
void on_group_peer_limit(Tox *m, uint32_t groupnumber, uint32_t peer_limit, void *userdata);
|
||||
void on_group_privacy_state(Tox *m, uint32_t groupnumber, TOX_GROUP_PRIVACY_STATE privacy_state, void *userdata);
|
||||
void on_group_topic_lock(Tox *m, uint32_t groupnumber, TOX_GROUP_TOPIC_LOCK topic_lock, void *userdata);
|
||||
void on_group_password(Tox *m, uint32_t groupnumber, const uint8_t *password, size_t length, void *userdata);
|
||||
void on_group_nick_change(Tox *m, uint32_t groupnumber, uint32_t peernumber, const uint8_t *newname, size_t length,
|
||||
void *userdata);
|
||||
|
@ -491,6 +491,15 @@ void on_group_privacy_state(Tox *m, uint32_t groupnumber, TOX_GROUP_PRIVACY_STAT
|
||||
}
|
||||
}
|
||||
|
||||
void on_group_topic_lock(Tox *m, uint32_t groupnumber, TOX_GROUP_TOPIC_LOCK topic_lock, void *userdata)
|
||||
{
|
||||
for (size_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i] != NULL && windows[i]->onGroupTopicLock != NULL) {
|
||||
windows[i]->onGroupTopicLock(windows[i], m, groupnumber, topic_lock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void on_group_password(Tox *m, uint32_t groupnumber, const uint8_t *password, size_t length, void *userdata)
|
||||
{
|
||||
for (size_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
|
@ -204,6 +204,7 @@ struct ToxWindow {
|
||||
void(*onGroupTopicChange)(ToxWindow *, Tox *, uint32_t, uint32_t, const char *, size_t);
|
||||
void(*onGroupPeerLimit)(ToxWindow *, Tox *, uint32_t, uint32_t);
|
||||
void(*onGroupPrivacyState)(ToxWindow *, Tox *, uint32_t, TOX_GROUP_PRIVACY_STATE);
|
||||
void(*onGroupTopicLock)(ToxWindow *, Tox *, uint32_t, TOX_GROUP_TOPIC_LOCK);
|
||||
void(*onGroupPassword)(ToxWindow *, Tox *, uint32_t, const char *, size_t);
|
||||
void(*onGroupSelfJoin)(ToxWindow *, Tox *, uint32_t);
|
||||
void(*onGroupRejected)(ToxWindow *, Tox *, uint32_t, TOX_GROUP_JOIN_FAIL);
|
||||
|
Loading…
Reference in New Issue
Block a user