mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 06:03:04 +01:00
bug fixes and code cleanup
This commit is contained in:
parent
a01cc35368
commit
33cfca7ecc
@ -53,7 +53,7 @@
|
|||||||
extern char *DATA_FILE;
|
extern char *DATA_FILE;
|
||||||
|
|
||||||
extern FileSender file_senders[MAX_FILES];
|
extern FileSender file_senders[MAX_FILES];
|
||||||
extern _Friends Friends;
|
extern FriendsList Friends;
|
||||||
|
|
||||||
extern struct Winthread Winthread;
|
extern struct Winthread Winthread;
|
||||||
extern struct user_settings *user_settings;
|
extern struct user_settings *user_settings;
|
||||||
@ -940,7 +940,6 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
|||||||
|
|
||||||
wclear(ctx->linewin);
|
wclear(ctx->linewin);
|
||||||
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
||||||
line_info_reset_start(self, ctx->hst);
|
|
||||||
reset_buf(ctx);
|
reset_buf(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
#include "file_senders.h"
|
#include "file_senders.h"
|
||||||
|
|
||||||
extern ToxWindow *prompt;
|
extern ToxWindow *prompt;
|
||||||
extern _Friends Friends;
|
extern FriendsList Friends;
|
||||||
|
|
||||||
extern FileSender file_senders[MAX_FILES];
|
extern FileSender file_senders[MAX_FILES];
|
||||||
extern uint8_t max_file_senders_index;
|
extern uint8_t max_file_senders_index;
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
FileSender file_senders[MAX_FILES];
|
FileSender file_senders[MAX_FILES];
|
||||||
uint8_t max_file_senders_index;
|
uint8_t max_file_senders_index;
|
||||||
uint8_t num_active_file_senders;
|
uint8_t num_active_file_senders;
|
||||||
extern _Friends Friends;
|
extern FriendsList Friends;
|
||||||
|
|
||||||
/* creates initial progress line that will be updated during file transfer.
|
/* creates initial progress line that will be updated during file transfer.
|
||||||
Assumes progline is of size MAX_STR_SIZE */
|
Assumes progline is of size MAX_STR_SIZE */
|
||||||
|
@ -53,9 +53,9 @@ extern struct arg_opts arg_opts;
|
|||||||
|
|
||||||
static uint8_t blocklist_view = 0; /* 0 if we're in friendlist view, 1 if we're in blocklist view */
|
static uint8_t blocklist_view = 0; /* 0 if we're in friendlist view, 1 if we're in blocklist view */
|
||||||
|
|
||||||
_Friends Friends;
|
FriendsList Friends;
|
||||||
|
|
||||||
static struct _Blocked {
|
static struct Blocked {
|
||||||
int num_selected;
|
int num_selected;
|
||||||
int max_idx;
|
int max_idx;
|
||||||
int num_blocked;
|
int num_blocked;
|
||||||
@ -64,7 +64,7 @@ static struct _Blocked {
|
|||||||
BlockedFriend *list;
|
BlockedFriend *list;
|
||||||
} Blocked;
|
} Blocked;
|
||||||
|
|
||||||
static struct _pendingDel {
|
static struct pendingDel {
|
||||||
int num;
|
int num;
|
||||||
bool active;
|
bool active;
|
||||||
WINDOW *popup;
|
WINDOW *popup;
|
||||||
@ -115,7 +115,7 @@ void kill_friendlist(void)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i <= Friends.max_idx; ++i) {
|
for (i = 0; i <= Friends.max_idx; ++i) {
|
||||||
if (Friends.list[i].group_invite.key != NULL)
|
if (Friends.list[i].active && Friends.list[i].group_invite.key != NULL)
|
||||||
free(Friends.list[i].group_invite.key);
|
free(Friends.list[i].group_invite.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +171,7 @@ static int save_blocklist(char *path)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
return ret;
|
||||||
|
|
||||||
on_error:
|
on_error:
|
||||||
free(data);
|
free(data);
|
||||||
|
@ -88,7 +88,7 @@ typedef struct {
|
|||||||
int num_friends;
|
int num_friends;
|
||||||
int *index;
|
int *index;
|
||||||
ToxicFriend *list;
|
ToxicFriend *list;
|
||||||
} _Friends;
|
} FriendsList;
|
||||||
|
|
||||||
ToxWindow new_friendlist(void);
|
ToxWindow new_friendlist(void);
|
||||||
void disable_chatwin(int32_t f_num);
|
void disable_chatwin(int32_t f_num);
|
||||||
|
@ -37,8 +37,8 @@
|
|||||||
|
|
||||||
extern char *DATA_FILE;
|
extern char *DATA_FILE;
|
||||||
extern ToxWindow *prompt;
|
extern ToxWindow *prompt;
|
||||||
extern _Friends Friends;
|
extern FriendsList Friends;
|
||||||
extern _FriendRequests FriendRequests;
|
extern FriendRequests FrndRequests;
|
||||||
|
|
||||||
/* command functions */
|
/* command functions */
|
||||||
void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||||
@ -55,13 +55,13 @@ void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FriendRequests.request[req].active) {
|
if (!FrndRequests.request[req].active) {
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend request with that ID.");
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend request with that ID.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *msg;
|
const char *msg;
|
||||||
int32_t friendnum = tox_add_friend_norequest(m, FriendRequests.request[req].key);
|
int32_t friendnum = tox_add_friend_norequest(m, FrndRequests.request[req].key);
|
||||||
|
|
||||||
if (friendnum == -1)
|
if (friendnum == -1)
|
||||||
msg = "Failed to add friend.";
|
msg = "Failed to add friend.";
|
||||||
@ -70,17 +70,17 @@ void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
|
|||||||
on_friendadded(m, friendnum, true);
|
on_friendadded(m, friendnum, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&FriendRequests.request[req], 0, sizeof(struct friend_request));
|
memset(&FrndRequests.request[req], 0, sizeof(struct friend_request));
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = FriendRequests.max_idx; i > 0; --i) {
|
for (i = FrndRequests.max_idx; i > 0; --i) {
|
||||||
if (FriendRequests.request[i - 1].active)
|
if (FrndRequests.request[i - 1].active)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
FriendRequests.max_idx = i;
|
FrndRequests.max_idx = i;
|
||||||
--FriendRequests.num_requests;
|
--FrndRequests.num_requests;
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,7 +193,8 @@ void cmd_avatar(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
|
|||||||
|
|
||||||
/* turns the avatar off */
|
/* turns the avatar off */
|
||||||
if (strlen(argv[1]) < 3) {
|
if (strlen(argv[1]) < 3) {
|
||||||
tox_set_avatar(m, TOX_AVATAR_FORMAT_NONE, (const uint8_t *) NULL, 0);
|
tox_unset_avatar(m);
|
||||||
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No avatar set.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,6 +251,10 @@ void cmd_avatar(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
|
|||||||
if (tox_set_avatar(m, TOX_AVATAR_FORMAT_PNG, (const uint8_t *) avatar, (uint32_t) sz) == -1)
|
if (tox_set_avatar(m, TOX_AVATAR_FORMAT_PNG, (const uint8_t *) avatar, (uint32_t) sz) == -1)
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar: Core error.");
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set avatar: Core error.");
|
||||||
|
|
||||||
|
char filename[MAX_STR_SIZE];
|
||||||
|
get_file_name(filename, sizeof(filename), path);
|
||||||
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Avatar set to '%s'", filename);
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
free(avatar);
|
free(avatar);
|
||||||
}
|
}
|
||||||
@ -297,22 +302,22 @@ void cmd_decline(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FriendRequests.request[req].active) {
|
if (!FrndRequests.request[req].active) {
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend request with that ID.");
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend request with that ID.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&FriendRequests.request[req], 0, sizeof(struct friend_request));
|
memset(&FrndRequests.request[req], 0, sizeof(struct friend_request));
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = FriendRequests.max_idx; i > 0; --i) {
|
for (i = FrndRequests.max_idx; i > 0; --i) {
|
||||||
if (FriendRequests.request[i - 1].active)
|
if (FrndRequests.request[i - 1].active)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
FriendRequests.max_idx = i;
|
FrndRequests.max_idx = i;
|
||||||
--FriendRequests.num_requests;
|
--FrndRequests.num_requests;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||||
@ -469,7 +474,7 @@ void cmd_quit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
|
|||||||
|
|
||||||
void cmd_requests(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
void cmd_requests(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||||
{
|
{
|
||||||
if (FriendRequests.num_requests == 0) {
|
if (FrndRequests.num_requests == 0) {
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend requests.");
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend requests.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -477,22 +482,22 @@ void cmd_requests(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
|
|||||||
int i, j;
|
int i, j;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
for (i = 0; i < FriendRequests.max_idx; ++i) {
|
for (i = 0; i < FrndRequests.max_idx; ++i) {
|
||||||
if (!FriendRequests.request[i].active)
|
if (!FrndRequests.request[i].active)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
char id[TOX_CLIENT_ID_SIZE * 2 + 1] = {0};
|
char id[TOX_CLIENT_ID_SIZE * 2 + 1] = {0};
|
||||||
|
|
||||||
for (j = 0; j < TOX_CLIENT_ID_SIZE; ++j) {
|
for (j = 0; j < TOX_CLIENT_ID_SIZE; ++j) {
|
||||||
char d[3];
|
char d[3];
|
||||||
snprintf(d, sizeof(d), "%02X", FriendRequests.request[i].key[j] & 0xff);
|
snprintf(d, sizeof(d), "%02X", FrndRequests.request[i].key[j] & 0xff);
|
||||||
strcat(id, d);
|
strcat(id, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%d : %s", i, id);
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%d : %s", i, id);
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", FriendRequests.request[i].msg);
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", FrndRequests.request[i].msg);
|
||||||
|
|
||||||
if (++count < FriendRequests.num_requests)
|
if (++count < FrndRequests.num_requests)
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "");
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -430,7 +430,6 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
|||||||
|
|
||||||
wclear(ctx->linewin);
|
wclear(ctx->linewin);
|
||||||
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
||||||
line_info_reset_start(self, ctx->hst);
|
|
||||||
reset_buf(ctx);
|
reset_buf(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,6 +258,10 @@ static void line_info_check_queue(ToxWindow *self)
|
|||||||
++hst->start_id;
|
++hst->start_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* force move to bottom of history when we print an outgoing message */
|
||||||
|
if (line->type == OUT_MSG)
|
||||||
|
line_info_reset_start(self, hst);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NOREAD_FLAG_TIMEOUT 5 /* seconds before a sent message with no read receipt is flagged as unread */
|
#define NOREAD_FLAG_TIMEOUT 5 /* seconds before a sent message with no read receipt is flagged as unread */
|
||||||
|
21
src/prompt.c
21
src/prompt.c
@ -46,7 +46,7 @@ extern ToxWindow *prompt;
|
|||||||
extern struct user_settings *user_settings;
|
extern struct user_settings *user_settings;
|
||||||
extern struct Winthread Winthread;
|
extern struct Winthread Winthread;
|
||||||
|
|
||||||
_FriendRequests FriendRequests;
|
FriendRequests FrndRequests;
|
||||||
|
|
||||||
/* Array of global command names used for tab completion. */
|
/* Array of global command names used for tab completion. */
|
||||||
const char glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE] = {
|
const char glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||||
@ -132,21 +132,21 @@ void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected)
|
|||||||
Returns request number on success, -1 if queue is full. */
|
Returns request number on success, -1 if queue is full. */
|
||||||
static int add_friend_request(const char *public_key, const char *data)
|
static int add_friend_request(const char *public_key, const char *data)
|
||||||
{
|
{
|
||||||
if (FriendRequests.max_idx >= MAX_FRIEND_REQUESTS)
|
if (FrndRequests.max_idx >= MAX_FRIEND_REQUESTS)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i <= FriendRequests.max_idx; ++i) {
|
for (i = 0; i <= FrndRequests.max_idx; ++i) {
|
||||||
if (!FriendRequests.request[i].active) {
|
if (!FrndRequests.request[i].active) {
|
||||||
FriendRequests.request[i].active = true;
|
FrndRequests.request[i].active = true;
|
||||||
memcpy(FriendRequests.request[i].key, public_key, TOX_CLIENT_ID_SIZE);
|
memcpy(FrndRequests.request[i].key, public_key, TOX_CLIENT_ID_SIZE);
|
||||||
snprintf(FriendRequests.request[i].msg, sizeof(FriendRequests.request[i].msg), "%s", data);
|
snprintf(FrndRequests.request[i].msg, sizeof(FrndRequests.request[i].msg), "%s", data);
|
||||||
|
|
||||||
if (i == FriendRequests.max_idx)
|
if (i == FrndRequests.max_idx)
|
||||||
++FriendRequests.max_idx;
|
++FrndRequests.max_idx;
|
||||||
|
|
||||||
++FriendRequests.num_requests;
|
++FrndRequests.num_requests;
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@ -218,7 +218,6 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
|||||||
|
|
||||||
wclear(ctx->linewin);
|
wclear(ctx->linewin);
|
||||||
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
||||||
line_info_reset_start(self, ctx->hst);
|
|
||||||
reset_buf(ctx);
|
reset_buf(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ typedef struct {
|
|||||||
int max_idx;
|
int max_idx;
|
||||||
int num_requests;
|
int num_requests;
|
||||||
struct friend_request request[MAX_FRIEND_REQUESTS];
|
struct friend_request request[MAX_FRIEND_REQUESTS];
|
||||||
} _FriendRequests;
|
} FriendRequests;
|
||||||
|
|
||||||
ToxWindow new_prompt(void);
|
ToxWindow new_prompt(void);
|
||||||
void prep_prompt_win(void);
|
void prep_prompt_win(void);
|
||||||
|
@ -223,7 +223,7 @@ static void queue_init_message(const char *msg, ...)
|
|||||||
init_messages.msgs = new_msgs;
|
init_messages.msgs = new_msgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called after messages have been printed to console and are no longer needed */
|
/* called after messages have been printed to prompt and are no longer needed */
|
||||||
static void cleanup_init_messages(void)
|
static void cleanup_init_messages(void)
|
||||||
{
|
{
|
||||||
if (init_messages.num <= 0)
|
if (init_messages.num <= 0)
|
||||||
@ -1062,6 +1062,7 @@ int main(int argc, char *argv[])
|
|||||||
print_init_messages(prompt);
|
print_init_messages(prompt);
|
||||||
cleanup_init_messages();
|
cleanup_init_messages();
|
||||||
|
|
||||||
|
/* set user avatar from config file. if no valid path is supplied tox_unset_avatar is called */
|
||||||
char avatarstr[MAX_STR_SIZE];
|
char avatarstr[MAX_STR_SIZE];
|
||||||
snprintf(avatarstr, sizeof(avatarstr), "/avatar \"%s\"", user_settings->avatar_path);
|
snprintf(avatarstr, sizeof(avatarstr), "/avatar \"%s\"", user_settings->avatar_path);
|
||||||
execute(prompt->chatwin->history, prompt, m, avatarstr, GLOBAL_COMMAND_MODE);
|
execute(prompt->chatwin->history, prompt, m, avatarstr, GLOBAL_COMMAND_MODE);
|
||||||
|
Loading…
Reference in New Issue
Block a user