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

implemented typing status

This commit is contained in:
Jfreegman 2014-02-23 04:28:33 -05:00
parent 6269eafeaa
commit 2b707f1d80
5 changed files with 54 additions and 1 deletions

View File

@ -45,6 +45,14 @@ static const uint8_t chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = {
{ "/status" }, { "/status" },
}; };
static void set_typingstatus(ToxWindow *self, Tox *m, bool is_typing)
{
ChatContext *ctx = self->chatwin;
tox_set_user_is_typing(m, self->num, is_typing);
ctx->self_is_typing = is_typing;
}
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)
{ {
if (self->num != num) if (self->num != num)
@ -77,7 +85,22 @@ static void chat_onConnectionChange(ToxWindow *self, Tox *m, int num, uint8_t st
return; return;
StatusBar *statusbar = self->stb; StatusBar *statusbar = self->stb;
statusbar->is_online = status == 1 ? true : false;
if (status == 1) {
statusbar->is_online = true;
friends[num].is_typing = tox_get_is_typing(m, num);
} else {
statusbar->is_online = false;
friends[num].is_typing = false;
}
}
static void chat_onTypingChange(ToxWindow *self, Tox *m, int num, int is_typing)
{
if (self->num != num)
return;
friends[num].is_typing = is_typing;
} }
static void chat_onAction(ToxWindow *self, Tox *m, int num, uint8_t *action, uint16_t len) static void chat_onAction(ToxWindow *self, Tox *m, int num, uint8_t *action, uint16_t len)
@ -416,6 +439,9 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
else else
wmove(self->window, y, x + MAX(1, wcwidth(key))); wmove(self->window, y, x + MAX(1, wcwidth(key)));
} }
if (!ctx->self_is_typing)
set_typingstatus(self, m, true);
} }
/* RETURN key: Execute command or print line */ /* RETURN key: Execute command or print line */
else if (key == '\n') { else if (key == '\n') {
@ -473,6 +499,9 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
reset_buf(ctx->line, &ctx->pos, &ctx->len); reset_buf(ctx->line, &ctx->pos, &ctx->len);
} }
} }
if (ctx->len <= 0 && ctx->self_is_typing)
set_typingstatus(self, m, false);
} }
static void chat_onDraw(ToxWindow *self, Tox *m) static void chat_onDraw(ToxWindow *self, Tox *m)
@ -523,9 +552,16 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
break; break;
} }
if (friends[self->num].is_typing)
wattron(statusbar->topline, COLOR_PAIR(YELLOW));
wattron(statusbar->topline, A_BOLD); wattron(statusbar->topline, A_BOLD);
wprintw(statusbar->topline, " %s ", self->name); wprintw(statusbar->topline, " %s ", self->name);
wattroff(statusbar->topline, A_BOLD); wattroff(statusbar->topline, A_BOLD);
if (friends[self->num].is_typing)
wattroff(statusbar->topline, COLOR_PAIR(YELLOW));
wattron(statusbar->topline, COLOR_PAIR(colour) | A_BOLD); wattron(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);
wprintw(statusbar->topline, "[%s]", status_text); wprintw(statusbar->topline, "[%s]", status_text);
wattroff(statusbar->topline, COLOR_PAIR(colour) | A_BOLD); wattroff(statusbar->topline, COLOR_PAIR(colour) | A_BOLD);
@ -611,6 +647,7 @@ ToxWindow new_chat(Tox *m, int friendnum)
ret.onInit = &chat_onInit; ret.onInit = &chat_onInit;
ret.onMessage = &chat_onMessage; ret.onMessage = &chat_onMessage;
ret.onConnectionChange = &chat_onConnectionChange; ret.onConnectionChange = &chat_onConnectionChange;
ret.onTypingChange = & chat_onTypingChange;
ret.onGroupInvite = &chat_onGroupInvite; ret.onGroupInvite = &chat_onGroupInvite;
ret.onNickChange = &chat_onNickChange; ret.onNickChange = &chat_onNickChange;
ret.onStatusChange = &chat_onStatusChange; ret.onStatusChange = &chat_onStatusChange;

View File

@ -14,6 +14,7 @@ typedef struct {
int chatwin; int chatwin;
bool active; bool active;
bool online; bool online;
bool is_typing;
TOX_USERSTATUS status; TOX_USERSTATUS status;
struct FileReceiver file_receiver; struct FileReceiver file_receiver;
} ToxicFriend; } ToxicFriend;

View File

@ -108,6 +108,7 @@ static Tox *init_tox(int ipv4)
/* Callbacks */ /* Callbacks */
tox_callback_connection_status(m, on_connectionchange, NULL); tox_callback_connection_status(m, on_connectionchange, NULL);
tox_callback_typing_change(m, on_typing_change, NULL);
tox_callback_friend_request(m, on_request, NULL); tox_callback_friend_request(m, on_request, NULL);
tox_callback_friend_message(m, on_message, NULL); tox_callback_friend_message(m, on_message, NULL);
tox_callback_name_change(m, on_nickchange, NULL); tox_callback_name_change(m, on_nickchange, NULL);

View File

@ -84,6 +84,7 @@ struct ToxWindow {
void(*onFileSendRequest)(ToxWindow *, Tox *, int, uint8_t, uint64_t, uint8_t *, uint16_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(*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); void(*onFileData)(ToxWindow *, Tox *, int, uint8_t, uint8_t *, uint16_t);
void(*onTypingChange)(ToxWindow *, Tox *, int, int);
char name[TOX_MAX_NAME_LENGTH]; char name[TOX_MAX_NAME_LENGTH];
int num; int num;
@ -124,6 +125,8 @@ struct ChatContext {
int hst_pos; int hst_pos;
int hst_tot; int hst_tot;
bool self_is_typing;
WINDOW *history; WINDOW *history;
WINDOW *linewin; WINDOW *linewin;
WINDOW *sidebar; WINDOW *sidebar;
@ -185,6 +188,7 @@ void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t ch
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_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_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); void on_file_data(Tox *m, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata);
void on_typing_change(Tox *m, int friendnumber, int is_typing, void *userdata);
ToxWindow *init_windows(Tox *m); ToxWindow *init_windows(Tox *m);
void draw_active_window(Tox *m); void draw_active_window(Tox *m);

View File

@ -37,6 +37,16 @@ void on_connectionchange(Tox *m, int friendnumber, uint8_t status, void *userdat
} }
} }
void on_typing_change(Tox *m, int friendnumber, int is_typing, void *userdata)
{
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onTypingChange != NULL)
windows[i].onTypingChange(&windows[i], m, friendnumber, is_typing);
}
}
void on_message(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) void on_message(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata)
{ {
int i; int i;