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

refactor groupchats to allow scrolling

This commit is contained in:
Jfreegman 2014-03-25 08:21:50 -04:00
parent 2f981ecb12
commit a5ce17f44e
10 changed files with 148 additions and 128 deletions

View File

@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.65])
AC_INIT([toxic], [0.3.1], [https://tox.im/])
AC_INIT([toxic], [0.3.2], [https://tox.im/])
AC_CONFIG_AUX_DIR(configure_aux)
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS([config.h])

View File

@ -793,12 +793,14 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
static void chat_onInit(ToxWindow *self, Tox *m)
{
curs_set(1);
int x2, y2;
getmaxyx(self->window, y2, x2);
self->x = x2;
/* Init statusbar info */
StatusBar *statusbar = self->stb;
statusbar->status = tox_get_user_status(m, self->num);
statusbar->is_online = tox_get_friend_connection_status(m, self->num) == 1;
@ -809,6 +811,7 @@ static void chat_onInit(ToxWindow *self, Tox *m)
/* Init subwindows */
ChatContext *ctx = self->chatwin;
statusbar->topline = subwin(self->window, 2, x2, 0, 0);
ctx->history = subwin(self->window, y2-CHATBOX_HEIGHT+1, x2, 0, 0);
scrollok(ctx->history, 1);

View File

@ -34,6 +34,7 @@
#include "chat.h"
#include "friendlist.h"
#include "misc_tools.h"
#include "line_info.h"
#ifdef _SUPPORT_AUDIO
#include "audio_call.h"
@ -104,12 +105,14 @@ static void friendlist_onMessage(ToxWindow *self, Tox *m, int32_t num, uint8_t *
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
tox_get_name(m, num, nick);
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
wprintw(prompt->window, "%s: %s\n", nick, str);
wattron(prompt->window, COLOR_PAIR(RED));
wprintw(prompt->window, "* Warning: Too many windows are open.\n");
wattron(prompt->window, COLOR_PAIR(RED));
uint8_t timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt);
line_info_add(prompt, timefrmt, nick, NULL, str, IN_MSG, 0, 0);
uint8_t *msg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
alert_window(prompt, WINDOW_ALERT_1, true);
}
}
@ -120,7 +123,7 @@ static void friendlist_onConnectionChange(ToxWindow *self, Tox *m, int32_t num,
if (num >= max_friends_index)
return;
friends[num].online = status == 1 ? true : false;
friends[num].online = status;
update_friend_last_online(num, get_unix_time());
store_data(m, DATA_FILE);
sort_friendlist_index();
@ -210,9 +213,9 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, u
tox_get_name(m, num, nick);
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
wattron(prompt->window, COLOR_PAIR(RED));
wprintw(prompt->window, "* File transfer from %s failed: too many windows are open.\n", nick);
wattron(prompt->window, COLOR_PAIR(RED));
uint8_t msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "* File transfer from %s failed: too many windows are open.", nick);
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
alert_window(prompt, WINDOW_ALERT_1, true);
}
@ -232,9 +235,9 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, uint8
tox_get_name(m, num, nick);
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
wattron(prompt->window, COLOR_PAIR(RED));
wprintw(prompt->window, "* Group chat invite from %s failed: too many windows are open.\n", nick);
wattron(prompt->window, COLOR_PAIR(RED));
uint8_t msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "* Group chat invite from %s failed: too many windows are open.", nick);
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
alert_window(prompt, WINDOW_ALERT_1, true);
}
@ -340,9 +343,8 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
friends[f].chatwin = add_window(m, new_chat(m, friends[f].num));
set_active_window(friends[f].chatwin);
} else {
wattron(prompt->window, COLOR_PAIR(RED));
wprintw(prompt->window, "* Warning: Too many windows are open.\n");
wattron(prompt->window, COLOR_PAIR(RED));
uint8_t *msg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
alert_window(prompt, WINDOW_ALERT_1, true);
}
@ -534,11 +536,13 @@ static void friendlist_onAv(ToxWindow *self, ToxAv *av)
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
tox_get_name(m, id, nick);
nick[TOXIC_MAX_NAME_LENGTH] = '\0';
wprintw(prompt->window, "Audio action from: %s!\n", nick);
wattron(prompt->window, COLOR_PAIR(RED));
wprintw(prompt->window, "* Warning: Too many windows are open.\n");
wattron(prompt->window, COLOR_PAIR(RED));
uint8_t msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Audio action from: %s!", nick);
line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
uint8_t *errmsg = "* Warning: Too many windows are open.";
line_info_add(prompt, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
alert_window(prompt, WINDOW_ALERT_0, true);
}

View File

@ -181,8 +181,9 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
void cmd_clear(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
wclear(window);
wprintw(window, "\n\n");
struct history *hst = self->chatwin->hst;
line_info_cleanup(hst);
line_info_init(hst);
}
void cmd_connect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
@ -393,7 +394,7 @@ void cmd_prompt_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
{ " /groupchat : Create a group chat" },
{ " /myid : Print your ID" },
{ " /help : Print this message again" },
{ " /clear : Clear the window" },
{ " /clear : Clear window history" },
{ " /quit or /exit : Exit Toxic" },
#ifdef _SUPPORT_AUDIO
{ " /lsdev <type> : List devices where type: in|out" },

View File

@ -35,6 +35,7 @@
#include "prompt.h"
#include "toxic_strings.h"
#include "log.h"
#include "line_info.h"
extern char *DATA_FILE;
extern int store_data(Tox *m, char *path);
@ -103,29 +104,38 @@ static void close_groupchat(ToxWindow *self, Tox *m, int groupnum)
kill_groupchat_window(self);
}
static void print_groupchat_help(ChatContext *ctx)
static void print_groupchat_help(ToxWindow *self)
{
wattron(ctx->history, COLOR_PAIR(CYAN) | A_BOLD);
wprintw(ctx->history, "Group chat commands:\n");
wattroff(ctx->history, COLOR_PAIR(CYAN) | A_BOLD);
uint8_t *msg = "Group chat commands:";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN);
wprintw(ctx->history, " /add <id> <msg> : Add friend with optional message\n");
wprintw(ctx->history, " /status <type> <msg>: Set your status with optional note\n");
wprintw(ctx->history, " /note <msg> : Set a personal note\n");
wprintw(ctx->history, " /nick <nick> : Set your nickname\n");
wprintw(ctx->history, " /groupchat : Create a group chat\n");
wprintw(ctx->history, " /log <on> or <off> : Enable/disable logging\n");
wprintw(ctx->history, " /close : Close the current group chat\n");
wprintw(ctx->history, " /help : Print this message again\n");
wprintw(ctx->history, " /help global : Show a list of global commands\n");
wattron(ctx->history, COLOR_PAIR(CYAN) | A_BOLD);
wprintw(ctx->history, " * Argument messages must be enclosed in quotation marks.\n");
wprintw(ctx->history, " * Scroll peer list with the Page Up/Page Down keys.\n\n");
wattroff(ctx->history, COLOR_PAIR(CYAN) | A_BOLD);
wattron(ctx->history, COLOR_PAIR(WHITE) | A_BOLD);
wprintw(ctx->history, " Notice, some friends will be missing names while finding peers\n\n");
wattroff(ctx->history, COLOR_PAIR(WHITE) | A_BOLD);
#define NUMLINES 9
uint8_t lines[NUMLINES][MAX_STR_SIZE] = {
{ " /add <id> <msg> : Add friend with optional message" },
{ " /status <type> <msg>: Set your status with optional note" },
{ " /note <msg> : Set a personal note" },
{ " /nick <nick> : Set your nickname" },
{ " /groupchat : Create a group chat" },
{ " /log <on> or <off> : Enable/disable logging" },
{ " /close : Close the current group chat" },
{ " /help : Print this message again" },
{ " /help global : Show a list of global commands" },
};
int i;
for (i = 0; i < NUMLINES; ++i)
line_info_add(self, NULL, NULL, NULL, lines[i], SYS_MSG, 0, 0);
msg = " * Use ESC key to toggle history scroll mode";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN);
msg = " * Scroll peer list with the Page Up/Page Down keys.\n";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN);
msg = " * Notice, some friends will be missing names while finding peers\n";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, 0);
}
static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int peernum,
@ -158,19 +168,10 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
alert_window(self, alert_type, beep);
print_time(ctx->history);
wattron(ctx->history, COLOR_PAIR(nick_clr));
wprintw(ctx->history, "%s: ", nick);
wattroff(ctx->history, COLOR_PAIR(nick_clr));
if (msg[0] == '>') {
wattron(ctx->history, COLOR_PAIR(GREEN));
wprintw(ctx->history, "%s\n", msg);
wattroff(ctx->history, COLOR_PAIR(GREEN));
} else {
wprintw(ctx->history, "%s\n", msg);
}
uint8_t timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt);
line_info_add(self, timefrmt, nick, NULL, msg, IN_MSG, 0, nick_clr);
write_to_log(msg, nick, ctx->log, false);
}
@ -202,11 +203,10 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
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));
uint8_t timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt);
line_info_add(self, timefrmt, nick, NULL, action, ACTION, 0, 0);
write_to_log(action, nick, ctx->log, true);
}
@ -270,31 +270,21 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
qsort(groupchats[groupnum].peer_names, groupchats[groupnum].num_peers, TOX_MAX_NAME_LENGTH, qsort_strcasecmp_hlpr);
ChatContext *ctx = self->chatwin;
print_time(ctx->history);
const uint8_t *event;
uint8_t *event;
uint8_t timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt);
switch (change) {
case TOX_CHAT_CHANGE_PEER_ADD:
event = "has joined the room";
wattron(ctx->history, COLOR_PAIR(GREEN));
wattron(ctx->history, A_BOLD);
wprintw(ctx->history, "* %s", peername);
wattroff(ctx->history, A_BOLD);
wprintw(ctx->history, " %s\n", event);
wattroff(ctx->history, COLOR_PAIR(GREEN));
line_info_add(self, timefrmt, peername, NULL, event, CONNECTION, 0, GREEN);
write_to_log(event, peername, ctx->log, true);
break;
case TOX_CHAT_CHANGE_PEER_DEL:
event = "has left the room";
wattron(ctx->history, A_BOLD);
wprintw(ctx->history, "* %s", oldpeername);
wattroff(ctx->history, A_BOLD);
wprintw(ctx->history, " %s\n", event);
line_info_add(self, timefrmt, oldpeername, NULL, event, CONNECTION, 0, 0);
if (groupchats[self->num].side_pos > 0)
--groupchats[self->num].side_pos;
@ -303,17 +293,8 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
break;
case TOX_CHAT_CHANGE_PEER_NAME:
wattron(ctx->history, COLOR_PAIR(MAGENTA));
wattron(ctx->history, A_BOLD);
wprintw(ctx->history, "* %s", oldpeername);
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));
event = " is now known as ";
line_info_add(self, timefrmt, oldpeername, peername, event, NAME_CHANGE, 0, 0);
uint8_t tmp_event[TOXIC_MAX_NAME_LENGTH + 32];
snprintf(tmp_event, sizeof(tmp_event), "is now known as %s", peername);
@ -331,9 +312,8 @@ static void send_group_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t
}
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));
uint8_t *errmsg = " * Failed to send action.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
}
}
@ -346,6 +326,17 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
getmaxyx(self->window, y2, x2);
int cur_len = 0;
if (key == T_KEY_ESC) { /* ESC key: Toggle history scroll mode */
bool scroll = ctx->hst->scroll_mode ? false : true;
line_info_toggle_scroll(self, scroll);
}
/* If we're in scroll mode ignore rest of function */
if (ctx->hst->scroll_mode) {
line_info_onKey(self, key);
return;
}
if (key == 0x107 || key == 0x8 || key == 0x7f) { /* BACKSPACE key: Remove character behind pos */
if (ctx->pos > 0) {
cur_len = MAX(1, wcwidth(ctx->line[ctx->pos - 1]));
@ -502,7 +493,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
wclear(ctx->linewin);
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
wclrtobot(self->window);
if (!string_is_empty(line))
add_line_to_hist(ctx->line, ctx->len, ctx->ln_history, &ctx->hst_tot, &ctx->hst_pos);
@ -515,7 +506,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
if (strcmp(line, "help global") == 0)
execute(ctx->history, self, m, "/help", GLOBAL_COMMAND_MODE);
else
print_groupchat_help(ctx);
print_groupchat_help(self);
} else if (strncmp(line, "/me ", strlen("/me ")) == 0) {
send_group_action(self, ctx, m, line + strlen("/me "));
@ -524,9 +515,8 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
}
} 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));
uint8_t *errmsg = " * Failed to send message.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);
}
}
@ -536,13 +526,17 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
static void groupchat_onDraw(ToxWindow *self, Tox *m)
{
curs_set(1);
int x2, y2;
getmaxyx(self->window, y2, x2);
ChatContext *ctx = self->chatwin;
if (!ctx->hst->scroll_mode)
scrollok(ctx->history, 1);
wclear(ctx->linewin);
line_info_print(self);
if (ctx->len > 0) {
uint8_t line[MAX_STR_SIZE];
@ -593,22 +587,26 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
getmaxyx(self->window, y, x);
ChatContext *ctx = self->chatwin;
ctx->history = subwin(self->window, y-CHATBOX_HEIGHT+1, x-SIDEBAR_WIDTH-1, 0, 0);
scrollok(ctx->history, 1);
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x, y-CHATBOX_HEIGHT, 0);
ctx->sidebar = subwin(self->window, y-CHATBOX_HEIGHT+1, SIDEBAR_WIDTH, 0, x-SIDEBAR_WIDTH);
ctx->hst = malloc(sizeof(struct history));
ctx->log = malloc(sizeof(struct chatlog));
if (ctx->log == NULL) {
if (ctx->log == NULL || ctx->hst == NULL) {
endwin();
fprintf(stderr, "malloc() failed. Aborting...\n");
exit(EXIT_FAILURE);
}
memset(ctx->hst, 0, sizeof(struct history));
memset(ctx->log, 0, sizeof(struct chatlog));
print_groupchat_help(ctx);
line_info_init(ctx->hst);
print_groupchat_help(self);
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);
wmove(self->window, y-CURS_Y_OFFSET, 0);

View File

@ -50,7 +50,7 @@ void line_info_init(struct history *hst)
static void line_info_reset_start(struct history *hst)
{
struct line_info *line = hst->line_end;
uint32_t start_id = hst->start_id;
uint32_t start_id = hst->start_id + 1;
while (line) {
if (line->id == start_id) {
@ -91,7 +91,7 @@ void line_info_cleanup(struct history *hst)
}
void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *name2, uint8_t *msg,
uint8_t msgtype, uint8_t bold, uint8_t colour)
uint8_t type, uint8_t bold, uint8_t colour)
{
struct history *hst = self->chatwin->hst;
struct line_info *new_line = malloc(sizeof(struct line_info));
@ -107,8 +107,9 @@ void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *na
int len = 1; /* there will always be a newline */
/* for type-specific formatting in print function */
switch (msgtype) {
switch (type) {
case ACTION:
case NAME_CHANGE:
len += 3;
break;
default:
@ -131,7 +132,7 @@ void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *na
}
new_line->len = len;
new_line->msgtype = msgtype;
new_line->type = type;
new_line->bold = bold;
new_line->colour = colour;
new_line->id = hst->line_end->id + 1;
@ -180,15 +181,19 @@ void line_info_print(ToxWindow *self)
WINDOW *win = ctx->history;
wclear(win);
wmove(win, 1, 0);
int y2, x2;
getmaxyx(self->window, y2, x2);
struct line_info *line = ctx->hst->line_start;
if (self->is_groupchat)
wmove(win, 0, 0);
else
wmove(win, 2, 0);
struct line_info *line = ctx->hst->line_start->next;
int numlines = 0;
while(line && numlines <= y2) {
uint8_t type = line->msgtype;
uint8_t type = line->type;
numlines += line->len / x2;
switch (type) {
@ -274,6 +279,25 @@ void line_info_print(ToxWindow *self)
wprintw(win, "%s\n", line->msg);
wattroff(win, COLOR_PAIR(line->colour));
break;
case NAME_CHANGE:
wattron(win, COLOR_PAIR(BLUE));
wprintw(win, "%s", line->timestamp);
wattroff(win, COLOR_PAIR(BLUE));
wattron(win, COLOR_PAIR(MAGENTA));
wattron(win, A_BOLD);
wprintw(win, "* %s", line->name1);
wattroff(win, A_BOLD);
wprintw(win, "%s", line->msg);
wattron(win, A_BOLD);
wprintw(win, "%s\n", line->name2);
wattroff(win, A_BOLD);
wattroff(win, COLOR_PAIR(MAGENTA));
break;
}

View File

@ -20,7 +20,7 @@
*
*/
#define MAX_HISTORY 50
#define MAX_HISTORY 200
enum {
SYS_MSG,
@ -29,6 +29,7 @@ enum {
PROMPT,
ACTION,
CONNECTION,
NAME_CHANGE,
} LINE_TYPE;
struct line_info {
@ -36,7 +37,7 @@ struct line_info {
uint8_t name1[TOXIC_MAX_NAME_LENGTH];
uint8_t name2[TOXIC_MAX_NAME_LENGTH];
uint8_t msg[MAX_STR_SIZE];
uint8_t msgtype;
uint8_t type;
uint8_t bold;
uint8_t colour;
uint32_t id;
@ -57,7 +58,7 @@ struct history {
};
void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *name2, uint8_t *msg,
uint8_t msgtype, uint8_t bold, uint8_t colour);
uint8_t type, uint8_t bold, uint8_t colour);
void line_info_cleanup(struct history *hst);
void line_info_toggle_scroll(ToxWindow *self, bool scroll);
void line_info_init(struct history *hst);

View File

@ -55,17 +55,6 @@ struct tm *get_time(void)
return timeinfo;
}
/* Prints the time to given window */
void print_time(WINDOW *window)
{
uint8_t s[MAX_STR_SIZE];
strftime(s, MAX_STR_SIZE, "[%H:%M:%S] ", get_time());
wattron(window, COLOR_PAIR(BLUE));
wprintw(window, "%s", s);
wattroff(window,COLOR_PAIR(BLUE));
}
void get_time_str(uint8_t *buf)
{
strftime(buf, TIME_STR_SIZE, "[%H:%M:%S] ", get_time());

View File

@ -29,8 +29,8 @@ unsigned char *hex_string_to_bin(char hex_string[]);
/* get the current unix time */
uint64_t get_unix_time(void);
/* Prints the time to given window */
void print_time(WINDOW *window);
/*Puts the current time in buf in the format of [Hour:Min:Sec] */
void get_time_str(uint8_t *buf);
/* get the current local time */
struct tm *get_time(void);

View File

@ -215,7 +215,6 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key)
int k = ctx->orig_y + ((ctx->len + p_ofst) / px2);
if (k >= y2) {
wprintw(ctx->history, "\n");
--ctx->orig_y;
}
}
@ -403,24 +402,25 @@ static void prompt_onFriendRequest(ToxWindow *self, Tox *m, uint8_t *key, uint8_
data[length - 1] = 0;
ChatContext *ctx = self->chatwin;
wprintw(ctx->history, "\n");
print_time(ctx->history);
uint8_t timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt);
uint8_t msg[MAX_STR_SIZE];
snprintf(msg, sizeof(msg), "Friend request with the message '%s'\n", data);
wprintw(ctx->history, "%s", msg);
snprintf(msg, sizeof(msg), "Friend request with the message '%s'", data);
line_info_add(self, timefrmt, NULL, NULL, msg, SYS_MSG, 0, 0);
write_to_log(msg, "", ctx->log, true);
int n = add_friend_request(key);
if (n == -1) {
const uint8_t *errmsg = "Friend request queue is full. Discarding request.\n";
wprintw(ctx->history, "%s", errmsg);
uint8_t *errmsg = "Friend request queue is full. Discarding request.";
line_info_add(self, NULL, NULL, NULL, errmsg, SYS_MSG, 0, 0);
write_to_log(errmsg, "", ctx->log, true);
return;
}
wprintw(ctx->history, "Type \"/accept %d\" to accept it.\n", n);
snprintf(msg, sizeof(msg), "Type \"/accept %d\" to accept it.", n);
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);
alert_window(self, WINDOW_ALERT_1, true);
}