diff --git a/src/execute.c b/src/execute.c index d53767b..0596904 100644 --- a/src/execute.c +++ b/src/execute.c @@ -82,9 +82,10 @@ static struct cmd_func chat_commands[] = { }; static struct cmd_func group_commands[] = { - { "/topic", cmd_set_topic }, { "/chatid", cmd_chatid }, { "/ignore", cmd_ignore }, + { "/rejoin", cmd_rejoin }, + { "/topic", cmd_set_topic }, { "/unignore", cmd_unignore }, #ifdef AUDIO { "/mute", cmd_mute }, diff --git a/src/group_commands.c b/src/group_commands.c index f2892d6..ad43176 100644 --- a/src/group_commands.c +++ b/src/group_commands.c @@ -29,48 +29,15 @@ #include "log.h" #include "groupchat.h" -void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) -{ - if (argc < 1) { - char cur_topic[MAX_STR_SIZE]; - int tlen = tox_group_get_topic(m, self->num, (uint8_t *) cur_topic); - - if (tlen > 0) { - cur_topic[tlen] = '\0'; - line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Topic is set to: %s", cur_topic); - } else { - line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Topic is not set"); - } - - return; - } - - const char *topic = argv[1]; - - if (tox_group_set_topic(m, self->num, (uint8_t *) topic, strlen(topic)) != 0) { - line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set topic."); - return; - } - - char timefrmt[TIME_STR_SIZE]; - char selfnick[TOX_MAX_NAME_LENGTH]; - - get_time_str(timefrmt, sizeof(timefrmt)); - int sn_len = tox_group_get_self_name(m, self->num, (uint8_t *) selfnick); - selfnick[sn_len] = '\0'; - - line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, MAGENTA, "-!- You set the topic to: %s", topic); - - char tmp_event[MAX_STR_SIZE]; - snprintf(tmp_event, sizeof(tmp_event), "set topic to %s", topic); - write_to_log(tmp_event, selfnick, self->chatwin->log, true); -} - void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { char chatid[TOX_GROUP_CHAT_ID_SIZE * 2 + 1] = {0}; char chat_public_key[TOX_GROUP_CHAT_ID_SIZE]; - tox_group_get_chat_id(m, self->num, (uint8_t *) chat_public_key); + + if (tox_group_get_chat_id(m, self->num, (uint8_t *) chat_public_key) == -1) { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error retreiving chat id."); + return; + } size_t i; @@ -109,6 +76,51 @@ void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[ line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- Ignoring %s", nick); } +void cmd_rejoin(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) +{ + if (tox_group_reconnect(m, self->num) == -1) + return; + + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Reconnecting to group..."); +} + +void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) +{ + if (argc < 1) { + char cur_topic[MAX_STR_SIZE]; + int tlen = tox_group_get_topic(m, self->num, (uint8_t *) cur_topic); + + if (tlen > 0) { + cur_topic[tlen] = '\0'; + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Topic is set to: %s", cur_topic); + } else { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Topic is not set"); + } + + return; + } + + const char *topic = argv[1]; + + if (tox_group_set_topic(m, self->num, (uint8_t *) topic, strlen(topic)) != 0) { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set topic."); + return; + } + + char timefrmt[TIME_STR_SIZE]; + char selfnick[TOX_MAX_NAME_LENGTH]; + + get_time_str(timefrmt, sizeof(timefrmt)); + int sn_len = tox_group_get_self_name(m, self->num, (uint8_t *) selfnick); + selfnick[sn_len] = '\0'; + + line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, MAGENTA, "-!- You set the topic to: %s", topic); + + char tmp_event[MAX_STR_SIZE]; + snprintf(tmp_event, sizeof(tmp_event), "set topic to %s", topic); + write_to_log(tmp_event, selfnick, self->chatwin->log, true); +} + void cmd_unignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { if (argc < 1) { diff --git a/src/group_commands.h b/src/group_commands.h index dc41f40..a9dc6c7 100644 --- a/src/group_commands.h +++ b/src/group_commands.h @@ -26,9 +26,10 @@ #include "windows.h" #include "toxic.h" -void cmd_set_topic(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_unignore(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_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]); #endif /* GROUP_COMMANDS_H */ diff --git a/src/groupchat.c b/src/groupchat.c index 4c0b886..1e782a9 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 26 +#define AC_NUM_GROUP_COMMANDS 27 #else -#define AC_NUM_GROUP_COMMANDS 22 +#define AC_NUM_GROUP_COMMANDS 23 #endif /* AUDIO */ /* groupchat command names used for tab completion. */ @@ -89,16 +89,17 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = { { "/group" }, { "/help" }, { "/ignore" }, - { "/unignore" }, { "/join" }, { "/log" }, { "/myid" }, { "/nick" }, { "/note" }, { "/quit" }, + { "/rejoin" }, { "/requests" }, { "/status" }, { "/topic" }, + { "/unignore" }, #ifdef AUDIO @@ -546,16 +547,16 @@ static void groupchat_onGroupRejected(ToxWindow *self, Tox *m, int groupnum, uin switch (type) { case TOX_GJ_NICK_TAKEN: - msg = "That nick is already in use. Please change your nick with the '/nick' command."; + msg = "Nick already in use. Change your nick and use the 'rejoin' command."; break; case TOX_GJ_GROUP_FULL: - msg = "Group is full."; + msg = "Group is full. Try again with the 'rejoin' command."; break; case TOX_GJ_INVITES_DISABLED: msg = "Invites for this group have been disabled."; break; case TOX_GJ_INVITE_FAILED: - msg = "Invite failed."; + msg = "Invite failed. Try again with the 'rejoin' command."; break; default: return; diff --git a/src/help.c b/src/help.c index e05028e..f817c5e 100644 --- a/src/help.c +++ b/src/help.c @@ -242,9 +242,10 @@ static void help_draw_group(ToxWindow *self) wprintw(win, "Group commands:\n"); wattroff(win, A_BOLD | COLOR_PAIR(RED)); - wprintw(win, " /topic : Set group topic (show current topic if no msg)\n"); wprintw(win, " /chatid : Print the group chat id to share with others.\n"); wprintw(win, " /ignore : Ignore peer\n"); + wprintw(win, " /rejoin : Rejoin the group (only works if not connected)\n"); + wprintw(win, " /topic : Set group topic (show current topic if no msg)\n"); wprintw(win, " /unignore : Unignore peer \n\n"); #ifdef AUDIO @@ -312,9 +313,9 @@ void help_onKey(ToxWindow *self, wint_t key) case 'r': #ifdef AUDIO - help_init_window(self, 13, 80); + help_init_window(self, 14, 80); #else - help_init_window(self, 9, 80); + help_init_window(self, 10, 80); #endif self->help->type = HELP_GROUP; break;