From 8526d4d77e4bfd0f6161ac9c98f901b5638bfd8e Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Tue, 1 Sep 2015 02:29:25 -0400 Subject: [PATCH] Refactor group peerlist to match API refactor Peerlists are now similar to the friendlist, which makes managing them much easier, and improves efficiency --- src/group_commands.c | 46 ++--- src/groupchat.c | 423 +++++++++++++++++++++++++++---------------- src/groupchat.h | 11 +- src/misc_tools.c | 6 +- src/misc_tools.h | 2 +- src/toxic.c | 2 +- src/toxic.h | 1 - src/windows.c | 42 ++--- src/windows.h | 1 - 9 files changed, 316 insertions(+), 218 deletions(-) diff --git a/src/group_commands.c b/src/group_commands.c index 0740ee8..fe96eea 100644 --- a/src/group_commands.c +++ b/src/group_commands.c @@ -60,15 +60,15 @@ void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[ } const char *nick = argv[1]; - int peernum = group_get_nick_peernumber(self->num, nick); + uint32_t peer_id; - if (peernum == -1) { + if (group_get_nick_peer_id(self->num, nick, &peer_id) == -1) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); return; } TOX_ERR_GROUP_TOGGLE_IGNORE err; - if (!tox_group_toggle_ignore(m, self->num, peernum, true, &err)) { + if (!tox_group_toggle_ignore(m, self->num, peer_id, true, &err)) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to ignore %s (error %d).", nick, err); return; } @@ -81,9 +81,9 @@ void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[ static void cmd_kickban_helper(ToxWindow *self, Tox *m, const char *nick, bool set_ban) { - int peernumber = group_get_nick_peernumber(self->num, nick); + uint32_t peer_id; - if (peernumber == -1) { + if (group_get_nick_peer_id(self->num, nick, &peer_id) == -1) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); return; } @@ -91,7 +91,7 @@ static void cmd_kickban_helper(ToxWindow *self, Tox *m, const char *nick, bool s const char *type_str = set_ban ? "ban" : "kick"; TOX_ERR_GROUP_MOD_REMOVE_PEER err; - tox_group_mod_remove_peer(m, self->num, (uint32_t) peernumber, set_ban, &err); + tox_group_mod_remove_peer(m, self->num, peer_id, set_ban, &err); switch (err) { case TOX_ERR_GROUP_MOD_REMOVE_PEER_OK: { @@ -227,15 +227,15 @@ void cmd_mod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX } const char *nick = argv[1]; - int peernumber = group_get_nick_peernumber(self->num, nick); + uint32_t peer_id; - if (peernumber == -1) { + if (group_get_nick_peer_id(self->num, nick, &peer_id) == -1) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); return; } TOX_ERR_GROUP_MOD_SET_ROLE err; - tox_group_mod_set_role(m, self->num, peernumber, TOX_GROUP_ROLE_MODERATOR, &err); + tox_group_mod_set_role(m, self->num, peer_id, TOX_GROUP_ROLE_MODERATOR, &err); switch (err) { case TOX_ERR_GROUP_MOD_SET_ROLE_OK: { @@ -264,20 +264,20 @@ void cmd_unmod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M } const char *nick = argv[1]; - int peernumber = group_get_nick_peernumber(self->num, nick); + uint32_t peer_id; - if (peernumber == -1) { + if (group_get_nick_peer_id(self->num, nick, &peer_id) == -1) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); return; } - if (tox_group_peer_get_role(m, self->num, peernumber, NULL) != TOX_GROUP_ROLE_MODERATOR) { + if (tox_group_peer_get_role(m, self->num, peer_id, NULL) != TOX_GROUP_ROLE_MODERATOR) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s is not a moderator", nick); return; } TOX_ERR_GROUP_MOD_SET_ROLE err; - tox_group_mod_set_role(m, self->num, peernumber, TOX_GROUP_ROLE_USER, &err); + tox_group_mod_set_role(m, self->num, peer_id, TOX_GROUP_ROLE_USER, &err); switch (err) { case TOX_ERR_GROUP_MOD_SET_ROLE_OK: { @@ -428,15 +428,15 @@ void cmd_silence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv) } const char *nick = argv[1]; - int peernumber = group_get_nick_peernumber(self->num, nick); + uint32_t peer_id; - if (peernumber == -1) { + if (group_get_nick_peer_id(self->num, nick, &peer_id) == -1) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); return; } TOX_ERR_GROUP_MOD_SET_ROLE err; - tox_group_mod_set_role(m, self->num, peernumber, TOX_GROUP_ROLE_OBSERVER, &err); + tox_group_mod_set_role(m, self->num, peer_id, TOX_GROUP_ROLE_OBSERVER, &err); switch (err) { case TOX_ERR_GROUP_MOD_SET_ROLE_OK: { @@ -461,20 +461,20 @@ void cmd_unsilence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg } const char *nick = argv[1]; - int peernumber = group_get_nick_peernumber(self->num, nick); + uint32_t peer_id; - if (peernumber == -1) { + if (group_get_nick_peer_id(self->num, nick, &peer_id) == -1) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); return; } - if (tox_group_peer_get_role(m, self->num, peernumber, NULL) != TOX_GROUP_ROLE_OBSERVER) { + if (tox_group_peer_get_role(m, self->num, peer_id, NULL) != TOX_GROUP_ROLE_OBSERVER) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s is not silenced.", nick); return; } TOX_ERR_GROUP_MOD_SET_ROLE err; - tox_group_mod_set_role(m, self->num, peernumber, TOX_GROUP_ROLE_USER, &err); + tox_group_mod_set_role(m, self->num, peer_id, TOX_GROUP_ROLE_USER, &err); switch (err) { case TOX_ERR_GROUP_MOD_SET_ROLE_OK: { @@ -583,15 +583,15 @@ void cmd_unignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv } const char *nick = argv[1]; - int peernum = group_get_nick_peernumber(self->num, nick); + uint32_t peer_id; - if (peernum == -1) { + if (group_get_nick_peer_id(self->num, nick, &peer_id) == -1) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); return; } TOX_ERR_GROUP_TOGGLE_IGNORE err; - if (!tox_group_toggle_ignore(m, self->num, peernum, false, &err)) { + if (!tox_group_toggle_ignore(m, self->num, peer_id, false, &err)) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to unignore %s (error %d).", nick, err); return; } diff --git a/src/groupchat.c b/src/groupchat.c index 490081a..1b29b18 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -122,42 +122,13 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = { #endif /* AUDIO */ }; -static void groupchat_set_group_name(ToxWindow *self, Tox *m, uint32_t groupnum); + ToxWindow new_group_chat(Tox *m, uint32_t groupnum, const char *groupname, int length); -static void groupchat_onGroupPeerlistUpdate(ToxWindow *self, Tox *m, uint32_t groupnum); +static void groupchat_set_group_name(ToxWindow *self, Tox *m, uint32_t groupnum); +static void group_update_name_list(uint32_t groupnum); +static void groupchat_onGroupPeerJoin(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peer_id); +static int realloc_peer_list(uint32_t groupnum, uint32_t n); -int init_groupchat_win(Tox *m, uint32_t groupnum, const char *groupname, size_t length) -{ - if (groupnum > MAX_GROUPCHAT_NUM) - return -1; - - ToxWindow self = new_group_chat(m, groupnum, groupname, length); - - /* In case we're loading a saved group */ - if (length == 0) - groupchat_set_group_name(&self, m, groupnum); - - int i; - - for (i = 0; i <= max_groupchat_index; ++i) { - if (!groupchats[i].active) { - groupchats[i].chatwin = add_window(m, self); - groupchats[i].active = true; - groupchats[i].groupnumber = groupnum; - - if (i == max_groupchat_index) - ++max_groupchat_index; - - set_active_window(groupchats[i].chatwin); - groupchat_onGroupPeerlistUpdate(&self, m, groupnum); - store_data(m, DATA_FILE); - - return 0; - } - } - - return -1; -} static void kill_groupchat_window(ToxWindow *self) { @@ -179,8 +150,7 @@ void close_groupchat(ToxWindow *self, Tox *m, uint32_t groupnum) { GroupChat *chat = &groupchats[groupnum]; - if (chat->peer_list) - free(chat->peer_list); + realloc_peer_list(groupnum, 0); if (chat->name_list) free(chat->name_list); @@ -207,6 +177,50 @@ static void exit_groupchat(ToxWindow *self, Tox *m, uint32_t groupnum, const cha close_groupchat(self, m, groupnum); } +int init_groupchat_win(Tox *m, uint32_t groupnum, const char *groupname, size_t length) +{ + if (groupnum > MAX_GROUPCHAT_NUM) + return -1; + + ToxWindow self = new_group_chat(m, groupnum, groupname, length); + + /* In case we're loading a saved group */ + if (length == 0) + groupchat_set_group_name(&self, m, groupnum); + + int i; + + for (i = 0; i <= max_groupchat_index; ++i) { + if (!groupchats[i].active) { + groupchats[i].chatwin = add_window(m, self); + groupchats[i].active = true; + groupchats[i].groupnumber = groupnum; + groupchats[i].num_peers = 0; + groupchats[i].time_connected = 0; + + if (i == max_groupchat_index) + ++max_groupchat_index; + + set_active_window(groupchats[i].chatwin); + store_data(m, DATA_FILE); + + TOX_ERR_GROUP_SELF_QUERY err; + uint32_t peer_id = tox_group_self_get_peer_id(m, groupnum, &err); + + if (err != TOX_ERR_GROUP_SELF_QUERY_OK) { + close_groupchat(&self, m, groupnum); + return -1; + } + + groupchat_onGroupPeerJoin(&self, m, groupnum, peer_id); + + return 0; + } + } + + return -1; +} + /* Note: the arguments to these functions are validated in the caller functions */ void set_nick_all_groups(Tox *m, const char *nick, size_t length) { @@ -231,7 +245,7 @@ void set_nick_all_groups(Tox *m, const char *nick, size_t length) break; } default: { - if (groupchats[i].is_connected) + if (groupchats[i].time_connected > 0) line_info_add(self, NULL, NULL, 0, SYS_MSG, 0, RED, "-!- Failed to set nick (error %d).", err); break; @@ -251,12 +265,44 @@ void set_status_all_groups(Tox *m, uint8_t status) } } -int group_get_nick_peernumber(uint32_t groupnum, const char *nick) +/* Gets the peer_id associated with nick. + * Returns -1 on failure or if nick is not assigned to anyone in the group. + */ +int group_get_nick_peer_id(uint32_t groupnum, const char *nick, uint32_t *peer_id) { + GroupChat *chat = &groupchats[groupnum]; + + if (!chat) + return -1; + uint32_t i; - for (i = 0; i < groupchats[groupnum].num_peers; ++i) { - if (strcmp(nick, groupchats[groupnum].peer_list[i].name) == 0) + for (i = 0; i < chat->max_idx; ++i) { + if (chat->peer_list[i].active) { + if (strcmp(nick, groupchats[groupnum].peer_list[i].name) == 0) { + *peer_id = groupchats[groupnum].peer_list[i].peer_id; + return 0; + } + } + } + + return -1; +} + +/* Returns the peerlist index of peer_id for groupnum's group chat. + * Returns -1 on failure. + */ +static int get_peer_index(uint32_t groupnum, uint32_t peer_id) +{ + GroupChat *chat = &groupchats[groupnum]; + + if (!chat) + return -1; + + uint32_t i; + + for (i = 0; i < chat->max_idx; ++i) { + if (chat->peer_list[i].active && chat->peer_list[i].peer_id == peer_id) return i; } @@ -267,6 +313,9 @@ static void group_update_name_list(uint32_t groupnum) { GroupChat *chat = &groupchats[groupnum]; + if (!chat) + return; + if (chat->name_list) free(chat->name_list); @@ -275,10 +324,14 @@ static void group_update_name_list(uint32_t groupnum) if (chat->name_list == NULL) exit_toxic_err("failed in group_update_name_list", FATALERR_MEMORY); - uint32_t i; + uint32_t i, count = 0; - for (i = 0; i < chat->num_peers; ++i) - memcpy(&chat->name_list[i * TOX_MAX_NAME_LENGTH], chat->peer_list[i].name, chat->peer_list[i].name_length + 1); + for (i = 0; i < chat->max_idx; ++i) { + if (chat->peer_list[i].active) { + memcpy(&chat->name_list[count * TOX_MAX_NAME_LENGTH], chat->peer_list[i].name, chat->peer_list[i].name_length + 1); + ++count; + } + } } /* destroys and re-creates groupchat window */ @@ -317,13 +370,13 @@ void redraw_groupchat_win(ToxWindow *self) } -static void group_onAction(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peernum, const char *action, +static void group_onAction(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peer_id, const char *action, size_t len) { ChatContext *ctx = self->chatwin; char nick[TOX_MAX_NAME_LENGTH]; - get_group_nick_truncate(m, nick, peernum, groupnum); + get_group_nick_truncate(m, nick, peer_id, groupnum); char selfnick[TOX_MAX_NAME_LENGTH]; tox_self_get_name(m, (uint8_t *) selfnick); @@ -349,21 +402,21 @@ static void group_onAction(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t write_to_log(action, nick, ctx->log, true); } -static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peernum, +static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peer_id, TOX_MESSAGE_TYPE type, const char *msg, size_t len) { if (self->num != groupnum) return; if (type == TOX_MESSAGE_TYPE_ACTION) { - group_onAction(self, m, groupnum, peernum, msg, len); + group_onAction(self, m, groupnum, peer_id, msg, len); return; } ChatContext *ctx = self->chatwin; char nick[TOX_MAX_NAME_LENGTH]; - get_group_nick_truncate(m, nick, peernum, groupnum); + get_group_nick_truncate(m, nick, peer_id, groupnum); char selfnick[TOX_MAX_NAME_LENGTH]; tox_self_get_name(m, (uint8_t *) selfnick); @@ -394,7 +447,7 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, uint32_t groupnum, write_to_log(msg, nick, ctx->log, false); } -static void groupchat_onGroupPrivateMessage(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peernum, +static void groupchat_onGroupPrivateMessage(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peer_id, const char *msg, size_t len) { if (self->num != groupnum) @@ -403,7 +456,7 @@ static void groupchat_onGroupPrivateMessage(ToxWindow *self, Tox *m, uint32_t gr ChatContext *ctx = self->chatwin; char nick[TOX_MAX_NAME_LENGTH]; - get_group_nick_truncate(m, nick, peernum, groupnum); + get_group_nick_truncate(m, nick, peer_id, groupnum); char timefrmt[TIME_STR_SIZE]; get_time_str(timefrmt, sizeof(timefrmt)); @@ -419,7 +472,7 @@ static void groupchat_onGroupPrivateMessage(ToxWindow *self, Tox *m, uint32_t gr box_silent_notify(self, NT_NOFOCUS, &self->active_box, self->name, "%s %s", nick, msg); } -static void groupchat_onGroupTopicChange(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peernum, +static void groupchat_onGroupTopicChange(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peer_id, const char *topic, size_t length) { ChatContext *ctx = self->chatwin; @@ -431,7 +484,7 @@ static void groupchat_onGroupTopicChange(ToxWindow *self, Tox *m, uint32_t group get_time_str(timefrmt, sizeof(timefrmt)); char nick[TOX_MAX_NAME_LENGTH]; - get_group_nick_truncate(m, nick, peernum, groupnum); + get_group_nick_truncate(m, nick, peer_id, groupnum); line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, MAGENTA, "-!- %s set the topic to: %s", nick, topic); char tmp_event[MAX_STR_SIZE]; @@ -501,90 +554,99 @@ static void groupchat_onGroupPassword(ToxWindow *self, Tox *m, uint32_t groupnum } } -/* TODO: This function could probably be cleaned up and optimized */ -static void groupchat_onGroupPeerlistUpdate(ToxWindow *self, Tox *m, uint32_t groupnum) +/* Reallocates groupnum's peer list to size n. + * + * Returns 0 on success. + * Returns -1 on failure. + */ +static int realloc_peer_list(uint32_t groupnum, uint32_t n) { - if (self->num != groupnum) - return; - - TOX_ERR_GROUP_STATE_QUERIES err; - uint32_t num_peers = tox_group_get_number_peers(m, groupnum, &err); - - if (num_peers == 0 || err != TOX_ERR_GROUP_STATE_QUERIES_OK) - return; - GroupChat *chat = &groupchats[groupnum]; - chat->num_peers = num_peers; - if (chat->peer_list) + if (!chat) + return -1; + + if (n == 0) { free(chat->peer_list); - - chat->peer_list = malloc(sizeof(struct GroupPeer) * num_peers); - - if (chat->peer_list == NULL) - exit_toxic_err("failed in groupchat_onGroupPeerlistUpdate", FATALERR_MEMORY); - - uint32_t i; - - for (i = 0; i < num_peers; ++i) { - memset(&chat->peer_list[i], 0, sizeof(struct GroupPeer)); - - TOX_ERR_GROUP_PEER_QUERY err; - size_t name_length = tox_group_peer_get_name_size(m, groupnum, i, &err); - - if (err != TOX_ERR_GROUP_PEER_QUERY_OK) - name_length = 0; - else - name_length = MIN(name_length, TOX_MAX_NAME_LENGTH - 1); - - if (!tox_group_peer_get_name(m, groupnum, i, (uint8_t *) chat->peer_list[i].name, NULL)) { - name_length = strlen(UNKNOWN_NAME); - memcpy(chat->peer_list[i].name, UNKNOWN_NAME, name_length); - } - - chat->peer_list[i].name[name_length] = '\0'; - chat->peer_list[i].name_length = name_length; - chat->peer_list[i].status = tox_group_peer_get_status(m, groupnum, i, NULL); - chat->peer_list[i].role = tox_group_peer_get_role(m, groupnum, i, NULL); + chat->peer_list = NULL; + return 0; } - group_update_name_list(groupnum); + struct GroupPeer *tmp_list = realloc(chat->peer_list, n * sizeof(struct GroupPeer)); + + if (!tmp_list) + return -1; + + chat->peer_list = tmp_list; + + return 0; } -static void groupchat_onGroupPeerJoin(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peernum) +static void groupchat_onGroupPeerJoin(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peer_id) { if (groupnum != self->num) return; - if (peernum > groupchats[groupnum].num_peers) + GroupChat *chat = &groupchats[groupnum]; + + if (!chat) return; - char name[TOX_MAX_NAME_LENGTH]; - get_group_nick_truncate(m, name, peernum, groupnum); + if (realloc_peer_list(groupnum, chat->max_idx + 1) == -1) + return; - char timefrmt[TIME_STR_SIZE]; - get_time_str(timefrmt, sizeof(timefrmt)); + memset(&chat->peer_list[chat->max_idx], 0, sizeof(struct GroupPeer)); - line_info_add(self, timefrmt, name, NULL, CONNECTION, 0, GREEN, "has joined the room."); + uint32_t i; - char log_str[TOXIC_MAX_NAME_LENGTH + 32]; - snprintf(log_str, sizeof(log_str), "%s has joined the room", name); + for (i = 0; i <= chat->max_idx; ++i) { + if (chat->peer_list[i].active) + continue; - write_to_log(log_str, name, self->chatwin->log, true); - sound_notify(self, silent, NT_WNDALERT_2, NULL); + ++chat->num_peers; + + chat->peer_list[i].active = true; + chat->peer_list[i].peer_id = peer_id; + get_group_nick_truncate(m, chat->peer_list[i].name, peer_id, groupnum); + chat->peer_list[i].name_length = strlen(chat->peer_list[i].name); + chat->peer_list[i].status = tox_group_peer_get_status(m, groupnum, peer_id, NULL); + chat->peer_list[i].role = tox_group_peer_get_role(m, groupnum, peer_id, NULL); + + if (i == chat->max_idx) + ++chat->max_idx; + + if (timed_out(chat->time_connected, 7)) { /* ignore join messages when we first connect to the group */ + char timefrmt[TIME_STR_SIZE]; + get_time_str(timefrmt, sizeof(timefrmt)); + + line_info_add(self, timefrmt, chat->peer_list[i].name, NULL, CONNECTION, 0, GREEN, "has joined the room."); + + char log_str[TOXIC_MAX_NAME_LENGTH + 32]; + snprintf(log_str, sizeof(log_str), "%s has joined the room", chat->peer_list[i].name); + + write_to_log(log_str, chat->peer_list[i].name, self->chatwin->log, true); + sound_notify(self, silent, NT_WNDALERT_2, NULL); + } + + group_update_name_list(groupnum); + + return; + } } -static void groupchat_onGroupPeerExit(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peernum, +static void groupchat_onGroupPeerExit(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peer_id, const char *partmessage, size_t len) { if (groupnum != self->num) return; - if (peernum > groupchats[groupnum].num_peers) + GroupChat *chat = &groupchats[groupnum]; + + if (!chat) return; char name[TOX_MAX_NAME_LENGTH]; - get_group_nick_truncate(m, name, peernum, groupnum); + get_group_nick_truncate(m, name, peer_id, groupnum); char timefrmt[TIME_STR_SIZE]; get_time_str(timefrmt, sizeof(timefrmt)); @@ -596,6 +658,28 @@ static void groupchat_onGroupPeerExit(ToxWindow *self, Tox *m, uint32_t groupnum write_to_log(log_str, name, self->chatwin->log, true); sound_notify(self, silent, NT_WNDALERT_2, NULL); + + int peer_index = get_peer_index(groupnum, peer_id); + + if (peer_index < 0) + return; + + memset(&chat->peer_list[peer_index], 0, sizeof(struct GroupPeer)); + + uint32_t i; + + for (i = chat->max_idx; i > 0; --i) { + if (chat->peer_list[i - 1].active) + break; + } + + if (realloc_peer_list(groupnum, i) == -1) + return; + + --chat->num_peers; + chat->max_idx = i; + + group_update_name_list(groupnum); } static void groupchat_set_group_name(ToxWindow *self, Tox *m, uint32_t groupnum) @@ -633,7 +717,7 @@ static void groupchat_onGroupSelfJoin(ToxWindow *self, Tox *m, uint32_t groupnum for (i = 0; i < max_groupchat_index; ++i) { if (groupchats[i].active && groupchats[i].groupnumber == groupnum) { - groupchats[i].is_connected = true; + groupchats[i].time_connected = get_unix_time(); break; } } @@ -687,8 +771,8 @@ static void groupchat_onGroupRejected(ToxWindow *self, Tox *m, uint32_t groupnum line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 0, RED, "-!- %s", msg); } -static void groupchat_onGroupModeration(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t src_peernum, - uint32_t tgt_peernum, TOX_GROUP_MOD_EVENT type) +static void groupchat_onGroupModeration(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t src_peer_id, + uint32_t tgt_peer_id, TOX_GROUP_MOD_EVENT type) { if (groupnum != self->num) return; @@ -698,10 +782,15 @@ static void groupchat_onGroupModeration(ToxWindow *self, Tox *m, uint32_t groupn char src_name[TOX_MAX_NAME_LENGTH]; char tgt_name[TOX_MAX_NAME_LENGTH]; - if (get_group_nick_truncate(m, src_name, src_peernum, groupnum) == -1) + if (get_group_nick_truncate(m, src_name, src_peer_id, groupnum) == -1) return; - if (get_group_nick_truncate(m, tgt_name, tgt_peernum, groupnum) == -1) + if (get_group_nick_truncate(m, tgt_name, tgt_peer_id, groupnum) == -1) + return; + + int tgt_index = get_peer_index(groupnum, tgt_peer_id); + + if (tgt_index < 0) return; char timefrmt[TIME_STR_SIZE]; @@ -715,15 +804,15 @@ static void groupchat_onGroupModeration(ToxWindow *self, Tox *m, uint32_t groupn line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, RED, "-!- %s has been banned by %s", tgt_name, src_name); break; case TOX_GROUP_MOD_EVENT_OBSERVER: - chat->peer_list[tgt_peernum].role = TOX_GROUP_ROLE_OBSERVER; + chat->peer_list[tgt_index].role = TOX_GROUP_ROLE_OBSERVER; line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- %s has set %s's role to observer", src_name, tgt_name); break; case TOX_GROUP_MOD_EVENT_USER: - chat->peer_list[tgt_peernum].role = TOX_GROUP_ROLE_USER; + chat->peer_list[tgt_index].role = TOX_GROUP_ROLE_USER; line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- %s has set %s's role to user", src_name, tgt_name); break; case TOX_GROUP_MOD_EVENT_MODERATOR: - chat->peer_list[tgt_peernum].role = TOX_GROUP_ROLE_MODERATOR; + chat->peer_list[tgt_index].role = TOX_GROUP_ROLE_MODERATOR; line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- %s has set %s's role to moderator", src_name, tgt_name); break; default: @@ -731,7 +820,7 @@ static void groupchat_onGroupModeration(ToxWindow *self, Tox *m, uint32_t groupn } } -static void groupchat_onGroupNickChange(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peernum, +static void groupchat_onGroupNickChange(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peer_id, const char *newnick, size_t len) { if (groupnum != self->num) @@ -739,29 +828,40 @@ static void groupchat_onGroupNickChange(ToxWindow *self, Tox *m, uint32_t groupn GroupChat *chat = &groupchats[groupnum]; + int peer_index = get_peer_index(groupnum, peer_id); + + if (peer_index < 0) + return; + char oldnick[TOX_MAX_NAME_LENGTH]; - get_group_nick_truncate(m, oldnick, peernum, groupnum); + get_group_nick_truncate(m, oldnick, peer_id, groupnum); len = MAX(len, TOX_MAX_NAME_LENGTH - 1); - memcpy(groupchats[groupnum].peer_list[peernum].name, newnick, len); - chat->peer_list[peernum].name[len] = '\0'; - chat->peer_list[peernum].name_length = len; + memcpy(groupchats[groupnum].peer_list[peer_index].name, newnick, len); + chat->peer_list[peer_index].name[len] = '\0'; + chat->peer_list[peer_index].name_length = len; char timefrmt[TIME_STR_SIZE]; get_time_str(timefrmt, sizeof(timefrmt)); - line_info_add(self, timefrmt, oldnick, chat->peer_list[peernum].name, NAME_CHANGE, 0, MAGENTA, " is now known as "); + line_info_add(self, timefrmt, oldnick, chat->peer_list[peer_index].name, NAME_CHANGE, 0, MAGENTA, + " is now known as "); group_update_name_list(groupnum); } -static void groupchat_onGroupStatusChange(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peernum, +static void groupchat_onGroupStatusChange(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peer_id, TOX_USER_STATUS status) { if (groupnum != self->num) return; + int peer_index = get_peer_index(groupnum, peer_id); + + if (peer_index < 0) + return; + GroupChat *chat = &groupchats[groupnum]; - chat->peer_list[peernum].status = status; + chat->peer_list[peer_index].status = status; } static void send_group_message(ToxWindow *self, Tox *m, uint32_t groupnum, const char *msg, TOX_MESSAGE_TYPE type) @@ -810,45 +910,51 @@ static void send_group_message(ToxWindow *self, Tox *m, uint32_t groupnum, const } } -static void send_group_prvt_message(ToxWindow *self, Tox *m, uint32_t groupnum, const char *data) +static void send_group_prvt_message(ToxWindow *self, Tox *m, uint32_t groupnum, const char *data, size_t data_len) { ChatContext *ctx = self->chatwin; GroupChat *chat = &groupchats[groupnum]; - if (data == NULL) { - wprintw(ctx->history, "Message is empty.\n"); + if (data == NULL || data_len == 0) { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, "Message is empty."); return; } - size_t i; - int peernum = -1, nick_len = 0; - char *nick = NULL; + uint32_t i; + uint32_t peer_id, name_length = 0; + const char *nick = NULL; /* need to match the longest nick in case of nicks that are smaller sub-strings */ - for (i = 0; i < chat->num_peers; ++i) { + for (i = 0; i < chat->max_idx; ++i) { + if (!chat->peer_list[i].active) + continue; + + if (data_len <= chat->peer_list[i].name_length) + continue; + if (memcmp(chat->peer_list[i].name, data, chat->peer_list[i].name_length) == 0) { - if (chat->peer_list[i].name_length > nick_len) { - nick_len = chat->peer_list[i].name_length; + if (chat->peer_list[i].name_length > name_length ) { + name_length = chat->peer_list[i].name_length; nick = chat->peer_list[i].name; - peernum = i; + peer_id = chat->peer_list[i].peer_id; } } } - if (peernum == -1) { + if (nick == NULL) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name."); return; } - int msg_len = strlen(data) - chat->peer_list[i].name_length - 1; + int msg_len = ((int) data_len) - ((int) name_length) - 1; if (msg_len <= 0) return; - const char *msg = data + chat->peer_list[i].name_length + 1; + const char *msg = data + name_length + 1; TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE err; - if (!tox_group_send_private_message(m, groupnum, peernum, (uint8_t *) msg, msg_len, &err)) { + if (!tox_group_send_private_message(m, groupnum, peer_id, (uint8_t *) msg, msg_len, &err)) { if (err == TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_PERMISSIONS) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * You are silenced."); } else { @@ -858,11 +964,8 @@ static void send_group_prvt_message(ToxWindow *self, Tox *m, uint32_t groupnum, return; } - /* turn "peername" into ">peername<" to signify private message */ - char pm_nick[TOX_MAX_NAME_LENGTH + 2]; - strcpy(pm_nick, ">"); - strcpy(pm_nick + 1, nick); - strcpy(pm_nick + 1 + chat->peer_list[i].name_length, "<"); + char pm_nick[TOX_MAX_NAME_LENGTH + 3]; + snprintf(pm_nick, sizeof(pm_nick), ">%s<", nick); char timefrmt[TIME_STR_SIZE]; get_time_str(timefrmt, sizeof(timefrmt)); @@ -926,10 +1029,10 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) } else if (key == user_settings->key_peer_list_down) { /* Scroll peerlist up and down one position */ int L = y2 - CHATBOX_HEIGHT - SDBAR_OFST; - if (groupchats[self->num].side_pos < groupchats[self->num].num_peers - L) + if (chat->side_pos < (int) chat->num_peers - L) ++chat->side_pos; } else if (key == user_settings->key_peer_list_up) { - if (groupchats[self->num].side_pos > 0) + if (chat->side_pos > 0) --chat->side_pos; } else if (key == '\n') { rm_trailing_spaces_buf(ctx); @@ -954,7 +1057,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) } else if (strncmp(line, "/me ", strlen("/me ")) == 0) { send_group_message(self, m, self->num, line + 4, TOX_MESSAGE_TYPE_ACTION); } else if (strncmp(line, "/whisper ", strlen("/whisper ")) == 0) { - send_group_prvt_message(self, m, self->num, line + 9); + send_group_prvt_message(self, m, self->num, line + 9, ctx->len - 9); } else { execute(ctx->history, self, m, line, GROUPCHAT_COMMAND_MODE); } @@ -1005,38 +1108,41 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m) mvwhline(ctx->sidebar, 1, 1, ACS_HLINE, SIDEBAR_WIDTH - 1); int maxlines = y2 - SDBAR_OFST - CHATBOX_HEIGHT; - uint32_t i; + uint32_t i, offset = 0; - for (i = 0; i < chat->num_peers && i < maxlines; ++i) { - wmove(ctx->sidebar, i + 2, 1); - int peer = i + chat->side_pos; + for (i = 0; i < chat->max_idx && i < maxlines; ++i) { + if (!chat->peer_list[i].active) + continue; - int maxlen_offset = chat->peer_list[i].role == TOX_GROUP_ROLE_USER ? 2 : 3; + wmove(ctx->sidebar, offset + 2, 1); + int p = i + chat->side_pos; + + int maxlen_offset = chat->peer_list[p].role == TOX_GROUP_ROLE_USER ? 2 : 3; /* truncate nick to fit in side panel without modifying list */ char tmpnck[TOX_MAX_NAME_LENGTH]; int maxlen = SIDEBAR_WIDTH - maxlen_offset; - memcpy(tmpnck, chat->peer_list[peer].name, maxlen); + memcpy(tmpnck, chat->peer_list[p].name, maxlen); tmpnck[maxlen] = '\0'; int namecolour = WHITE; - if (chat->peer_list[i].status == TOX_USER_STATUS_AWAY) + if (chat->peer_list[p].status == TOX_USER_STATUS_AWAY) namecolour = YELLOW; - else if (chat->peer_list[i].status == TOX_USER_STATUS_BUSY) + else if (chat->peer_list[p].status == TOX_USER_STATUS_BUSY) namecolour = RED; /* Signify roles (e.g. founder, moderator) */ const char *rolesig = ""; int rolecolour = WHITE; - if (chat->peer_list[i].role == TOX_GROUP_ROLE_FOUNDER) { + if (chat->peer_list[p].role == TOX_GROUP_ROLE_FOUNDER) { rolesig = "&"; rolecolour = BLUE; - } else if (chat->peer_list[i].role == TOX_GROUP_ROLE_MODERATOR) { + } else if (chat->peer_list[p].role == TOX_GROUP_ROLE_MODERATOR) { rolesig = "+"; rolecolour = GREEN; - } else if (chat->peer_list[i].role == TOX_GROUP_ROLE_OBSERVER) { + } else if (chat->peer_list[p].role == TOX_GROUP_ROLE_OBSERVER) { rolesig = "-"; rolecolour = MAGENTA; } @@ -1048,6 +1154,8 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m) wattron(ctx->sidebar, COLOR_PAIR(namecolour)); wprintw(ctx->sidebar, "%s\n", tmpnck); wattroff(ctx->sidebar, COLOR_PAIR(namecolour)); + + ++offset; } pthread_mutex_unlock(&Winthread.lock); @@ -1110,7 +1218,6 @@ ToxWindow new_group_chat(Tox *m, uint32_t groupnum, const char *groupname, int l ret.onDraw = &groupchat_onDraw; ret.onInit = &groupchat_onInit; ret.onGroupMessage = &groupchat_onGroupMessage; - ret.onGroupPeerlistUpdate = &groupchat_onGroupPeerlistUpdate; ret.onGroupPrivateMessage = &groupchat_onGroupPrivateMessage; ret.onGroupPeerJoin = &groupchat_onGroupPeerJoin; ret.onGroupPeerExit = &groupchat_onGroupPeerExit; diff --git a/src/groupchat.h b/src/groupchat.h index 61f8cf9..62ac668 100644 --- a/src/groupchat.h +++ b/src/groupchat.h @@ -32,8 +32,10 @@ #define GROUP_EVENT_WAIT 3 struct GroupPeer { + bool active; char name[TOX_MAX_NAME_LENGTH]; size_t name_length; + uint32_t peer_id; TOX_USER_STATUS status; TOX_GROUP_ROLE role; }; @@ -41,19 +43,20 @@ struct GroupPeer { typedef struct { struct GroupPeer *peer_list; char *name_list; /* List of peer names, needed for tab completion */ - uint32_t num_peers; + uint32_t num_peers; /* Number of peers in the chat/name_list array */ + uint32_t max_idx; /* Maximum peer list index - 1 */ uint32_t groupnumber; int chatwin; bool active; - bool is_connected; - int side_pos; /* current position of the sidebar - used for scrolling up and down */ + uint64_t time_connected; /* The time we successfully connected to the group */ + int side_pos; /* current position of the sidebar - used for scrolling up and down */ } GroupChat; void close_groupchat(ToxWindow *self, Tox *m, uint32_t groupnum); int init_groupchat_win(Tox *m, uint32_t groupnum, const char *groupname, size_t length); void set_nick_all_groups(Tox *m, const char *nick, size_t length); void set_status_all_groups(Tox *m, uint8_t status); -int group_get_nick_peernumber(uint32_t groupnum, const char *nick); +int group_get_nick_peer_id(uint32_t groupnum, const char *nick, uint32_t *peer_id); /* destroys and re-creates groupchat window */ void redraw_groupchat_win(ToxWindow *self); diff --git a/src/misc_tools.c b/src/misc_tools.c index 5487806..e10671f 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -293,16 +293,16 @@ size_t get_nick_truncate(Tox *m, char *buf, uint32_t friendnum) } /* same as get_nick_truncate but for groupchats */ -int get_group_nick_truncate(Tox *m, char *buf, int peernum, int groupnum) +int get_group_nick_truncate(Tox *m, char *buf, uint32_t peer_id, int groupnum) { TOX_ERR_GROUP_PEER_QUERY err; - size_t len = tox_group_peer_get_name_size(m, groupnum, peernum, &err); + size_t len = tox_group_peer_get_name_size(m, groupnum, peer_id, &err); if (err != TOX_ERR_GROUP_PEER_QUERY_OK) { strcpy(buf, UNKNOWN_NAME); len = strlen(UNKNOWN_NAME); } else { - tox_group_peer_get_name(m, groupnum, peernum, (uint8_t *) buf, &err); + tox_group_peer_get_name(m, groupnum, peer_id, (uint8_t *) buf, &err); if (err != TOX_ERR_GROUP_PEER_QUERY_OK) { strcpy(buf, UNKNOWN_NAME); diff --git a/src/misc_tools.h b/src/misc_tools.h index 44ce5f0..df4e2f3 100644 --- a/src/misc_tools.h +++ b/src/misc_tools.h @@ -111,7 +111,7 @@ void str_to_lower(char *str); size_t get_nick_truncate(Tox *m, char *buf, uint32_t friendnum); /* same as get_nick_truncate but for groupchats */ -int get_group_nick_truncate(Tox *m, char *buf, int peernum, int groupnum); +int get_group_nick_truncate(Tox *m, char *buf, uint32_t peer_id, int groupnum); /* copies data to msg buffer. returns length of msg. diff --git a/src/toxic.c b/src/toxic.c index 41d606f..4786227 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -603,7 +603,6 @@ static void init_tox_callbacks(Tox *m) tox_callback_group_invite(m, on_group_invite, NULL); tox_callback_group_message(m, on_group_message, NULL); tox_callback_group_private_message(m, on_group_private_message, NULL); - tox_callback_group_peerlist_update(m, on_group_namelistchange, NULL); tox_callback_group_peer_join(m, on_group_peer_join, NULL); tox_callback_group_peer_exit(m, on_group_peer_exit, NULL); tox_callback_group_peer_name(m, on_group_nick_change, NULL); @@ -1147,6 +1146,7 @@ void DnD_callback(const char* asdv, DropType dt) int main(int argc, char *argv[]) { + update_unix_time(); parse_args(argc, argv); /* Use the -b flag to enable stderr */ diff --git a/src/toxic.h b/src/toxic.h index a4f456b..53bee44 100644 --- a/src/toxic.h +++ b/src/toxic.h @@ -119,7 +119,6 @@ void on_group_invite(Tox *m, uint32_t friendnumber, const uint8_t *invite_data, void on_group_message(Tox *m, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type, const uint8_t *message, size_t length, void *userdata); void on_group_private_message(Tox *m, uint32_t groupnumber, uint32_t peernumber, const uint8_t *message, size_t length, void *userdata); -void on_group_namelistchange(Tox *m, uint32_t groupnumber, void *userdata); void on_group_peer_join(Tox *m, uint32_t groupnumber, uint32_t peernumber, void *userdata); void on_group_peer_exit(Tox *m, uint32_t groupnumber, uint32_t peernumber, const uint8_t *partmsg, size_t length, void *userdata); void on_group_topic_change(Tox *m, uint32_t groupnumber, uint32_t peernumber, const uint8_t *topic, size_t length, void *userdata); diff --git a/src/windows.c b/src/windows.c index 0cd5c1b..2eacf8e 100644 --- a/src/windows.c +++ b/src/windows.c @@ -161,7 +161,7 @@ void on_group_invite(Tox *m, uint32_t friendnumber, const uint8_t *invite_data, } } -void on_group_message(Tox *m, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type, +void on_group_message(Tox *m, uint32_t groupnumber, uint32_t peer_id, TOX_MESSAGE_TYPE type, const uint8_t *message, size_t length, void *userdata) { char msg[MAX_STR_SIZE + 1]; @@ -171,11 +171,11 @@ void on_group_message(Tox *m, uint32_t groupnumber, uint32_t peernumber, TOX_MES for (i = 0; i < MAX_WINDOWS_NUM; ++i) { if (windows[i].onGroupMessage != NULL) - windows[i].onGroupMessage(&windows[i], m, groupnumber, peernumber, type, msg, length); + windows[i].onGroupMessage(&windows[i], m, groupnumber, peer_id, type, msg, length); } } -void on_group_private_message(Tox *m, uint32_t groupnumber, uint32_t peernumber, const uint8_t *message, +void on_group_private_message(Tox *m, uint32_t groupnumber, uint32_t peer_id, const uint8_t *message, size_t length, void *userdata) { char msg[MAX_STR_SIZE + 1]; @@ -185,41 +185,31 @@ void on_group_private_message(Tox *m, uint32_t groupnumber, uint32_t peernumber, for (i = 0; i < MAX_WINDOWS_NUM; ++i) { if (windows[i].onGroupPrivateMessage != NULL) - windows[i].onGroupPrivateMessage(&windows[i], m, groupnumber, peernumber, msg, length); + windows[i].onGroupPrivateMessage(&windows[i], m, groupnumber, peer_id, msg, length); } } -void on_group_namelistchange(Tox *m, uint32_t groupnumber, void *userdata) -{ - size_t i; - - for (i = 0; i < MAX_WINDOWS_NUM; ++i) { - if (windows[i].onGroupPeerlistUpdate != NULL) - windows[i].onGroupPeerlistUpdate(&windows[i], m, groupnumber); - } -} - -void on_group_status_change(Tox *m, uint32_t groupnumber, uint32_t peernumber, TOX_USER_STATUS status, void *userdata) +void on_group_status_change(Tox *m, uint32_t groupnumber, uint32_t peer_id, TOX_USER_STATUS status, void *userdata) { size_t i; for (i = 0; i < MAX_WINDOWS_NUM; ++i) { if (windows[i].onGroupStatusChange != NULL) - windows[i].onGroupStatusChange(&windows[i], m, groupnumber, peernumber, status); + windows[i].onGroupStatusChange(&windows[i], m, groupnumber, peer_id, status); } } -void on_group_peer_join(Tox *m, uint32_t groupnumber, uint32_t peernumber, void *userdata) +void on_group_peer_join(Tox *m, uint32_t groupnumber, uint32_t peer_id, void *userdata) { size_t i; for (i = 0; i < MAX_WINDOWS_NUM; ++i) { if (windows[i].onGroupPeerJoin != NULL) - windows[i].onGroupPeerJoin(&windows[i], m, groupnumber, peernumber); + windows[i].onGroupPeerJoin(&windows[i], m, groupnumber, peer_id); } } -void on_group_peer_exit(Tox *m, uint32_t groupnumber, uint32_t peernumber, const uint8_t *partmsg, size_t length, +void on_group_peer_exit(Tox *m, uint32_t groupnumber, uint32_t peer_id, const uint8_t *partmsg, size_t length, void *userdata) { char msg[MAX_STR_SIZE + 1]; @@ -235,11 +225,11 @@ void on_group_peer_exit(Tox *m, uint32_t groupnumber, uint32_t peernumber, const for (i = 0; i < MAX_WINDOWS_NUM; ++i) { if (windows[i].onGroupPeerExit != NULL) - windows[i].onGroupPeerExit(&windows[i], m, groupnumber, peernumber, msg, length); + windows[i].onGroupPeerExit(&windows[i], m, groupnumber, peer_id, msg, length); } } -void on_group_topic_change(Tox *m, uint32_t groupnumber, uint32_t peernumber, const uint8_t *topic, size_t length, +void on_group_topic_change(Tox *m, uint32_t groupnumber, uint32_t peer_id, const uint8_t *topic, size_t length, void *userdata) { char data[MAX_STR_SIZE + 1]; @@ -249,7 +239,7 @@ void on_group_topic_change(Tox *m, uint32_t groupnumber, uint32_t peernumber, co for (i = 0; i < MAX_WINDOWS_NUM; ++i) { if (windows[i].onGroupTopicChange != NULL) - windows[i].onGroupTopicChange(&windows[i], m, groupnumber, peernumber, data, length); + windows[i].onGroupTopicChange(&windows[i], m, groupnumber, peer_id, data, length); } } @@ -283,7 +273,7 @@ void on_group_password(Tox *m, uint32_t groupnumber, const uint8_t *password, si } } -void on_group_nick_change(Tox *m, uint32_t groupnumber, uint32_t peernumber, const uint8_t *newname, size_t length, +void on_group_nick_change(Tox *m, uint32_t groupnumber, uint32_t peer_id, const uint8_t *newname, size_t length, void *userdata) { char name[TOXIC_MAX_NAME_LENGTH + 1]; @@ -294,7 +284,7 @@ void on_group_nick_change(Tox *m, uint32_t groupnumber, uint32_t peernumber, con for (i = 0; i < MAX_WINDOWS_NUM; ++i) { if (windows[i].onGroupNickChange != NULL) - windows[i].onGroupNickChange(&windows[i], m, groupnumber, peernumber, name, length); + windows[i].onGroupNickChange(&windows[i], m, groupnumber, peer_id, name, length); } } @@ -318,14 +308,14 @@ void on_group_rejected(Tox *m, uint32_t groupnumber, TOX_GROUP_JOIN_FAIL type, v } } -void on_group_moderation(Tox *m, uint32_t groupnumber, uint32_t source_peernum, uint32_t target_peernum, +void on_group_moderation(Tox *m, uint32_t groupnumber, uint32_t source_peer_id, uint32_t target_peer_id, TOX_GROUP_MOD_EVENT type, void *userdata) { size_t i; for (i = 0; i < MAX_WINDOWS_NUM; ++i) { if (windows[i].onGroupModeration != NULL) - windows[i].onGroupModeration(&windows[i], m, groupnumber, source_peernum, target_peernum, type); + windows[i].onGroupModeration(&windows[i], m, groupnumber, source_peer_id, target_peer_id, type); } } diff --git a/src/windows.h b/src/windows.h index 010f590..ffe253d 100644 --- a/src/windows.h +++ b/src/windows.h @@ -131,7 +131,6 @@ struct ToxWindow { void(*onGroupInvite)(ToxWindow *, Tox *, uint32_t, const char *, size_t); void(*onGroupMessage)(ToxWindow *, Tox *, uint32_t, uint32_t, TOX_MESSAGE_TYPE, const char *, size_t); void(*onGroupPrivateMessage)(ToxWindow *, Tox *, uint32_t, uint32_t, const char *, size_t); - void(*onGroupPeerlistUpdate)(ToxWindow *, Tox *, uint32_t); void(*onGroupPeerJoin)(ToxWindow *, Tox *, uint32_t, uint32_t); void(*onGroupPeerExit)(ToxWindow *, Tox *, uint32_t, uint32_t, const char *, size_t); void(*onGroupNickChange)(ToxWindow *, Tox *, uint32_t, uint32_t, const char *, size_t);