mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 20:23:01 +01:00
add group silencing and improve group help menu
This commit is contained in:
parent
928134da7a
commit
9cd2158c72
@ -95,10 +95,12 @@ static struct cmd_func group_commands[] = {
|
||||
{ "/privacy", cmd_set_privacy },
|
||||
{ "/prune", cmd_prune },
|
||||
{ "/rejoin", cmd_rejoin },
|
||||
{ "/silence", cmd_silence },
|
||||
{ "/topic", cmd_set_topic },
|
||||
{ "/unban", cmd_unban },
|
||||
{ "/unignore", cmd_unignore },
|
||||
{ "/unmod", cmd_unmod },
|
||||
{ "/unsilence", cmd_unsilence },
|
||||
#ifdef AUDIO
|
||||
{ "/mute", cmd_mute },
|
||||
{ "/sense", cmd_sense },
|
||||
@ -106,8 +108,9 @@ static struct cmd_func group_commands[] = {
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
#define NUM_SPECIAL_COMMANDS 11
|
||||
#define NUM_SPECIAL_COMMANDS 14
|
||||
static const char special_commands[NUM_SPECIAL_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||
"/ban",
|
||||
"/gaccept",
|
||||
"/group",
|
||||
"/ignore",
|
||||
@ -116,9 +119,11 @@ static const char special_commands[NUM_SPECIAL_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||
"/nick",
|
||||
"/note",
|
||||
"/passwd",
|
||||
"/silence",
|
||||
"/topic",
|
||||
"/unignore",
|
||||
"/unmod",
|
||||
"/unsilence",
|
||||
};
|
||||
|
||||
/* return true if input command is in the special_commands array. False otherwise.*/
|
||||
|
@ -62,7 +62,7 @@ void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
|
||||
int peernum = group_get_nick_peernumber(self->num, nick);
|
||||
|
||||
if (peernum == -1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name");
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ static void cmd_kickban_helper(ToxWindow *self, Tox *m, const char *nick, bool s
|
||||
int peernumber = group_get_nick_peernumber(self->num, nick);
|
||||
|
||||
if (peernumber == -1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name");
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ void cmd_ban(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
||||
for (i = 0; i < num_banned; ++i) {
|
||||
struct tm tm_set = *localtime((const time_t *) &ban_list[i].time_set);
|
||||
char time_str[64];
|
||||
strftime(time_str, sizeof(time_str), "%c", &tm_set);
|
||||
strftime(time_str, sizeof(time_str), "%e %b %Y %H:%M:%S%p", &tm_set);
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "[ID: %d] %s : %s : %s", ban_list[i].id,
|
||||
ban_list[i].ip_address, ban_list[i].nick, time_str);
|
||||
}
|
||||
@ -194,7 +194,7 @@ void cmd_mod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
||||
int peernumber = group_get_nick_peernumber(self->num, nick);
|
||||
|
||||
if (peernumber == -1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name.");
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -243,7 +243,12 @@ void cmd_unmod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
|
||||
int peernumber = group_get_nick_peernumber(self->num, nick);
|
||||
|
||||
if (peernumber == -1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name.");
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
|
||||
return;
|
||||
}
|
||||
|
||||
if (tox_group_get_peer_role(m, self->num, peernumber) != TOX_GR_MODERATOR) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s is not a moderator", nick);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -387,6 +392,77 @@ void cmd_set_privacy(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_silence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
if (argc < 1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified.");
|
||||
return;
|
||||
}
|
||||
|
||||
const char *nick = argv[1];
|
||||
int peernumber = group_get_nick_peernumber(self->num, nick);
|
||||
|
||||
if (peernumber == -1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = tox_group_set_peer_role(m, self->num, peernumber, TOX_GR_OBSERVER);
|
||||
|
||||
switch (ret) {
|
||||
case 0: {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 1, BLUE, "You have silenced %s", nick);
|
||||
return;
|
||||
}
|
||||
case -2: {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to silence %s.", nick);
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to silence %s.", nick);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_unsilence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
if (argc < 1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified.");
|
||||
return;
|
||||
}
|
||||
|
||||
const char *nick = argv[1];
|
||||
int peernumber = group_get_nick_peernumber(self->num, nick);
|
||||
|
||||
if (peernumber == -1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
|
||||
return;
|
||||
}
|
||||
|
||||
if (tox_group_get_peer_role(m, self->num, peernumber) != TOX_GR_OBSERVER) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s is not silenced", nick);
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = tox_group_set_peer_role(m, self->num, peernumber, TOX_GR_USER);
|
||||
|
||||
switch (ret) {
|
||||
case 0: {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 1, BLUE, "You have unsilenced %s", nick);
|
||||
return;
|
||||
}
|
||||
case -2: {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to unsilence %s.", nick);
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to unsilence %s.", nick);
|
||||
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) {
|
||||
@ -447,7 +523,7 @@ void cmd_unignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
|
||||
int peernum = group_get_nick_peernumber(self->num, nick);
|
||||
|
||||
if (peernum == -1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer '%s' does not exist", nick);
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,8 @@ void cmd_set_peerlimit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (
|
||||
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_silence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_unsilence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_unban(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_unmod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
|
@ -70,9 +70,9 @@ extern struct user_settings *user_settings;
|
||||
extern struct Winthread Winthread;
|
||||
|
||||
#ifdef AUDIO
|
||||
#define AC_NUM_GROUP_COMMANDS 36
|
||||
#define AC_NUM_GROUP_COMMANDS 38
|
||||
#else
|
||||
#define AC_NUM_GROUP_COMMANDS 32
|
||||
#define AC_NUM_GROUP_COMMANDS 34
|
||||
#endif /* AUDIO */
|
||||
|
||||
/* groupchat command names used for tab completion. */
|
||||
@ -103,11 +103,13 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||
{ "/quit" },
|
||||
{ "/rejoin" },
|
||||
{ "/requests" },
|
||||
{ "/silence" },
|
||||
{ "/status" },
|
||||
{ "/topic" },
|
||||
{ "/unban" },
|
||||
{ "/unignore" },
|
||||
{ "/unmod" },
|
||||
{ "/unsilence" },
|
||||
{ "/whisper" },
|
||||
|
||||
#ifdef AUDIO
|
||||
@ -876,7 +878,7 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
|
||||
/* TODO: Make this not poll */
|
||||
pthread_mutex_lock(&Winthread.lock);
|
||||
uint8_t status = tox_group_get_status(m, self->num, i);
|
||||
TOX_GROUP_ROLE role = tox_group_get_role(m, self->num, i);
|
||||
TOX_GROUP_ROLE role = tox_group_get_peer_role(m, self->num, i);
|
||||
pthread_mutex_unlock(&Winthread.lock);
|
||||
|
||||
int maxlen_offset = role == TOX_GR_USER ? 2 : 3;
|
||||
@ -906,6 +908,9 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
|
||||
} else if (role == TOX_GR_MODERATOR) {
|
||||
rolesig = "+";
|
||||
rolecolour = GREEN;
|
||||
} else if (role == TOX_GR_OBSERVER) {
|
||||
rolesig = "-";
|
||||
rolecolour = MAGENTA;
|
||||
}
|
||||
|
||||
wattron(ctx->sidebar, COLOR_PAIR(rolecolour) | A_BOLD);
|
||||
|
24
src/help.c
24
src/help.c
@ -243,21 +243,31 @@ static void help_draw_group(ToxWindow *self)
|
||||
wprintw(win, "Group commands:\n");
|
||||
wattroff(win, A_BOLD | COLOR_PAIR(RED));
|
||||
|
||||
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, " /unignore <nick> : Unignore peer \n");
|
||||
wprintw(win, " /rejoin : Rejoin the group\n");
|
||||
wprintw(win, " /topic <msg> : Set group topic (show current topic if no msg)\n");
|
||||
wprintw(win, " /whisper <nick> <msg> : Send private message to nick\n");
|
||||
|
||||
wattron(win, A_BOLD);
|
||||
wprintw(win, " Moderator commands:\n");
|
||||
wattroff(win, A_BOLD);
|
||||
wprintw(win, " /kick <nick> : Kick peer\n");
|
||||
wprintw(win, " /ban <nick> : Ban peer (leave nick blank to see ban list)\n");
|
||||
wprintw(win, " /unban <Ban ID> : Unban entry\n");
|
||||
wprintw(win, " /silence <nick> : Silences peer for the entire group\n");
|
||||
wprintw(win, " /unsilence <nick> : Unsilences peer\n");
|
||||
|
||||
wattron(win, A_BOLD);
|
||||
wprintw(win, " Founder commands:\n");
|
||||
wattroff(win, A_BOLD);
|
||||
wprintw(win, " /mod <nick> : Promote peer to moderator\n");
|
||||
wprintw(win, " /unmod <nick> : Demote moderator to normal user\n");
|
||||
wprintw(win, " /passwd <password> : Set group password (leave blank to unset)\n");
|
||||
wprintw(win, " /peerlimit <num> : Set group peer limit\n");
|
||||
wprintw(win, " /privacy <state> : Set group privacy state: private|public\n");
|
||||
wprintw(win, " /rejoin : Rejoin the group\n");
|
||||
wprintw(win, " /topic <msg> : Set group topic (show current topic if no msg)\n");
|
||||
wprintw(win, " /whisper <nick> <msg> : Send private message to nick\n\n");
|
||||
|
||||
#ifdef AUDIO
|
||||
#endif /* AUDIO */
|
||||
help_draw_bottom_menu(win);
|
||||
|
||||
box(win, ACS_VLINE, ACS_HLINE);
|
||||
@ -313,7 +323,7 @@ void help_onKey(ToxWindow *self, wint_t key)
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
help_init_window(self, 17, 80);
|
||||
help_init_window(self, 23, 80);
|
||||
self->help->type = HELP_GROUP;
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user