From 4e177d60b09a91df4e1f833f30a224bb8b835476 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Sat, 15 Nov 2014 15:55:45 -0500 Subject: [PATCH] group title fixes and api update --- src/chat.c | 2 +- src/global_commands.c | 11 ++++++++++- src/group_commands.c | 11 +++++++++-- src/groupchat.c | 2 +- src/misc_tools.c | 2 +- src/toxic.c | 2 +- src/windows.h | 2 +- 7 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/chat.c b/src/chat.c index 666eed7..74e988d 100644 --- a/src/chat.c +++ b/src/chat.c @@ -79,7 +79,7 @@ static const char chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = { { "/close" }, { "/connect" }, { "/exit" }, - { "/groupchat" }, + { "/group" }, { "/help" }, { "/invite" }, { "/join" }, diff --git a/src/global_commands.c b/src/global_commands.c index d063e3d..52ca34e 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -330,7 +330,16 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg return; } - uint8_t type = TOX_GROUPCHAT_TYPE_AV ? !strcasecmp(argv[1], "audio") : TOX_GROUPCHAT_TYPE_TEXT; + uint8_t type; + + if (!strcasecmp(argv[1], "audio")) + type = TOX_GROUPCHAT_TYPE_AV; + else if (!strcasecmp(argv[1], "text")) + type = TOX_GROUPCHAT_TYPE_TEXT; + else { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Valid group types are: text | audio"); + return; + } int groupnum = -1; diff --git a/src/group_commands.c b/src/group_commands.c index 12d341e..8795fde 100644 --- a/src/group_commands.c +++ b/src/group_commands.c @@ -33,8 +33,15 @@ void cmd_set_title(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg char title[MAX_STR_SIZE]; if (argc < 1) { - snprintf(title, sizeof(title), "Title is set to: %s", self->name); - line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, MAGENTA, title); + int tlen = tox_group_get_title(m, self->num, (uint8_t *) title); + + if (tlen != -1) { + title[tlen] = '\0'; + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Title is set to: %s", title); + } else { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Title is not set"); + } + return; } diff --git a/src/groupchat.c b/src/groupchat.c index d2cfc52..bf721c4 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -290,7 +290,7 @@ static void groupchat_onGroupTitleChange(ToxWindow *self, Tox *m, int groupnum, /* announce title when we join the room */ if (!timed_out(groupchats[self->num].start_time, get_unix_time(), GROUP_EVENT_WAIT)) { - line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, MAGENTA, "Title is set to: %s", title); + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Title is set to: %s", title); return; } diff --git a/src/misc_tools.c b/src/misc_tools.c index 36690b4..d89c046 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -384,7 +384,7 @@ void set_window_title(ToxWindow *self, const char *title, int len) char cpy[TOXIC_MAX_NAME_LENGTH + 1]; if (self->is_groupchat) /* keep groupnumber in title */ - snprintf(cpy, sizeof(cpy), "%d-%s", self->num, title); + snprintf(cpy, sizeof(cpy), "%d %s", self->num, title); else snprintf(cpy, sizeof(cpy), "%s", title); diff --git a/src/toxic.c b/src/toxic.c index d4c6236..359cae5 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -309,11 +309,11 @@ static Tox *init_tox(void) tox_callback_group_message(m, on_groupmessage, NULL); tox_callback_group_action(m, on_groupaction, NULL); tox_callback_group_namelist_change(m, on_group_namelistchange, NULL); + tox_callback_group_title(m, on_group_titlechange, NULL); tox_callback_file_send_request(m, on_file_sendrequest, NULL); tox_callback_file_control(m, on_file_control, NULL); tox_callback_file_data(m, on_file_data, NULL); tox_callback_read_receipt(m, on_read_receipt, NULL); - tox_callback_group_title(m, on_group_titlechange, NULL); tox_set_name(m, (uint8_t *) "Toxic User", strlen("Toxic User")); diff --git a/src/windows.h b/src/windows.h index 02da7c1..a6a92c0 100644 --- a/src/windows.h +++ b/src/windows.h @@ -37,7 +37,7 @@ #include "toxic.h" #define MAX_WINDOWS_NUM 32 -#define MAX_WINDOW_NAME_LENGTH 20 +#define MAX_WINDOW_NAME_LENGTH 22 #define CURS_Y_OFFSET 1 /* y-axis cursor offset for chat contexts */ #define CHATBOX_HEIGHT 2