mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-26 15:53:26 +01:00
testing groupchat stuff
This commit is contained in:
parent
8dabfdc2da
commit
5e37ddc0f8
@ -25,7 +25,7 @@ static int num_selected = 0;
|
||||
|
||||
static int friendlist_index[MAX_FRIENDS_NUM] = {0};
|
||||
|
||||
int index_name_cmp(const void *n1, const void *n2)
|
||||
static int index_name_cmp(const void *n1, const void *n2)
|
||||
{
|
||||
int res = name_compare(friends[*(int *) n1].name, friends[*(int *) n2].name);
|
||||
|
||||
|
@ -101,7 +101,7 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
||||
|
||||
print_time(ctx->history);
|
||||
wattron(ctx->history, COLOR_PAIR(4));
|
||||
wprintw(ctx->history, "%s: ", nick);
|
||||
wprintw(ctx->history, "%s (peernum %d): ", nick, peernum);
|
||||
wattroff(ctx->history, COLOR_PAIR(4));
|
||||
|
||||
if (msg[0] == '>') {
|
||||
@ -114,13 +114,70 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
||||
self->blink = true;
|
||||
}
|
||||
|
||||
static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnum)
|
||||
static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnum, int peernum,
|
||||
uint8_t change)
|
||||
{
|
||||
if (self->num != groupnum)
|
||||
return;
|
||||
|
||||
groupchats[groupnum].num_peers = MIN(tox_group_number_peers(m, groupnum), MAX_GROUP_PEERS);
|
||||
/* Temporary */
|
||||
if (peernum < 0 || peernum > MAX_GROUP_PEERS)
|
||||
return;
|
||||
|
||||
/* get old peer name before updating name list */
|
||||
uint8_t oldpeername[TOX_MAX_NAME_LENGTH] = {0};
|
||||
snprintf(oldpeername, sizeof(oldpeername), "%s", groupchats[groupnum].oldpeer_names[peernum]);
|
||||
|
||||
if (string_is_empty(oldpeername))
|
||||
strcpy(oldpeername, (uint8_t *) UNKNOWN_NAME);
|
||||
|
||||
groupchats[groupnum].num_peers = tox_group_number_peers(m, groupnum);
|
||||
|
||||
/* two copies: oldpeer_names will be unsorted and match correct peernums on the next callback */
|
||||
tox_group_copy_names(m, groupnum, groupchats[groupnum].peer_names, groupchats[groupnum].num_peers);
|
||||
tox_group_copy_names(m, groupnum, groupchats[groupnum].oldpeer_names, groupchats[groupnum].num_peers);
|
||||
|
||||
uint8_t *peername = groupchats[groupnum].peer_names[peernum];
|
||||
|
||||
if (string_is_empty(peername))
|
||||
peername = (uint8_t *) UNKNOWN_NAME;
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
|
||||
print_time(ctx->history);
|
||||
|
||||
switch (change) {
|
||||
case TOX_CHAT_CHANGE_PEER_ADD:
|
||||
wattron(ctx->history, COLOR_PAIR(GREEN));
|
||||
wattron(ctx->history, A_BOLD);
|
||||
wprintw(ctx->history, "* %s (peernum %d)", peername, peernum);
|
||||
wattroff(ctx->history, A_BOLD);
|
||||
wprintw(ctx->history, " has joined the room.\n");
|
||||
wattroff(ctx->history, COLOR_PAIR(GREEN));
|
||||
break;
|
||||
case TOX_CHAT_CHANGE_PEER_DEL:
|
||||
wattron(ctx->history, COLOR_PAIR(RED));
|
||||
wattron(ctx->history, A_BOLD);
|
||||
wprintw(ctx->history, "* %s (peernum %d)", oldpeername, peernum);
|
||||
wattroff(ctx->history, A_BOLD);
|
||||
wprintw(ctx->history, " has left the room.\n");
|
||||
wattroff(ctx->history, COLOR_PAIR(RED));
|
||||
break;
|
||||
case TOX_CHAT_CHANGE_PEER_NAME:
|
||||
wattron(ctx->history, COLOR_PAIR(MAGENTA));
|
||||
wattron(ctx->history, A_BOLD);
|
||||
wprintw(ctx->history, "* %s (peernum %d)", oldpeername, peernum);
|
||||
wattroff(ctx->history, A_BOLD);
|
||||
|
||||
wprintw(ctx->history, " is now known as ");
|
||||
|
||||
wattron(ctx->history, A_BOLD);
|
||||
wprintw(ctx->history, "%s.\n", peername);
|
||||
wattroff(ctx->history, A_BOLD);
|
||||
wattroff(ctx->history, COLOR_PAIR(MAGENTA));
|
||||
break;
|
||||
}
|
||||
|
||||
qsort(groupchats[groupnum].peer_names, groupchats[groupnum].num_peers, TOX_MAX_NAME_LENGTH, name_compare);
|
||||
}
|
||||
|
||||
@ -225,7 +282,8 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
|
||||
for (i = 0; i < num_peers; ++i) {
|
||||
wmove(ctx->sidebar, i, 1);
|
||||
groupchats[self->num].peer_names[i][SIDEBAR_WIDTH-2] = '\0';
|
||||
uint8_t *nick = strlen(groupchats[self->num].peer_names[i]) ? groupchats[self->num].peer_names[i] : (uint8_t *) UNKNOWN_NAME;
|
||||
uint8_t *nick = strlen(groupchats[self->num].peer_names[i]) ?\
|
||||
groupchats[self->num].peer_names[i] : (uint8_t *) UNKNOWN_NAME;
|
||||
wprintw(ctx->sidebar, "%s\n", nick);
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,14 @@
|
||||
#define CHATBOX_HEIGHT 4
|
||||
|
||||
/* Limits # of peers in sidepanel (make this go away) */
|
||||
#define MAX_GROUP_PEERS 100
|
||||
#define MAX_GROUP_PEERS 500
|
||||
|
||||
typedef struct {
|
||||
int chatwin;
|
||||
bool active;
|
||||
int num_peers;
|
||||
uint8_t peer_names[MAX_GROUP_PEERS][TOX_MAX_NAME_LENGTH];
|
||||
uint8_t oldpeer_names[MAX_GROUP_PEERS][TOX_MAX_NAME_LENGTH];
|
||||
} GroupChat;
|
||||
|
||||
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum);
|
||||
|
@ -61,7 +61,7 @@ struct ToxWindow_ {
|
||||
void(*onAction)(ToxWindow *, Tox *, int, uint8_t *, uint16_t);
|
||||
void(*onGroupMessage)(ToxWindow *, Tox *, int, int, uint8_t *, uint16_t);
|
||||
void(*onGroupInvite)(ToxWindow *, Tox *, int, uint8_t *);
|
||||
void(*onGroupNamelistChange)(ToxWindow *, Tox*, int);
|
||||
void(*onGroupNamelistChange)(ToxWindow *, Tox*, int, int, uint8_t);
|
||||
void(*onFileSendRequest)(ToxWindow *, Tox *, int, uint8_t, uint64_t, uint8_t *, uint16_t);
|
||||
void(*onFileControl)(ToxWindow *, Tox *, int, uint8_t, uint8_t, uint8_t, uint8_t *, uint16_t);
|
||||
void(*onFileData)(ToxWindow *, Tox *, int, uint8_t, uint8_t *, uint16_t);
|
||||
@ -150,7 +150,7 @@ void on_statusmessagechange(Tox *m, int friendnumber, uint8_t *string, uint16_t
|
||||
void on_friendadded(Tox *m, int friendnumber);
|
||||
void on_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message, uint16_t length, void *userdata);
|
||||
void on_groupinvite(Tox *m, int friendnumber, uint8_t *group_pub_key, void *userdata);
|
||||
void on_group_namelistchange(Tox *m, int groupnumber, void *userdata);
|
||||
void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata);
|
||||
void on_file_sendrequest(Tox *m, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *pathname, uint16_t pathname_length, void *userdata);
|
||||
void on_file_control(Tox *m, int friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata);
|
||||
void on_file_data(Tox *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata);
|
||||
|
@ -127,13 +127,13 @@ void on_groupinvite(Tox *m, int friendnumber, uint8_t *group_pub_key, void *user
|
||||
}
|
||||
}
|
||||
|
||||
void on_group_namelistchange(Tox *m, int groupnumber, void *userdata)
|
||||
void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onGroupNamelistChange != NULL)
|
||||
windows[i].onGroupNamelistChange(&windows[i], m, groupnumber);
|
||||
windows[i].onGroupNamelistChange(&windows[i], m, groupnumber, peernumber, change);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user