1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 16:03:27 +01:00

bug fixes and code cleanup

This commit is contained in:
Jfreegman 2014-09-28 17:49:48 -04:00
parent a01cc35368
commit 33cfca7ecc
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
11 changed files with 54 additions and 46 deletions

View File

@ -53,7 +53,7 @@
extern char *DATA_FILE;
extern FileSender file_senders[MAX_FILES];
extern _Friends Friends;
extern FriendsList Friends;
extern struct Winthread Winthread;
extern struct user_settings *user_settings;
@ -199,7 +199,7 @@ static void chat_onConnectionChange(ToxWindow *self, Tox *m, int32_t num, uint8_
if (status == 1) { /* Friend goes online */
statusbar->is_online = true;
Friends.list[num].is_typing = user_settings->show_typing_other == SHOW_TYPING_ON
? tox_get_is_typing(m, num) : 0;
? tox_get_is_typing(m, num) : 0;
chat_resume_file_transfers(m, num);
msg = "has come online";
@ -940,7 +940,6 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
wclear(ctx->linewin);
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
line_info_reset_start(self, ctx->hst);
reset_buf(ctx);
}

View File

@ -34,7 +34,7 @@
#include "file_senders.h"
extern ToxWindow *prompt;
extern _Friends Friends;
extern FriendsList Friends;
extern FileSender file_senders[MAX_FILES];
extern uint8_t max_file_senders_index;

View File

@ -36,7 +36,7 @@
FileSender file_senders[MAX_FILES];
uint8_t max_file_senders_index;
uint8_t num_active_file_senders;
extern _Friends Friends;
extern FriendsList Friends;
/* creates initial progress line that will be updated during file transfer.
Assumes progline is of size MAX_STR_SIZE */

View File

@ -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 */
_Friends Friends;
FriendsList Friends;
static struct _Blocked {
static struct Blocked {
int num_selected;
int max_idx;
int num_blocked;
@ -64,7 +64,7 @@ static struct _Blocked {
BlockedFriend *list;
} Blocked;
static struct _pendingDel {
static struct pendingDel {
int num;
bool active;
WINDOW *popup;
@ -115,7 +115,7 @@ void kill_friendlist(void)
int 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);
}
@ -171,6 +171,7 @@ static int save_blocklist(char *path)
ret = 0;
fclose(fp);
return ret;
on_error:
free(data);

View File

@ -88,7 +88,7 @@ typedef struct {
int num_friends;
int *index;
ToxicFriend *list;
} _Friends;
} FriendsList;
ToxWindow new_friendlist(void);
void disable_chatwin(int32_t f_num);

View File

@ -37,8 +37,8 @@
extern char *DATA_FILE;
extern ToxWindow *prompt;
extern _Friends Friends;
extern _FriendRequests FriendRequests;
extern FriendsList Friends;
extern FriendRequests FrndRequests;
/* command functions */
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;
}
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.");
return;
}
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)
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);
}
memset(&FriendRequests.request[req], 0, sizeof(struct friend_request));
memset(&FrndRequests.request[req], 0, sizeof(struct friend_request));
int i;
for (i = FriendRequests.max_idx; i > 0; --i) {
if (FriendRequests.request[i - 1].active)
for (i = FrndRequests.max_idx; i > 0; --i) {
if (FrndRequests.request[i - 1].active)
break;
}
FriendRequests.max_idx = i;
--FriendRequests.num_requests;
FrndRequests.max_idx = i;
--FrndRequests.num_requests;
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 */
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;
}
@ -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)
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);
free(avatar);
}
@ -297,22 +302,22 @@ void cmd_decline(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)
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.");
return;
}
memset(&FriendRequests.request[req], 0, sizeof(struct friend_request));
memset(&FrndRequests.request[req], 0, sizeof(struct friend_request));
int i;
for (i = FriendRequests.max_idx; i > 0; --i) {
if (FriendRequests.request[i - 1].active)
for (i = FrndRequests.max_idx; i > 0; --i) {
if (FrndRequests.request[i - 1].active)
break;
}
FriendRequests.max_idx = i;
--FriendRequests.num_requests;
FrndRequests.max_idx = i;
--FrndRequests.num_requests;
}
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])
{
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.");
return;
}
@ -477,22 +482,22 @@ void cmd_requests(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
int i, j;
int count = 0;
for (i = 0; i < FriendRequests.max_idx; ++i) {
if (!FriendRequests.request[i].active)
for (i = 0; i < FrndRequests.max_idx; ++i) {
if (!FrndRequests.request[i].active)
continue;
char id[TOX_CLIENT_ID_SIZE * 2 + 1] = {0};
for (j = 0; j < TOX_CLIENT_ID_SIZE; ++j) {
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);
}
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, "");
}
}

View File

@ -430,7 +430,6 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
wclear(ctx->linewin);
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
line_info_reset_start(self, ctx->hst);
reset_buf(ctx);
}
}

View File

@ -258,6 +258,10 @@ static void line_info_check_queue(ToxWindow *self)
++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 */

View File

@ -46,7 +46,7 @@ extern ToxWindow *prompt;
extern struct user_settings *user_settings;
extern struct Winthread Winthread;
_FriendRequests FriendRequests;
FriendRequests FrndRequests;
/* Array of global command names used for tab completion. */
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. */
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;
int i;
for (i = 0; i <= FriendRequests.max_idx; ++i) {
if (!FriendRequests.request[i].active) {
FriendRequests.request[i].active = true;
memcpy(FriendRequests.request[i].key, public_key, TOX_CLIENT_ID_SIZE);
snprintf(FriendRequests.request[i].msg, sizeof(FriendRequests.request[i].msg), "%s", data);
for (i = 0; i <= FrndRequests.max_idx; ++i) {
if (!FrndRequests.request[i].active) {
FrndRequests.request[i].active = true;
memcpy(FrndRequests.request[i].key, public_key, TOX_CLIENT_ID_SIZE);
snprintf(FrndRequests.request[i].msg, sizeof(FrndRequests.request[i].msg), "%s", data);
if (i == FriendRequests.max_idx)
++FriendRequests.max_idx;
if (i == FrndRequests.max_idx)
++FrndRequests.max_idx;
++FriendRequests.num_requests;
++FrndRequests.num_requests;
return i;
}
@ -218,7 +218,6 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
wclear(ctx->linewin);
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
line_info_reset_start(self, ctx->hst);
reset_buf(ctx);
}
}

View File

@ -44,7 +44,7 @@ typedef struct {
int max_idx;
int num_requests;
struct friend_request request[MAX_FRIEND_REQUESTS];
} _FriendRequests;
} FriendRequests;
ToxWindow new_prompt(void);
void prep_prompt_win(void);

View File

@ -223,7 +223,7 @@ static void queue_init_message(const char *msg, ...)
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)
{
if (init_messages.num <= 0)
@ -1062,6 +1062,7 @@ int main(int argc, char *argv[])
print_init_messages(prompt);
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];
snprintf(avatarstr, sizeof(avatarstr), "/avatar \"%s\"", user_settings->avatar_path);
execute(prompt->chatwin->history, prompt, m, avatarstr, GLOBAL_COMMAND_MODE);