mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 02:43:01 +01:00
added groupchat actions
This commit is contained in:
parent
8b1dbd44ba
commit
34cc4314a5
38
src/chat.c
38
src/chat.c
@ -442,34 +442,30 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
delwin(statusbar->topline);
|
||||
del_window(self);
|
||||
disable_chatwin(f_num);
|
||||
} else if (!strncmp(line, "/me ", strlen("/me ")))
|
||||
} else if (strncmp(line, "/me ", strlen("/me ")) == 0)
|
||||
send_action(self, ctx, m, line + strlen("/me "));
|
||||
else
|
||||
execute(ctx->history, self, m, line, CHAT_COMMAND_MODE);
|
||||
} else {
|
||||
/* make sure the string has at least non-space character */
|
||||
if (!string_is_empty(line)) {
|
||||
uint8_t selfname[TOX_MAX_NAME_LENGTH];
|
||||
tox_get_self_name(m, selfname, TOX_MAX_NAME_LENGTH);
|
||||
} else if (!string_is_empty(line)) {
|
||||
uint8_t selfname[TOX_MAX_NAME_LENGTH];
|
||||
tox_get_self_name(m, selfname, TOX_MAX_NAME_LENGTH);
|
||||
|
||||
print_time(ctx->history);
|
||||
print_time(ctx->history);
|
||||
wattron(ctx->history, COLOR_PAIR(GREEN));
|
||||
wprintw(ctx->history, "%s: ", selfname);
|
||||
wattroff(ctx->history, COLOR_PAIR(GREEN));
|
||||
|
||||
if (line[0] == '>') {
|
||||
wattron(ctx->history, COLOR_PAIR(GREEN));
|
||||
wprintw(ctx->history, "%s: ", selfname);
|
||||
wprintw(ctx->history, "%s\n", line);
|
||||
wattroff(ctx->history, COLOR_PAIR(GREEN));
|
||||
} else
|
||||
wprintw(ctx->history, "%s\n", line);
|
||||
|
||||
if (line[0] == '>') {
|
||||
wattron(ctx->history, COLOR_PAIR(GREEN));
|
||||
wprintw(ctx->history, "%s\n", line);
|
||||
wattroff(ctx->history, COLOR_PAIR(GREEN));
|
||||
} else
|
||||
wprintw(ctx->history, "%s\n", line);
|
||||
|
||||
if (!statusbar->is_online
|
||||
|| tox_send_message(m, self->num, line, strlen(line) + 1) == 0) {
|
||||
wattron(ctx->history, COLOR_PAIR(RED));
|
||||
wprintw(ctx->history, " * Failed to send message.\n");
|
||||
wattroff(ctx->history, COLOR_PAIR(RED));
|
||||
}
|
||||
if (!statusbar->is_online || tox_send_message(m, self->num, line, strlen(line) + 1) == 0) {
|
||||
wattron(ctx->history, COLOR_PAIR(RED));
|
||||
wprintw(ctx->history, " * Failed to send message.\n");
|
||||
wattroff(ctx->history, COLOR_PAIR(RED));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,14 +26,15 @@ static int num_selected = 0;
|
||||
ToxicFriend friends[MAX_FRIENDS_NUM];
|
||||
static int friendlist_index[MAX_FRIENDS_NUM] = {0};
|
||||
|
||||
#define S_WEIGHT 100
|
||||
|
||||
static int index_name_cmp(const void *n1, const void *n2)
|
||||
{
|
||||
int res = qsort_strcasecmp_hlpr(friends[*(int *) n1].name, friends[*(int *) n2].name);
|
||||
|
||||
int k = 100;
|
||||
/* Use weight to make qsort always put online friends before offline */
|
||||
res = friends[*(int *) n1].online ? (res - k) : (res + k);
|
||||
res = friends[*(int *) n2].online ? (res + k) : (res - k);
|
||||
res = friends[*(int *) n1].online ? (res - S_WEIGHT) : (res + S_WEIGHT);
|
||||
res = friends[*(int *) n2].online ? (res + S_WEIGHT) : (res - S_WEIGHT);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -138,6 +138,40 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
||||
}
|
||||
}
|
||||
|
||||
static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int peernum, uint8_t *action,
|
||||
uint16_t len)
|
||||
{
|
||||
if (self->num != groupnum)
|
||||
return;
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
/* check if message contains own name and alert appropriately */
|
||||
int alert_type = WINDOW_ALERT_1;
|
||||
bool beep = false;
|
||||
|
||||
uint8_t selfnick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_get_self_name(m, selfnick, TOX_MAX_NAME_LENGTH);
|
||||
|
||||
bool nick_match = strcasestr(action, selfnick);
|
||||
|
||||
if (nick_match) {
|
||||
alert_type = WINDOW_ALERT_0;
|
||||
beep = true;
|
||||
}
|
||||
|
||||
alert_window(self, alert_type, beep);
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_group_peername(m, groupnum, peernum, nick);
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0'; /* enforce client max name length */
|
||||
|
||||
print_time(ctx->history);
|
||||
wattron(ctx->history, COLOR_PAIR(YELLOW));
|
||||
wprintw(ctx->history, "* %s %s\n", nick, action);
|
||||
wattroff(ctx->history, COLOR_PAIR(YELLOW));
|
||||
}
|
||||
|
||||
/* Puts two copies of peerlist in chat instance */
|
||||
static void copy_peernames(int gnum, int npeers, uint8_t tmp_peerlist[][TOX_MAX_NAME_LENGTH])
|
||||
{
|
||||
@ -235,6 +269,27 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
|
||||
alert_window(self, WINDOW_ALERT_2, false);
|
||||
}
|
||||
|
||||
static void send_group_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *action) {
|
||||
if (action == NULL) {
|
||||
wprintw(ctx->history, "Invalid syntax.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// uint8_t selfname[TOX_MAX_NAME_LENGTH];
|
||||
// tox_get_self_name(m, selfname, TOX_MAX_NAME_LENGTH);
|
||||
|
||||
// print_time(ctx->history);
|
||||
// wattron(ctx->history, COLOR_PAIR(YELLOW));
|
||||
// wprintw(ctx->history, "* %s %s\n", selfname, action);
|
||||
// wattroff(ctx->history, COLOR_PAIR(YELLOW));
|
||||
|
||||
if (tox_group_action_send(m, self->num, action, strlen(action) + 1) == -1) {
|
||||
wattron(ctx->history, COLOR_PAIR(RED));
|
||||
wprintw(ctx->history, " * Failed to send action\n");
|
||||
wattroff(ctx->history, COLOR_PAIR(RED));
|
||||
}
|
||||
}
|
||||
|
||||
static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
{
|
||||
ChatContext *ctx = self->chatwin;
|
||||
@ -400,35 +455,24 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
delwin(ctx->linewin);
|
||||
del_window(self);
|
||||
close_groupchatwin(m, groupnum);
|
||||
} else if (strncmp(line, "/help", strlen("/help")) == 0)
|
||||
} else if (strcmp(line, "/help") == 0)
|
||||
print_groupchat_help(ctx);
|
||||
else if (strncmp(line, "/me ", strlen("/me ")) == 0)
|
||||
send_group_action(self, ctx, m, line + strlen("/me "));
|
||||
else
|
||||
execute(ctx->history, self, m, line, GROUPCHAT_COMMAND_MODE);
|
||||
} else {
|
||||
/* make sure the string has at least non-space character */
|
||||
if (!string_is_empty(line)) {
|
||||
// uint8_t selfname[TOX_MAX_NAME_LENGTH];
|
||||
// tox_get_self_name(m, selfname, TOX_MAX_NAME_LENGTH);
|
||||
|
||||
// print_time(ctx->history);
|
||||
// wattron(ctx->history, COLOR_PAIR(GREEN));
|
||||
// wprintw(ctx->history, "%s: ", selfname);
|
||||
// wattroff(ctx->history, COLOR_PAIR(GREEN));
|
||||
// wprintw(ctx->history, "%s\n", line);
|
||||
|
||||
if (tox_group_message_send(m, self->num, line, strlen(line) + 1) == -1) {
|
||||
wattron(ctx->history, COLOR_PAIR(RED));
|
||||
wprintw(ctx->history, " * Failed to send message.\n");
|
||||
wattroff(ctx->history, COLOR_PAIR(RED));
|
||||
}
|
||||
} else if (!string_is_empty(line)) {
|
||||
if (tox_group_message_send(m, self->num, line, strlen(line) + 1) == -1) {
|
||||
wattron(ctx->history, COLOR_PAIR(RED));
|
||||
wprintw(ctx->history, " * Failed to send message.\n");
|
||||
wattroff(ctx->history, COLOR_PAIR(RED));
|
||||
}
|
||||
}
|
||||
|
||||
if (close_win)
|
||||
free(ctx);
|
||||
else {
|
||||
else
|
||||
reset_buf(ctx->line, &ctx->pos, &ctx->len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -507,7 +551,7 @@ ToxWindow new_group_chat(Tox *m, int groupnum)
|
||||
ret.onInit = &groupchat_onInit;
|
||||
ret.onGroupMessage = &groupchat_onGroupMessage;
|
||||
ret.onGroupNamelistChange = &groupchat_onGroupNamelistChange;
|
||||
// ret.onAction = &groupchat_onAction;
|
||||
ret.onGroupAction = &groupchat_onGroupAction;
|
||||
|
||||
snprintf(ret.name, sizeof(ret.name), "Room #%d", groupnum);
|
||||
|
||||
|
@ -116,6 +116,7 @@ static Tox *init_tox(int ipv4)
|
||||
tox_callback_friend_action(m, on_action, NULL);
|
||||
tox_callback_group_invite(m, on_groupinvite, NULL);
|
||||
tox_callback_group_message(m, on_groupmessage, NULL);
|
||||
tox_callback_group_action(m, on_groupaction, NULL);
|
||||
tox_callback_group_namelist_change(m, on_group_namelistchange, NULL);
|
||||
tox_callback_file_send_request(m, on_file_sendrequest, NULL);
|
||||
tox_callback_file_control(m, on_file_control, NULL);
|
||||
|
@ -77,6 +77,7 @@ struct ToxWindow {
|
||||
void(*onStatusMessageChange)(ToxWindow *, int, uint8_t *, uint16_t);
|
||||
void(*onAction)(ToxWindow *, Tox *, int, uint8_t *, uint16_t);
|
||||
void(*onGroupMessage)(ToxWindow *, Tox *, int, int, uint8_t *, uint16_t);
|
||||
void(*onGroupAction)(ToxWindow *, Tox *, int, int, uint8_t *, uint16_t);
|
||||
void(*onGroupInvite)(ToxWindow *, Tox *, int, uint8_t *);
|
||||
void(*onGroupNamelistChange)(ToxWindow *, Tox*, int, int, uint8_t);
|
||||
void(*onFileSendRequest)(ToxWindow *, Tox *, int, uint8_t, uint64_t, uint8_t *, uint16_t);
|
||||
@ -178,6 +179,7 @@ void on_statuschange(Tox *m, int friendnumber, TOX_USERSTATUS status, void *user
|
||||
void on_statusmessagechange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata);
|
||||
void on_friendadded(Tox *m, int friendnumber, bool sort);
|
||||
void on_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message, uint16_t length, void *userdata);
|
||||
void on_groupaction(Tox *m, int groupnumber, int peernumber, uint8_t *action, 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, 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);
|
||||
|
@ -117,6 +117,17 @@ void on_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message,
|
||||
}
|
||||
}
|
||||
|
||||
void on_groupaction(Tox *m, int groupnumber, int peernumber, uint8_t *action, uint16_t length,
|
||||
void *userdata)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onGroupAction != NULL)
|
||||
windows[i].onGroupAction(&windows[i], m, groupnumber, peernumber, action, length);
|
||||
}
|
||||
}
|
||||
|
||||
void on_groupinvite(Tox *m, int friendnumber, uint8_t *group_pub_key, void *userdata)
|
||||
{
|
||||
int i;
|
||||
|
Loading…
Reference in New Issue
Block a user