1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-12 23:33:03 +01:00

simplify groupchat counter

This commit is contained in:
Jfreegman 2013-11-17 16:09:14 -05:00
parent 39f1587a6e
commit 73cc9bfcf2
4 changed files with 15 additions and 26 deletions

View File

@ -16,6 +16,7 @@
extern char *DATA_FILE;
extern int store_data(Tox *m, char *path);
extern int num_groupchats;
static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint16_t len)
{
@ -225,9 +226,7 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int friendnumber, uint8_
wprintw(ctx->history, "%s has invited you to a group chat.\n", name);
int ngc = get_num_groupchats();
if (ngc < 0 || ngc > MAX_GROUPCHAT_NUM) {
if (num_groupchats >= MAX_GROUPCHAT_NUM) {
wprintw(ctx->history, "Maximum number of group chats has been reached. Discarding invite.\n");
return;
}

View File

@ -16,6 +16,7 @@ extern char *DATA_FILE;
extern uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
extern uint8_t num_frnd_requests;
extern int num_groupchats;
/* command functions */
void cmd_accept(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
@ -172,9 +173,7 @@ void cmd_connect(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, c
void cmd_groupchat(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
int ngc = get_num_groupchats();
if (ngc < 0 || ngc > MAX_GROUPCHAT_NUM) {
if (num_groupchats >= MAX_GROUPCHAT_NUM) {
wprintw(window, "\nMaximum number of group chats has been reached.\n");
return;
}

View File

@ -15,37 +15,28 @@
#include "misc_tools.h"
static GroupChat groupchats[MAX_GROUPCHAT_NUM];
static int group_chat_index = 0;
static int max_groupchat_index = 0;
int num_groupchats = 0;
ToxWindow new_group_chat(Tox *m, ToxWindow *prompt, int groupnum);
extern char *DATA_FILE;
extern int store_data(Tox *m, char *path);
int get_num_groupchats(void)
{
int i;
for (i = 0; i <= group_chat_index; ++i) {
if (!groupchats[i].active)
return i;
}
return -1;
}
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum)
{
int i;
for (i = 0; i <= group_chat_index; ++i) {
for (i = 0; i <= max_groupchat_index; ++i) {
if (!groupchats[i].active) {
groupchats[i].chatwin = add_window(m, new_group_chat(m, prompt, groupnum));
groupchats[i].active = true;
set_active_window(groupchats[i].chatwin);
if (i == group_chat_index)
++group_chat_index;
if (i == max_groupchat_index)
++max_groupchat_index;
++num_groupchats;
return 0;
}
@ -57,16 +48,17 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum)
static void close_groupchatwin(Tox *m, int groupnum)
{
tox_del_groupchat(m, groupnum);
memset(&groupchats[groupnum], 0, sizeof(GroupChat));
memset(&(groupchats[groupnum]), 0, sizeof(GroupChat));
int i;
for (i = group_chat_index; i > 0; --i) {
for (i = max_groupchat_index; i > 0; --i) {
if (groupchats[i-1].active)
break;
}
group_chat_index = i;
--num_groupchats;
max_groupchat_index = i;
}
static void print_groupchat_help(ChatContext *ctx)

View File

@ -3,4 +3,3 @@
*/
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum);
int get_num_groupchats(void);