diff --git a/src/execute.c b/src/execute.c index 4b5245c..c34ee18 100644 --- a/src/execute.c +++ b/src/execute.c @@ -127,6 +127,7 @@ static struct cmd_func groupchat_commands[] = { { "/disconnect",cmd_disconnect }, { "/ignore", cmd_ignore }, { "/kick", cmd_kick }, + { "/list", cmd_list }, { "/mod", cmd_mod }, { "/passwd", cmd_set_passwd }, { "/peerlimit", cmd_set_peerlimit }, diff --git a/src/groupchat_commands.c b/src/groupchat_commands.c index acd2d43..6a76811 100644 --- a/src/groupchat_commands.c +++ b/src/groupchat_commands.c @@ -162,6 +162,34 @@ void cmd_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA } } +void cmd_list(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) +{ + GroupChat *chat = get_groupchat(self->num); + + if (!chat) { + line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch GroupChat object."); + return; + } + + for (size_t i = 0; i < chat->max_idx; ++i) { + GroupPeer *peer = &chat->peer_list[i]; + + if (!peer->active) { + continue; + } + + char pk_string[TOX_GROUP_PEER_PUBLIC_KEY_SIZE * 2 + 1] = {0}; + + for (size_t j = 0; j < TOX_GROUP_PEER_PUBLIC_KEY_SIZE; ++j) { + char d[3]; + snprintf(d, sizeof(d), "%02X", peer->public_key[j] & 0xff); + strcat(pk_string, d); + } + + line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "%s : %s", pk_string, peer->name); + } +} + void cmd_mod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { if (argc < 1) { @@ -689,15 +717,13 @@ void cmd_whois(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M get_unix_time() - chat->peer_list[peer_index].last_active); char pk_string[TOX_GROUP_PEER_PUBLIC_KEY_SIZE * 2 + 1] = {0}; - size_t i; - for (i = 0; i < TOX_GROUP_PEER_PUBLIC_KEY_SIZE; ++i) { + for (size_t i = 0; i < TOX_GROUP_PEER_PUBLIC_KEY_SIZE; ++i) { char d[3]; snprintf(d, sizeof(d), "%02X", chat->peer_list[peer_index].public_key[i] & 0xff); strcat(pk_string, d); } - TOX_ERR_GROUP_PEER_QUERY conn_err; Tox_Connection connection_type = tox_group_peer_get_connection_status(m, self->num, peer_id, &conn_err); diff --git a/src/groupchat_commands.h b/src/groupchat_commands.h index fd97dbd..4199838 100644 --- a/src/groupchat_commands.h +++ b/src/groupchat_commands.h @@ -30,6 +30,7 @@ void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[ void cmd_disconnect(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_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); +void cmd_list(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_mod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_prune(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]); diff --git a/src/groupchats.c b/src/groupchats.c index ec6b3d1..e03ba0e 100644 --- a/src/groupchats.c +++ b/src/groupchats.c @@ -88,6 +88,7 @@ static const char *group_cmd_list[] = { "/ignore", "/join", "/kick", + "/list", "/log", "/mod", "/myid", diff --git a/src/help.c b/src/help.c index 4b5887c..f4b8843 100644 --- a/src/help.c +++ b/src/help.c @@ -302,6 +302,7 @@ static void help_draw_groupchats(ToxWindow *self) wprintw(win, " /ignore : Ignore a peer\n"); wprintw(win, " /unignore : Unignore an ignored peer\n"); wprintw(win, " /kick : Remove a peer from the group\n"); + wprintw(win, " /list : Print a list of peers currently in the group\n"); wprintw(win, " /mod : Promote a peer to moderator\n"); wprintw(win, " /passwd : Set a password needed to join the group\n"); wprintw(win, " /peerlimit : Set the maximum number of peers that can join\n"); @@ -488,7 +489,7 @@ void help_onKey(ToxWindow *self, wint_t key) break; case L'r': - help_init_window(self, 23, 80); + help_init_window(self, 24, 80); self->help->type = HELP_GROUP; break; }