diff --git a/src/chat.c b/src/chat.c index fbd6353..f77c0e5 100644 --- a/src/chat.c +++ b/src/chat.c @@ -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); } diff --git a/src/chat_commands.c b/src/chat_commands.c index 4f3f11f..e5597e0 100644 --- a/src/chat_commands.c +++ b/src/chat_commands.c @@ -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; diff --git a/src/file_senders.c b/src/file_senders.c index eb12ae7..8dafb28 100644 --- a/src/file_senders.c +++ b/src/file_senders.c @@ -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 */ diff --git a/src/friendlist.c b/src/friendlist.c index 04f422a..4b394ef 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -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); diff --git a/src/friendlist.h b/src/friendlist.h index 3d0df12..06ef781 100644 --- a/src/friendlist.h +++ b/src/friendlist.h @@ -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); diff --git a/src/global_commands.c b/src/global_commands.c index 4a00d04..96a2d17 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -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, ""); } } diff --git a/src/groupchat.c b/src/groupchat.c index 1bab012..416a611 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -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); } } diff --git a/src/line_info.c b/src/line_info.c index 9c942cf..ef98d3d 100644 --- a/src/line_info.c +++ b/src/line_info.c @@ -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 */ diff --git a/src/prompt.c b/src/prompt.c index cb28197..7bacf80 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -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); } } diff --git a/src/prompt.h b/src/prompt.h index e006e86..2d019c3 100644 --- a/src/prompt.h +++ b/src/prompt.h @@ -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); diff --git a/src/toxic.c b/src/toxic.c index 0bba549..e6531ed 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -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);