1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 18:43:26 +01:00

add ability for founder to set group privacy state

This commit is contained in:
Jfreegman 2015-05-22 21:41:32 -04:00
parent 0481f43746
commit 29d0384a90
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
5 changed files with 53 additions and 4 deletions

View File

@ -88,6 +88,7 @@ static struct cmd_func group_commands[] = {
{ "/chatid", cmd_chatid }, { "/chatid", cmd_chatid },
{ "/ignore", cmd_ignore }, { "/ignore", cmd_ignore },
{ "/passwd", cmd_set_passwd }, { "/passwd", cmd_set_passwd },
{ "/privacy", cmd_set_privacy },
{ "/rejoin", cmd_rejoin }, { "/rejoin", cmd_rejoin },
{ "/topic", cmd_set_topic }, { "/topic", cmd_set_topic },
{ "/unignore", cmd_unignore }, { "/unignore", cmd_unignore },

View File

@ -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]) void cmd_rejoin(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (tox_group_reconnect(m, self->num) == -1) if (tox_group_reconnect(m, self->num) == -1)

View File

@ -29,6 +29,7 @@
void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); 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_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_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_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]);
void cmd_unignore(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]);

View File

@ -70,9 +70,9 @@ extern struct user_settings *user_settings;
extern struct Winthread Winthread; extern struct Winthread Winthread;
#ifdef AUDIO #ifdef AUDIO
#define AC_NUM_GROUP_COMMANDS 29 #define AC_NUM_GROUP_COMMANDS 30
#else #else
#define AC_NUM_GROUP_COMMANDS 25 #define AC_NUM_GROUP_COMMANDS 26
#endif /* AUDIO */ #endif /* AUDIO */
/* groupchat command names used for tab completion. */ /* 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" }, { "/myid" },
{ "/nick" }, { "/nick" },
{ "/note" }, { "/note" },
{ "/passwd" },
{ "/privacy" },
{ "/quit" }, { "/quit" },
{ "/rejoin" }, { "/rejoin" },
{ "/requests" }, { "/requests" },
{ "/passwd" },
{ "/status" }, { "/status" },
{ "/topic" }, { "/topic" },
{ "/unignore" }, { "/unignore" },

View File

@ -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, " /chatid : Print the group chat id to share with others.\n");
wprintw(win, " /ignore <nick> : Ignore peer\n"); wprintw(win, " /ignore <nick> : Ignore peer\n");
wprintw(win, " /passwd <password> : Set group password (leave blank to unset)\n"); wprintw(win, " /passwd <password> : Set group password (leave blank to unset)\n");
wprintw(win, " /privacy <state> : Set group privacy state: private|public\n");
wprintw(win, " /rejoin : Rejoin the group\n"); wprintw(win, " /rejoin : Rejoin the group\n");
wprintw(win, " /topic <msg> : Set group topic (show current topic if no msg)\n"); wprintw(win, " /topic <msg> : Set group topic (show current topic if no msg)\n");
wprintw(win, " /unignore <nick> : Unignore peer \n"); wprintw(win, " /unignore <nick> : Unignore peer \n");
@ -308,7 +309,7 @@ void help_onKey(ToxWindow *self, wint_t key)
break; break;
case 'r': case 'r':
help_init_window(self, 12, 80); help_init_window(self, 13, 80);
self->help->type = HELP_GROUP; self->help->type = HELP_GROUP;
break; break;