diff --git a/src/execute.c b/src/execute.c index cd100b8..927e5f4 100644 --- a/src/execute.c +++ b/src/execute.c @@ -88,6 +88,7 @@ static struct cmd_func group_commands[] = { { "/chatid", cmd_chatid }, { "/ignore", cmd_ignore }, { "/passwd", cmd_set_passwd }, + { "/privacy", cmd_set_privacy }, { "/rejoin", cmd_rejoin }, { "/topic", cmd_set_topic }, { "/unignore", cmd_unignore }, diff --git a/src/group_commands.c b/src/group_commands.c index d72f97f..734a823 100644 --- a/src/group_commands.c +++ b/src/group_commands.c @@ -112,6 +112,51 @@ void cmd_set_passwd(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar } } +void cmd_set_privacy(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) +{ + const char *pstate_str = NULL; + TOX_GROUP_PRIVACY_STATE privacy_state; + + if (argc < 1) { + privacy_state = tox_group_get_privacy_state(m, self->num); + + if (privacy_state == TOX_GP_INVALID) { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve privacy state"); + return; + } + + pstate_str = privacy_state == TOX_GP_PRIVATE ? "private" : "public"; + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Privacy state is set to %s.", pstate_str); + return; + } + + pstate_str = argv[1]; + + if (strcasecmp(pstate_str, "private") != 0 && strcasecmp(pstate_str, "public") != 0) { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Privacy state must be \"private\" or \"public\"."); + return; + } + + privacy_state = strcasecmp(pstate_str, "private") == 0 ? TOX_GP_PRIVATE : TOX_GP_PUBLIC; + + int ret = tox_group_set_privacy_state(m, self->num, privacy_state); + + switch (ret) { + case 0: { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Privacy state has been set to %s.", pstate_str); + return; + } + case -2: { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to set the privacy state."); + return; + } + default: { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error setting privacy state."); + return; + } + } +} + void cmd_rejoin(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { if (tox_group_reconnect(m, self->num) == -1) diff --git a/src/group_commands.h b/src/group_commands.h index b1addf0..8d83043 100644 --- a/src/group_commands.h +++ b/src/group_commands.h @@ -29,6 +29,7 @@ void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_ignore(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_privacy(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_unignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); diff --git a/src/groupchat.c b/src/groupchat.c index 43d3be9..d966f4a 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -70,9 +70,9 @@ extern struct user_settings *user_settings; extern struct Winthread Winthread; #ifdef AUDIO -#define AC_NUM_GROUP_COMMANDS 29 +#define AC_NUM_GROUP_COMMANDS 30 #else -#define AC_NUM_GROUP_COMMANDS 25 +#define AC_NUM_GROUP_COMMANDS 26 #endif /* AUDIO */ /* groupchat command names used for tab completion. */ @@ -94,10 +94,11 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = { { "/myid" }, { "/nick" }, { "/note" }, + { "/passwd" }, + { "/privacy" }, { "/quit" }, { "/rejoin" }, { "/requests" }, - { "/passwd" }, { "/status" }, { "/topic" }, { "/unignore" }, diff --git a/src/help.c b/src/help.c index e656379..973c05a 100644 --- a/src/help.c +++ b/src/help.c @@ -246,6 +246,7 @@ static void help_draw_group(ToxWindow *self) wprintw(win, " /chatid : Print the group chat id to share with others.\n"); wprintw(win, " /ignore : Ignore peer\n"); wprintw(win, " /passwd : Set group password (leave blank to unset)\n"); + wprintw(win, " /privacy : Set group privacy state: private|public\n"); wprintw(win, " /rejoin : Rejoin the group\n"); wprintw(win, " /topic : Set group topic (show current topic if no msg)\n"); wprintw(win, " /unignore : Unignore peer \n"); @@ -308,7 +309,7 @@ void help_onKey(ToxWindow *self, wint_t key) break; case 'r': - help_init_window(self, 12, 80); + help_init_window(self, 13, 80); self->help->type = HELP_GROUP; break;