diff --git a/src/execute.c b/src/execute.c index 3afa2863a..a0202f364 100644 --- a/src/execute.c +++ b/src/execute.c @@ -145,6 +145,7 @@ static const char special_commands[][MAX_CMDNAME_SIZE] = { "/nick", "/note", "/passwd", + "/rejoin", "/silence", "/topic", "/unignore", diff --git a/src/global_commands.c b/src/global_commands.c index 072bd4d5f..8a039e60f 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -566,8 +566,8 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char self_nick[nick_length] = '\0'; Tox_Err_Group_New err; - uint32_t groupnumber = tox_group_new(tox, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *) name, len, - (const uint8_t *) self_nick, nick_length, &err); + const uint32_t groupnumber = tox_group_new(tox, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *) name, len, + (const uint8_t *) self_nick, nick_length, &err); if (err != TOX_ERR_GROUP_NEW_OK) { switch (err) { diff --git a/src/groupchat_commands.c b/src/groupchat_commands.c index aa1ed4e78..ed15ee184 100644 --- a/src/groupchat_commands.c +++ b/src/groupchat_commands.c @@ -867,12 +867,42 @@ void cmd_rejoin(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (* return; } + Tox *tox = toxic->tox; const Client_Config *c_config = toxic->c_config; - Tox_Err_Group_Reconnect err; + char chat_id[TOX_GROUP_CHAT_ID_SIZE]; + Tox_Err_Group_State_Query chatid_err; + + if (!tox_group_get_chat_id(tox, self->num, (uint8_t *) chat_id, &chatid_err)) { + line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, + "Failed to retrieve the Chat ID (error %d).", chatid_err); + return; + } + + char nick[TOX_MAX_NAME_LENGTH + 1]; + const size_t nick_length = get_group_self_nick_truncate(tox, nick, self->num); + + const char *password = NULL; + uint16_t password_length = 0; + + if (argc == 1) { + password_length = (uint16_t) strlen(argv[1]); + + if (password_length <= TOX_GROUP_MAX_PASSWORD_SIZE) { + password = argv[1]; + } else { + line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "Password length cannot exceed %d.", + TOX_GROUP_MAX_PASSWORD_SIZE); + password_length = 0; + } + } + + Tox_Err_Group_Join join_err; + tox_group_join(tox, (uint8_t *) chat_id, (const uint8_t *) nick, nick_length, (const uint8_t *) password, + (uint16_t) password_length, &join_err); - if (!tox_group_reconnect(toxic->tox, self->num, &err)) { - line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to rejoin group (error %d).", err); + if (join_err != TOX_ERR_GROUP_JOIN_OK) { + line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to rejoin group (error %d).", join_err); return; } diff --git a/src/help.c b/src/help.c index cd63c1a2a..170ba5717 100644 --- a/src/help.c +++ b/src/help.c @@ -296,10 +296,10 @@ static void help_draw_groupchats(ToxWindow *self) wprintw(win, " /locktopic : Set the topic lock: on | off\n"); wprintw(win, " /mod | : Promote a peer to moderator\n"); wprintw(win, " /nick : Set your name (for this group only)\n"); - wprintw(win, " /passwd : Set a password to join the group\n"); + wprintw(win, " /passwd : Set a password to join the group\n"); wprintw(win, " /peerlimit : Set the maximum number of peers that can join\n"); wprintw(win, " /privacy : Set the privacy state: private | public\n"); - wprintw(win, " /rejoin : Reconnect to the group\n"); + wprintw(win, " /rejoin : Reconnect to the group (password is optional)\n"); wprintw(win, " /silence | : Silence a peer for the entire group\n"); wprintw(win, " /unsilence | : Unsilence a silenced peer\n"); wprintw(win, " /status : Set your status (client-wide)\n");