1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-25 07:23:02 +01:00

Add support for new voice state feature

This commit is contained in:
jfreegman 2022-02-05 14:11:25 -05:00
parent 1b9f4f337a
commit 4d501aeb2a
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
9 changed files with 138 additions and 5 deletions

View File

@ -139,6 +139,7 @@ static struct cmd_func groupchat_commands[] = {
{ "/unignore", cmd_unignore }, { "/unignore", cmd_unignore },
{ "/unmod", cmd_unmod }, { "/unmod", cmd_unmod },
{ "/unsilence", cmd_unsilence }, { "/unsilence", cmd_unsilence },
{ "/voice", cmd_set_voice },
{ "/whois", cmd_whois }, { "/whois", cmd_whois },
#ifdef AUDIO #ifdef AUDIO
{ "/mute", cmd_mute }, { "/mute", cmd_mute },

View File

@ -400,6 +400,78 @@ void cmd_set_peerlimit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (
} }
} }
void cmd_set_voice(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
Tox_Group_Voice_State voice_state;
if (argc < 1) {
Tox_Err_Group_State_Queries err;
voice_state = tox_group_get_voice_state(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 voice state (error %d).", err);
return;
}
switch (voice_state) {
case TOX_GROUP_VOICE_STATE_ALL: {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Voice state is set to ALL");
break;
}
case TOX_GROUP_VOICE_STATE_MODERATOR: {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Voice state is set to MODERATOR");
break;
}
case TOX_GROUP_VOICE_STATE_FOUNDER: {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Voice state is set to FOUNDER");
break;
}
default:
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Error: Unknown voice state: %d", voice_state);
return;
}
return;
}
const char *vstate_str = argv[1];
if (strcasecmp(vstate_str, "mod") == 0) {
voice_state = TOX_GROUP_VOICE_STATE_MODERATOR;
} else if (strcasecmp(vstate_str, "founder") == 0) {
voice_state = TOX_GROUP_VOICE_STATE_FOUNDER;
} else if (strcasecmp(vstate_str, "all") == 0) {
voice_state = TOX_GROUP_VOICE_STATE_ALL;
} else {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0,
"voice state must be \"all\", \"mod\", or \"founder\".");
return;
}
Tox_Err_Group_Founder_Set_Voice_State err;
tox_group_founder_set_voice_state(m, self->num, voice_state, &err);
switch (err) {
case TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_OK: {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Voice state has been set to %s.", vstate_str);
return;
}
case TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_PERMISSIONS: {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to set the voice state.");
return;
}
default: {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Error setting voice state (error %d).", err);
return;
}
}
}
void cmd_set_privacy(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])
{ {
const char *pstate_str = NULL; const char *pstate_str = NULL;

View File

@ -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_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_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_privacy(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_set_voice(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_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_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_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);

View File

@ -114,6 +114,7 @@ static const char *group_cmd_list[] = {
"/unignore", "/unignore",
"/unmod", "/unmod",
"/unsilence", "/unsilence",
"/voice",
"/whisper", "/whisper",
"/whois", "/whois",
#ifdef AUDIO #ifdef AUDIO
@ -841,6 +842,43 @@ static void groupchat_onGroupPrivacyState(ToxWindow *self, Tox *m, uint32_t grou
write_to_log(tmp_event, "The founder", ctx->log, true); write_to_log(tmp_event, "The founder", ctx->log, true);
} }
void groupchat_onGroupVoiceState(ToxWindow *self, Tox *m, uint32_t groupnumber, Tox_Group_Voice_State voice_state)
{
ChatContext *ctx = self->chatwin;
if (self->num != groupnumber || !get_groupchat(groupnumber)) {
return;
}
char tmp_event[MAX_STR_SIZE];
switch (voice_state) {
case TOX_GROUP_VOICE_STATE_ALL: {
line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE, "-!- Voice: Everyone may speak");
snprintf(tmp_event, sizeof(tmp_event), " set the voice state to ALL.");
break;
}
case TOX_GROUP_VOICE_STATE_MODERATOR: {
line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE,
"-!- Voice: Only moderators and the founder may speak");
snprintf(tmp_event, sizeof(tmp_event), " set the voice state to MODERATOR.");
break;
}
case TOX_GROUP_VOICE_STATE_FOUNDER: {
line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE, "-!- Voice: Only the founder may speak.");
snprintf(tmp_event, sizeof(tmp_event), " set the voice state to FOUNDER.");
break;
}
default:
return;
}
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) static void groupchat_onGroupTopicLock(ToxWindow *self, Tox *m, uint32_t groupnumber, Tox_Group_Topic_Lock topic_lock)
{ {
ChatContext *ctx = self->chatwin; ChatContext *ctx = self->chatwin;
@ -1336,7 +1374,13 @@ static void send_group_message(ToxWindow *self, Tox *m, uint32_t groupnumber, co
if (!tox_group_send_message(m, groupnumber, type, (uint8_t *) msg, strlen(msg), &err)) { if (!tox_group_send_message(m, groupnumber, type, (uint8_t *) msg, strlen(msg), &err)) {
if (err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS) { if (err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS) {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * You are silenced."); const Tox_Group_Role role = tox_group_self_get_role(m, groupnumber, NULL);
if (role == TOX_GROUP_ROLE_OBSERVER) {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * You are silenced.");
} else {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * You do not have voice.");
}
} else { } else {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send message (Error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send message (Error %d).", err);
} }
@ -1411,11 +1455,12 @@ static void send_group_prvt_message(ToxWindow *self, Tox *m, uint32_t groupnumbe
Tox_Err_Group_Send_Private_Message err; Tox_Err_Group_Send_Private_Message err;
if (!tox_group_send_private_message(m, groupnumber, peer_id, TOX_MESSAGE_TYPE_NORMAL, (uint8_t *) msg, msg_len, &err)) { if (!tox_group_send_private_message(m, groupnumber, peer_id, TOX_MESSAGE_TYPE_NORMAL,
(uint8_t *) msg, msg_len, &err)) {
if (err == TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_PERMISSIONS) { if (err == TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_PERMISSIONS) {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * You are silenced."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * You are silenced.");
} else { } else {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send private message."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send private message (%d)", err);
} }
return; return;
@ -1762,6 +1807,7 @@ static ToxWindow *new_group_chat(Tox *m, uint32_t groupnumber, const char *group
ret->onGroupSelfJoin = &groupchat_onGroupSelfJoin; ret->onGroupSelfJoin = &groupchat_onGroupSelfJoin;
ret->onGroupRejected = &groupchat_onGroupRejected; ret->onGroupRejected = &groupchat_onGroupRejected;
ret->onGroupModeration = &groupchat_onGroupModeration; ret->onGroupModeration = &groupchat_onGroupModeration;
ret->onGroupVoiceState = &groupchat_onGroupVoiceState;
ChatContext *chatwin = calloc(1, sizeof(ChatContext)); ChatContext *chatwin = calloc(1, sizeof(ChatContext));
Help *help = calloc(1, sizeof(Help)); Help *help = calloc(1, sizeof(Help));

View File

@ -307,13 +307,14 @@ static void help_draw_groupchats(ToxWindow *self)
wprintw(win, " /mod <name> : Promote a peer to moderator\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, " /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"); wprintw(win, " /peerlimit <n> : Set the maximum number of peers that can join\n");
wprintw(win, " /privacy <type> : Set the group privacy state: private | public\n"); wprintw(win, " /privacy <state> : Set the privacy state: private | public\n");
wprintw(win, " /rejoin : Reconnect to the groupchat\n"); wprintw(win, " /rejoin : Reconnect to the groupchat\n");
wprintw(win, " /silence <name> : Silence a peer for the entire group\n"); wprintw(win, " /silence <name> : Silence a peer for the entire group\n");
wprintw(win, " /unsilence <name> : Unsilence a silenced peer\n"); wprintw(win, " /unsilence <name> : Unsilence a silenced peer\n");
wprintw(win, " /status <type> : Set your status\n"); wprintw(win, " /status <type> : Set your status\n");
wprintw(win, " /topic <m> : Set the group topic\n"); wprintw(win, " /topic <m> : Set the group topic\n");
wprintw(win, " /unmod <name> : Demote a moderator\n"); wprintw(win, " /unmod <name> : Demote a moderator\n");
wprintw(win, " /voice <state> : Set the voice state: all | mod | founder\n");
wprintw(win, " /whisper <name> <m> : Send a private message to a peer\n"); wprintw(win, " /whisper <name> <m> : Send a private message to a peer\n");
wprintw(win, " /whois <name> : Print whois info for a peer\n"); wprintw(win, " /whois <name> : Print whois info for a peer\n");
@ -490,7 +491,7 @@ void help_onKey(ToxWindow *self, wint_t key)
break; break;
case L'r': case L'r':
help_init_window(self, 25, 80); help_init_window(self, 26, 80);
self->help->type = HELP_GROUP; self->help->type = HELP_GROUP;
break; break;
} }

View File

@ -842,6 +842,7 @@ static void init_tox_callbacks(Tox *m)
tox_callback_group_self_join(m, on_group_self_join); tox_callback_group_self_join(m, on_group_self_join);
tox_callback_group_join_fail(m, on_group_rejected); tox_callback_group_join_fail(m, on_group_rejected);
tox_callback_group_moderation(m, on_group_moderation); tox_callback_group_moderation(m, on_group_moderation);
tox_callback_group_voice_state(m, on_group_voice_state);
} }
static void init_tox_options(struct Tox_Options *tox_opts) static void init_tox_options(struct Tox_Options *tox_opts)

View File

@ -173,6 +173,7 @@ void on_group_self_join(Tox *m, uint32_t groupnumber, void *userdata);
void on_group_rejected(Tox *m, uint32_t groupnumber, Tox_Group_Join_Fail type, void *userdata); void on_group_rejected(Tox *m, uint32_t groupnumber, Tox_Group_Join_Fail type, void *userdata);
void on_group_moderation(Tox *m, uint32_t groupnumber, uint32_t source_peernum, uint32_t target_peernum, void on_group_moderation(Tox *m, uint32_t groupnumber, uint32_t source_peernum, uint32_t target_peernum,
Tox_Group_Mod_Event type, void *userdata); Tox_Group_Mod_Event type, void *userdata);
void on_group_voice_state(Tox *m, uint32_t groupnumber, Tox_Group_Voice_State voice_state, void *userdata);
extern char *DATA_FILE; extern char *DATA_FILE;
extern char *BLOCK_FILE; extern char *BLOCK_FILE;

View File

@ -555,6 +555,15 @@ void on_group_moderation(Tox *m, uint32_t groupnumber, uint32_t source_peer_id,
} }
} }
void on_group_voice_state(Tox *m, uint32_t groupnumber, Tox_Group_Voice_State voice_state, void *userdata)
{
for (size_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i] != NULL && windows[i]->onGroupVoiceState != NULL) {
windows[i]->onGroupVoiceState(windows[i], m, groupnumber, voice_state);
}
}
}
/* CALLBACKS END */ /* CALLBACKS END */
int add_window(Tox *m, ToxWindow *w) int add_window(Tox *m, ToxWindow *w)

View File

@ -209,6 +209,7 @@ struct ToxWindow {
void(*onGroupSelfJoin)(ToxWindow *, Tox *, uint32_t); void(*onGroupSelfJoin)(ToxWindow *, Tox *, uint32_t);
void(*onGroupRejected)(ToxWindow *, Tox *, uint32_t, Tox_Group_Join_Fail); void(*onGroupRejected)(ToxWindow *, Tox *, uint32_t, Tox_Group_Join_Fail);
void(*onGroupModeration)(ToxWindow *, Tox *, uint32_t, uint32_t, uint32_t, Tox_Group_Mod_Event); void(*onGroupModeration)(ToxWindow *, Tox *, uint32_t, uint32_t, uint32_t, Tox_Group_Mod_Event);
void(*onGroupVoiceState)(ToxWindow *, Tox *, uint32_t, Tox_Group_Voice_State);
#ifdef AUDIO #ifdef AUDIO