mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-26 22:53:28 +01:00
simplify groupchat counter
This commit is contained in:
parent
39f1587a6e
commit
73cc9bfcf2
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
extern char *DATA_FILE;
|
extern char *DATA_FILE;
|
||||||
extern int store_data(Tox *m, char *path);
|
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)
|
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);
|
wprintw(ctx->history, "%s has invited you to a group chat.\n", name);
|
||||||
|
|
||||||
int ngc = get_num_groupchats();
|
if (num_groupchats >= MAX_GROUPCHAT_NUM) {
|
||||||
|
|
||||||
if (ngc < 0 || ngc > MAX_GROUPCHAT_NUM) {
|
|
||||||
wprintw(ctx->history, "Maximum number of group chats has been reached. Discarding invite.\n");
|
wprintw(ctx->history, "Maximum number of group chats has been reached. Discarding invite.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ extern char *DATA_FILE;
|
|||||||
|
|
||||||
extern uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
|
extern uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
|
||||||
extern uint8_t num_frnd_requests;
|
extern uint8_t num_frnd_requests;
|
||||||
|
extern int num_groupchats;
|
||||||
|
|
||||||
/* command functions */
|
/* command functions */
|
||||||
void cmd_accept(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
|
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])
|
void cmd_groupchat(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
|
||||||
{
|
{
|
||||||
int ngc = get_num_groupchats();
|
if (num_groupchats >= MAX_GROUPCHAT_NUM) {
|
||||||
|
|
||||||
if (ngc < 0 || ngc > MAX_GROUPCHAT_NUM) {
|
|
||||||
wprintw(window, "\nMaximum number of group chats has been reached.\n");
|
wprintw(window, "\nMaximum number of group chats has been reached.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -15,37 +15,28 @@
|
|||||||
#include "misc_tools.h"
|
#include "misc_tools.h"
|
||||||
|
|
||||||
static GroupChat groupchats[MAX_GROUPCHAT_NUM];
|
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);
|
ToxWindow new_group_chat(Tox *m, ToxWindow *prompt, int groupnum);
|
||||||
|
|
||||||
extern char *DATA_FILE;
|
extern char *DATA_FILE;
|
||||||
extern int store_data(Tox *m, char *path);
|
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 init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i <= group_chat_index; ++i) {
|
for (i = 0; i <= max_groupchat_index; ++i) {
|
||||||
if (!groupchats[i].active) {
|
if (!groupchats[i].active) {
|
||||||
groupchats[i].chatwin = add_window(m, new_group_chat(m, prompt, groupnum));
|
groupchats[i].chatwin = add_window(m, new_group_chat(m, prompt, groupnum));
|
||||||
groupchats[i].active = true;
|
groupchats[i].active = true;
|
||||||
set_active_window(groupchats[i].chatwin);
|
set_active_window(groupchats[i].chatwin);
|
||||||
|
|
||||||
if (i == group_chat_index)
|
if (i == max_groupchat_index)
|
||||||
++group_chat_index;
|
++max_groupchat_index;
|
||||||
|
|
||||||
|
++num_groupchats;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -57,16 +48,17 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum)
|
|||||||
static void close_groupchatwin(Tox *m, int groupnum)
|
static void close_groupchatwin(Tox *m, int groupnum)
|
||||||
{
|
{
|
||||||
tox_del_groupchat(m, groupnum);
|
tox_del_groupchat(m, groupnum);
|
||||||
memset(&groupchats[groupnum], 0, sizeof(GroupChat));
|
memset(&(groupchats[groupnum]), 0, sizeof(GroupChat));
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = group_chat_index; i > 0; --i) {
|
for (i = max_groupchat_index; i > 0; --i) {
|
||||||
if (groupchats[i-1].active)
|
if (groupchats[i-1].active)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
group_chat_index = i;
|
--num_groupchats;
|
||||||
|
max_groupchat_index = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_groupchat_help(ChatContext *ctx)
|
static void print_groupchat_help(ChatContext *ctx)
|
||||||
|
@ -3,4 +3,3 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum);
|
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum);
|
||||||
int get_num_groupchats(void);
|
|
||||||
|
Loading…
Reference in New Issue
Block a user