1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 16:43:02 +01:00

Sync with master branch

This commit is contained in:
jfreegman 2020-12-06 12:54:14 -05:00
parent 4aca8b6ecb
commit 2c51afd9ef
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
6 changed files with 153 additions and 212 deletions

View File

@ -793,8 +793,8 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, uint32_t friendnumber, c
box_silent_notify(self, NT_WNDALERT_2 | NT_NOFOCUS, &self->active_box, name, "invites you to join group chat"); box_silent_notify(self, NT_WNDALERT_2 | NT_NOFOCUS, &self->active_box, name, "invites you to join group chat");
} }
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s has invited you to join group chat \"%s\"", name, group_name); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "%s has invited you to join group chat \"%s\"", name, group_name);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0,
"Type \"/gaccept <password>\" to join the chat (password is optional)."); "Type \"/gaccept <password>\" to join the chat (password is optional).");
} }

View File

@ -182,12 +182,12 @@ void cmd_conference_join(WINDOW *window, ToxWindow *self, Tox *m, int argc, char
void cmd_group_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_group_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (get_num_active_windows() >= MAX_WINDOWS_NUM) { if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Warning: Too many windows are open."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * Warning: Too many windows are open.");
return; return;
} }
if (Friends.list[self->num].group_invite.length == 0) { if (Friends.list[self->num].group_invite.length == 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending group invite"); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "No pending group invite");
return; return;
} }
@ -211,16 +211,16 @@ void cmd_group_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*
if (err != TOX_ERR_GROUP_INVITE_ACCEPT_OK) { if (err != TOX_ERR_GROUP_INVITE_ACCEPT_OK) {
if (err == TOX_ERR_GROUP_INVITE_ACCEPT_TOO_LONG) { if (err == TOX_ERR_GROUP_INVITE_ACCEPT_TOO_LONG) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to join group: Password too long."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to join group: Password too long.");
} else { } else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to join group (error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to join group (error %d).", err);
} }
return; return;
} }
if (init_groupchat_win(m, groupnumber, NULL, 0, Group_Join_Type_Join) == -1) { if (init_groupchat_win(m, groupnumber, NULL, 0, Group_Join_Type_Join) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize.");
tox_group_leave(m, groupnumber, NULL, 0, NULL); tox_group_leave(m, groupnumber, NULL, 0, NULL);
return; return;
} }
@ -229,25 +229,25 @@ void cmd_group_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*
void cmd_group_invite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_group_invite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 1) { if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group number required."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Group number required.");
return; return;
} }
int groupnumber = atoi(argv[1]); int groupnumber = atoi(argv[1]);
if (groupnumber == 0 && strcmp(argv[1], "0")) { /* atoi returns 0 value on invalid input */ if (groupnumber == 0 && strcmp(argv[1], "0")) { /* atoi returns 0 value on invalid input */
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid group number."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid group number.");
return; return;
} }
TOX_ERR_GROUP_INVITE_FRIEND err; TOX_ERR_GROUP_INVITE_FRIEND err;
if (!tox_group_invite_friend(m, groupnumber, self->num, &err)) { if (!tox_group_invite_friend(m, groupnumber, self->num, &err)) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to invite contact to group (error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to invite contact to group (error %d).", err);
return; return;
} }
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invited contact to Group %d.", groupnumber); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invited contact to Group %d.", groupnumber);
} }
#ifdef GAMES #ifdef GAMES

View File

@ -536,19 +536,19 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
void cmd_join(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_join(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (get_num_active_windows() >= MAX_WINDOWS_NUM) { if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Warning: Too many windows are open."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * Warning: Too many windows are open.");
return; return;
} }
if (argc < 1) { if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Chat ID is required."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Chat ID is required.");
return; return;
} }
const char *chat_id = argv[1]; const char *chat_id = argv[1];
if (strlen(chat_id) != TOX_GROUP_CHAT_ID_SIZE * 2) { if (strlen(chat_id) != TOX_GROUP_CHAT_ID_SIZE * 2) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid chat ID"); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid chat ID");
return; return;
} }
@ -564,7 +564,7 @@ void cmd_join(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
xch[2] = '\0'; xch[2] = '\0';
if (sscanf(xch, "%02x", &x) != 1) { if (sscanf(xch, "%02x", &x) != 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid chat ID."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid chat ID.");
return; return;
} }
@ -590,9 +590,9 @@ void cmd_join(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
if (err != TOX_ERR_GROUP_JOIN_OK) { if (err != TOX_ERR_GROUP_JOIN_OK) {
if (err == TOX_ERR_GROUP_JOIN_TOO_LONG) { if (err == TOX_ERR_GROUP_JOIN_TOO_LONG) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Password length cannot exceed %d.", TOX_GROUP_MAX_PASSWORD_SIZE); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Password length cannot exceed %d.", TOX_GROUP_MAX_PASSWORD_SIZE);
} else { } else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to join group (error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to join group (error %d).", err);
} }
return; return;
@ -601,7 +601,7 @@ void cmd_join(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
int init = init_groupchat_win(m, groupnumber, NULL, 0, Group_Join_Type_Join); int init = init_groupchat_win(m, groupnumber, NULL, 0, Group_Join_Type_Join);
if (init == -1) { if (init == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize.");
tox_group_leave(m, groupnumber, NULL, 0, NULL); tox_group_leave(m, groupnumber, NULL, 0, NULL);
} }
} }

View File

@ -40,7 +40,7 @@ void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
TOX_ERR_GROUP_STATE_QUERIES err; TOX_ERR_GROUP_STATE_QUERIES err;
if (!tox_group_get_chat_id(m, self->num, (uint8_t *) chat_public_key, &err)) { if (!tox_group_get_chat_id(m, self->num, (uint8_t *) chat_public_key, &err)) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve the Chat ID (error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve the Chat ID (error %d).", err);
return; return;
} }
@ -52,7 +52,7 @@ void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
strcat(chatid, xx); strcat(chatid, xx);
} }
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", chatid); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "%s", chatid);
} }
void cmd_disconnect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_disconnect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
@ -62,17 +62,17 @@ void cmd_disconnect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
switch (err) { switch (err) {
case TOX_ERR_GROUP_DISCONNECT_OK: { case TOX_ERR_GROUP_DISCONNECT_OK: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Disconnected from group. Type '/rejoin' to reconnect."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Disconnected from group. Type '/rejoin' to reconnect.");
return; return;
} }
case TOX_ERR_GROUP_DISCONNECT_ALREADY_DISCONNECTED: { case TOX_ERR_GROUP_DISCONNECT_ALREADY_DISCONNECTED: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Already disconnected. Type '/rejoin' to connect."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Already disconnected. Type '/rejoin' to connect.");
return; return;
} }
default: { default: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to disconnect from group. Error: %d", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to disconnect from group. Error: %d", err);
return; return;
} }
} }
@ -81,7 +81,7 @@ void cmd_disconnect(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 1) { if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified.");
return; return;
} }
@ -89,7 +89,7 @@ void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
uint32_t peer_id; uint32_t peer_id;
if (group_get_nick_peer_id(self->num, nick, &peer_id) == -1) { if (group_get_nick_peer_id(self->num, nick, &peer_id) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
return; return;
} }
@ -102,26 +102,23 @@ void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
} }
case TOX_ERR_GROUP_TOGGLE_IGNORE_SELF: { case TOX_ERR_GROUP_TOGGLE_IGNORE_SELF: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You cannot ignore yourself."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You cannot ignore yourself.");
return; return;
} }
default: { default: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to toggle ignore on %s (error %d).", nick, err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to toggle ignore on %s (error %d).", nick, err);
return; return;
} }
} }
char timefrmt[TIME_STR_SIZE]; line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE, "-!- Ignoring %s", nick);
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- Ignoring %s", nick);
} }
void cmd_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 1) { if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified.");
return; return;
} }
@ -130,7 +127,7 @@ void cmd_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
uint32_t target_peer_id; uint32_t target_peer_id;
if (group_get_nick_peer_id(self->num, nick, &target_peer_id) == -1) { if (group_get_nick_peer_id(self->num, nick, &target_peer_id) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
return; return;
} }
@ -142,25 +139,23 @@ void cmd_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
char self_nick[TOX_MAX_NAME_LENGTH + 1]; char self_nick[TOX_MAX_NAME_LENGTH + 1];
get_group_self_nick_truncate(m, self_nick, self->num); get_group_self_nick_truncate(m, self_nick, self->num);
char timefrmt[TIME_STR_SIZE]; line_info_add(self, true, NULL, NULL, SYS_MSG, 1, RED, "-!- %s has been kicked by %s", nick, self_nick);
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, RED, "-!- %s has been kicked by %s", nick, self_nick);
groupchat_onGroupPeerExit(self, m, self->num, target_peer_id, TOX_GROUP_EXIT_TYPE_KICK, nick, strlen(nick), NULL, 0); groupchat_onGroupPeerExit(self, m, self->num, target_peer_id, TOX_GROUP_EXIT_TYPE_KICK, nick, strlen(nick), NULL, 0);
return; return;
} }
case TOX_ERR_GROUP_MOD_KICK_PEER_PERMISSIONS: { case TOX_ERR_GROUP_MOD_KICK_PEER_PERMISSIONS: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to kick %s.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to kick %s.", nick);
return; return;
} }
case TOX_ERR_GROUP_MOD_KICK_PEER_SELF: { case TOX_ERR_GROUP_MOD_KICK_PEER_SELF: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You cannot kick yourself."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You cannot kick yourself.");
return; return;
} }
default: { default: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to kick %s from the group (error %d).", nick, line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to kick %s from the group (error %d).", nick,
err); err);
return; return;
} }
@ -170,7 +165,7 @@ void cmd_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
void cmd_mod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_mod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 1) { if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified.");
return; return;
} }
@ -178,7 +173,7 @@ void cmd_mod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
uint32_t target_peer_id; uint32_t target_peer_id;
if (group_get_nick_peer_id(self->num, nick, &target_peer_id) == -1) { if (group_get_nick_peer_id(self->num, nick, &target_peer_id) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
return; return;
} }
@ -186,7 +181,7 @@ void cmd_mod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
uint32_t self_peer_id = tox_group_self_get_peer_id(m, self->num, &s_err); uint32_t self_peer_id = tox_group_self_get_peer_id(m, self->num, &s_err);
if (s_err != TOX_ERR_GROUP_SELF_QUERY_OK) { if (s_err != TOX_ERR_GROUP_SELF_QUERY_OK) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch self peer_id."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch self peer_id.");
return; return;
} }
@ -200,22 +195,22 @@ void cmd_mod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
} }
case TOX_ERR_GROUP_MOD_SET_ROLE_PERMISSIONS: { case TOX_ERR_GROUP_MOD_SET_ROLE_PERMISSIONS: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to promote moderators."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to promote moderators.");
return; return;
} }
case TOX_ERR_GROUP_MOD_SET_ROLE_ASSIGNMENT: { case TOX_ERR_GROUP_MOD_SET_ROLE_ASSIGNMENT: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s is already a moderator.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "%s is already a moderator.", nick);
return; return;
} }
case TOX_ERR_GROUP_MOD_SET_ROLE_SELF: { case TOX_ERR_GROUP_MOD_SET_ROLE_SELF: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You cannot make yourself a moderator."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You cannot make yourself a moderator.");
return; return;
} }
default: { default: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to promote peer to moderator (error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to promote peer to moderator (error %d).", err);
return; return;
} }
} }
@ -224,7 +219,7 @@ void cmd_mod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
void cmd_unmod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_unmod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 1) { if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified.");
return; return;
} }
@ -232,7 +227,7 @@ void cmd_unmod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
uint32_t target_peer_id; uint32_t target_peer_id;
if (group_get_nick_peer_id(self->num, nick, &target_peer_id) == -1) { if (group_get_nick_peer_id(self->num, nick, &target_peer_id) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
return; return;
} }
@ -240,12 +235,12 @@ void cmd_unmod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
uint32_t self_peer_id = tox_group_self_get_peer_id(m, self->num, &s_err); uint32_t self_peer_id = tox_group_self_get_peer_id(m, self->num, &s_err);
if (s_err != TOX_ERR_GROUP_SELF_QUERY_OK) { if (s_err != TOX_ERR_GROUP_SELF_QUERY_OK) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch self peer_id."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch self peer_id.");
return; return;
} }
if (tox_group_peer_get_role(m, self->num, target_peer_id, NULL) != TOX_GROUP_ROLE_MODERATOR) { if (tox_group_peer_get_role(m, self->num, target_peer_id, NULL) != TOX_GROUP_ROLE_MODERATOR) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s is not a moderator.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "%s is not a moderator.", nick);
return; return;
} }
@ -259,17 +254,17 @@ void cmd_unmod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
} }
case TOX_ERR_GROUP_MOD_SET_ROLE_PERMISSIONS: { case TOX_ERR_GROUP_MOD_SET_ROLE_PERMISSIONS: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to unmod %s.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to unmod %s.", nick);
return; return;
} }
case TOX_ERR_GROUP_MOD_SET_ROLE_SELF: { case TOX_ERR_GROUP_MOD_SET_ROLE_SELF: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You cannot remove your own moderator status."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You cannot remove your own moderator status.");
return; return;
} }
default: { default: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to revoke moderator powers from %s (error %d).", nick, line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to revoke moderator powers from %s (error %d).", nick,
err); err);
return; return;
} }
@ -284,7 +279,7 @@ void cmd_mykey(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
TOX_ERR_GROUP_SELF_QUERY err; TOX_ERR_GROUP_SELF_QUERY err;
if (!tox_group_self_get_public_key(m, self->num, (uint8_t *) pk, &err)) { if (!tox_group_self_get_public_key(m, self->num, (uint8_t *) pk, &err)) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch your public key (error %d)", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch your public key (error %d)", err);
return; return;
} }
@ -296,7 +291,7 @@ void cmd_mykey(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
strcat(pk_string, d); strcat(pk_string, d);
} }
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", pk_string); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "%s", pk_string);
} }
void cmd_set_passwd(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_set_passwd(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
@ -315,27 +310,27 @@ void cmd_set_passwd(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
switch (err) { switch (err) {
case TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK: { case TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK: {
if (len > 0) { if (len > 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Password has been set to %s.", passwd); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Password has been set to %s.", passwd);
} else { } else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Password has been unset."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Password has been unset.");
} }
return; return;
} }
case TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_TOO_LONG: { case TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_TOO_LONG: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Password length must not exceed %d.", line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Password length must not exceed %d.",
TOX_GROUP_MAX_PASSWORD_SIZE); TOX_GROUP_MAX_PASSWORD_SIZE);
return; return;
} }
case TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_PERMISSIONS: { case TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_PERMISSIONS: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to set the password."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to set the password.");
return; return;
} }
default: { default: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set password (error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to set password (error %d).", err);
return; return;
} }
} }
@ -350,18 +345,18 @@ void cmd_set_peerlimit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (
uint32_t maxpeers = tox_group_get_peer_limit(m, self->num, &err); uint32_t maxpeers = tox_group_get_peer_limit(m, self->num, &err);
if (err != TOX_ERR_GROUP_STATE_QUERIES_OK) { if (err != TOX_ERR_GROUP_STATE_QUERIES_OK) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve peer limit (error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve peer limit (error %d).", err);
return; return;
} }
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer limit is set to %d", maxpeers); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Peer limit is set to %d", maxpeers);
return; return;
} }
maxpeers = atoi(argv[1]); maxpeers = atoi(argv[1]);
if (maxpeers <= 0) { if (maxpeers <= 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer limit must be a value greater than 0."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Peer limit must be a value greater than 0.");
return; return;
} }
@ -370,17 +365,17 @@ void cmd_set_peerlimit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (
switch (err) { switch (err) {
case TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK: { case TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer limit has been set to %d.", maxpeers); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Peer limit has been set to %d.", maxpeers);
return; return;
} }
case TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_PERMISSIONS: { case TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_PERMISSIONS: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to set the peer limit."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to set the peer limit.");
return; return;
} }
default: { default: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set the peer limit (error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to set the peer limit (error %d).", err);
return; return;
} }
} }
@ -396,19 +391,19 @@ void cmd_set_privacy(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
privacy_state = tox_group_get_privacy_state(m, self->num, &err); privacy_state = tox_group_get_privacy_state(m, self->num, &err);
if (err != TOX_ERR_GROUP_STATE_QUERIES_OK) { if (err != TOX_ERR_GROUP_STATE_QUERIES_OK) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve privacy state (error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve privacy state (error %d).", err);
return; return;
} }
pstate_str = privacy_state == TOX_GROUP_PRIVACY_STATE_PRIVATE ? "private" : "public"; pstate_str = privacy_state == TOX_GROUP_PRIVACY_STATE_PRIVATE ? "private" : "public";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Privacy state is set to %s.", pstate_str); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Privacy state is set to %s.", pstate_str);
return; return;
} }
pstate_str = argv[1]; pstate_str = argv[1];
if (strcasecmp(pstate_str, "private") != 0 && strcasecmp(pstate_str, "public") != 0) { if (strcasecmp(pstate_str, "private") != 0 && strcasecmp(pstate_str, "public") != 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Privacy state must be \"private\" or \"public\"."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Privacy state must be \"private\" or \"public\".");
return; return;
} }
@ -420,17 +415,17 @@ void cmd_set_privacy(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
switch (err) { switch (err) {
case TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK: { case TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Privacy state has been set to %s.", pstate_str); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Privacy state has been set to %s.", pstate_str);
return; return;
} }
case TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_PERMISSIONS: { case TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_PERMISSIONS: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to set the privacy state."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to set the privacy state.");
return; return;
} }
default: { default: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error setting privacy state (error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Error setting privacy state (error %d).", err);
return; return;
} }
} }
@ -439,7 +434,7 @@ void cmd_set_privacy(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
void cmd_silence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_silence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 1) { if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified.");
return; return;
} }
@ -447,7 +442,7 @@ void cmd_silence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)
uint32_t target_peer_id; uint32_t target_peer_id;
if (group_get_nick_peer_id(self->num, nick, &target_peer_id) == -1) { if (group_get_nick_peer_id(self->num, nick, &target_peer_id) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
return; return;
} }
@ -455,7 +450,7 @@ void cmd_silence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)
uint32_t self_peer_id = tox_group_self_get_peer_id(m, self->num, &s_err); uint32_t self_peer_id = tox_group_self_get_peer_id(m, self->num, &s_err);
if (s_err != TOX_ERR_GROUP_SELF_QUERY_OK) { if (s_err != TOX_ERR_GROUP_SELF_QUERY_OK) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch self peer_id."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch self peer_id.");
return; return;
} }
@ -469,22 +464,22 @@ void cmd_silence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)
} }
case TOX_ERR_GROUP_MOD_SET_ROLE_PERMISSIONS: { case TOX_ERR_GROUP_MOD_SET_ROLE_PERMISSIONS: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to silence %s.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to silence %s.", nick);
return; return;
} }
case TOX_ERR_GROUP_MOD_SET_ROLE_ASSIGNMENT: { case TOX_ERR_GROUP_MOD_SET_ROLE_ASSIGNMENT: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s is already silenced.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "%s is already silenced.", nick);
return; return;
} }
case TOX_ERR_GROUP_MOD_SET_ROLE_SELF: { case TOX_ERR_GROUP_MOD_SET_ROLE_SELF: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You cannot silence yourself."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You cannot silence yourself.");
return; return;
} }
default: { default: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to silence %s (error %d).", nick, err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to silence %s (error %d).", nick, err);
return; return;
} }
} }
@ -493,7 +488,7 @@ void cmd_silence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)
void cmd_unsilence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_unsilence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 1) { if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified.");
return; return;
} }
@ -501,12 +496,12 @@ void cmd_unsilence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
uint32_t target_peer_id; uint32_t target_peer_id;
if (group_get_nick_peer_id(self->num, nick, &target_peer_id) == -1) { if (group_get_nick_peer_id(self->num, nick, &target_peer_id) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
return; return;
} }
if (tox_group_peer_get_role(m, self->num, target_peer_id, NULL) != TOX_GROUP_ROLE_OBSERVER) { if (tox_group_peer_get_role(m, self->num, target_peer_id, NULL) != TOX_GROUP_ROLE_OBSERVER) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s is not silenced.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "%s is not silenced.", nick);
return; return;
} }
@ -514,7 +509,7 @@ void cmd_unsilence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
uint32_t self_peer_id = tox_group_self_get_peer_id(m, self->num, &s_err); uint32_t self_peer_id = tox_group_self_get_peer_id(m, self->num, &s_err);
if (s_err != TOX_ERR_GROUP_SELF_QUERY_OK) { if (s_err != TOX_ERR_GROUP_SELF_QUERY_OK) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch self peer_id."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch self peer_id.");
return; return;
} }
@ -528,22 +523,22 @@ void cmd_unsilence(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
} }
case TOX_ERR_GROUP_MOD_SET_ROLE_PERMISSIONS: { case TOX_ERR_GROUP_MOD_SET_ROLE_PERMISSIONS: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to unsilence %s.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to unsilence %s.", nick);
return; return;
} }
case TOX_ERR_GROUP_MOD_SET_ROLE_ASSIGNMENT: { case TOX_ERR_GROUP_MOD_SET_ROLE_ASSIGNMENT: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s is not silenced.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "%s is not silenced.", nick);
return; return;
} }
case TOX_ERR_GROUP_MOD_SET_ROLE_SELF: { case TOX_ERR_GROUP_MOD_SET_ROLE_SELF: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You cannot unsilence yourself."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You cannot unsilence yourself.");
return; return;
} }
default: { default: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to unsilence %s (error %d).", nick, err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to unsilence %s (error %d).", nick, err);
return; return;
} }
} }
@ -554,11 +549,11 @@ void cmd_rejoin(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
TOX_ERR_GROUP_RECONNECT err; TOX_ERR_GROUP_RECONNECT err;
if (!tox_group_reconnect(m, self->num, &err)) { if (!tox_group_reconnect(m, self->num, &err)) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to rejoin group (error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to rejoin group (error %d).", err);
return; return;
} }
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Reconnecting to group..."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Reconnecting to group...");
groupchat_rejoin(self, m); groupchat_rejoin(self, m);
} }
@ -570,7 +565,7 @@ void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
size_t tlen = tox_group_get_topic_size(m, self->num, &err); size_t tlen = tox_group_get_topic_size(m, self->num, &err);
if (err != TOX_ERR_GROUP_STATE_QUERIES_OK) { if (err != TOX_ERR_GROUP_STATE_QUERIES_OK) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve topic length (error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve topic length (error %d).", err);
return; return;
} }
@ -578,14 +573,14 @@ void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
char cur_topic[TOX_GROUP_MAX_TOPIC_LENGTH + 1]; char cur_topic[TOX_GROUP_MAX_TOPIC_LENGTH + 1];
if (!tox_group_get_topic(m, self->num, (uint8_t *) cur_topic, &err)) { if (!tox_group_get_topic(m, self->num, (uint8_t *) cur_topic, &err)) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve topic (error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve topic (error %d).", err);
return; return;
} }
cur_topic[tlen] = 0; cur_topic[tlen] = 0;
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Topic is set to: %s", cur_topic); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Topic is set to: %s", cur_topic);
} else { } else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Topic is not set."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Topic is not set.");
} }
return; return;
@ -603,28 +598,25 @@ void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
} }
case TOX_ERR_GROUP_TOPIC_SET_TOO_LONG: { case TOX_ERR_GROUP_TOPIC_SET_TOO_LONG: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Topic length must not exceed %d.", TOX_GROUP_MAX_TOPIC_LENGTH); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Topic length must not exceed %d.", TOX_GROUP_MAX_TOPIC_LENGTH);
return; return;
} }
case TOX_ERR_GROUP_TOPIC_SET_PERMISSIONS: { case TOX_ERR_GROUP_TOPIC_SET_PERMISSIONS: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to set the topic."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to set the topic.");
return; return;
} }
default: { default: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set the topic (error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to set the topic (error %d).", err);
return; return;
} }
} }
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
char self_nick[TOX_MAX_NAME_LENGTH + 1]; char self_nick[TOX_MAX_NAME_LENGTH + 1];
get_group_self_nick_truncate(m, self_nick, self->num); get_group_self_nick_truncate(m, self_nick, self->num);
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, MAGENTA, "-!- You set the topic to: %s", topic); line_info_add(self, true, NULL, NULL, SYS_MSG, 1, MAGENTA, "-!- You set the topic to: %s", topic);
char tmp_event[MAX_STR_SIZE]; char tmp_event[MAX_STR_SIZE];
snprintf(tmp_event, sizeof(tmp_event), "set topic to %s", topic); snprintf(tmp_event, sizeof(tmp_event), "set topic to %s", topic);
@ -634,7 +626,7 @@ void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
void cmd_unignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_unignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 1) { if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer must be specified."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Peer must be specified.");
return; return;
} }
@ -642,7 +634,7 @@ void cmd_unignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
uint32_t peer_id; uint32_t peer_id;
if (group_get_nick_peer_id(self->num, nick, &peer_id) == -1) { if (group_get_nick_peer_id(self->num, nick, &peer_id) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
return; return;
} }
@ -655,33 +647,30 @@ void cmd_unignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
} }
case TOX_ERR_GROUP_TOGGLE_IGNORE_SELF: { case TOX_ERR_GROUP_TOGGLE_IGNORE_SELF: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You cannot unignore yourself."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "You cannot unignore yourself.");
return; return;
} }
default: { default: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to toggle ignore on %s (error %d).", nick, err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to toggle ignore on %s (error %d).", nick, err);
return; return;
} }
} }
char timefrmt[TIME_STR_SIZE]; line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE, "-!- You are no longer ignoring %s", nick);
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- You are no longer ignoring %s", nick);
} }
void cmd_whois(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_whois(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 1) { if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer must be specified."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Peer must be specified.");
return; return;
} }
GroupChat *chat = get_groupchat(self->num); GroupChat *chat = get_groupchat(self->num);
if (!chat) { if (!chat) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch GroupChat object."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch GroupChat object.");
return; return;
} }
@ -689,14 +678,14 @@ void cmd_whois(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
uint32_t peer_id; uint32_t peer_id;
if (group_get_nick_peer_id(self->num, nick, &peer_id) == -1) { if (group_get_nick_peer_id(self->num, nick, &peer_id) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name '%s'.", nick);
return; return;
} }
int peer_index = get_peer_index(self->num, peer_id); int peer_index = get_peer_index(self->num, peer_id);
if (peer_index < 0) { if (peer_index < 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch peer index."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch peer index.");
return; return;
} }
@ -731,9 +720,9 @@ void cmd_whois(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
strcat(pk_string, d); strcat(pk_string, d);
} }
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Whois for %s", nick); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Whois for %s", nick);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Role: %s", role_str); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Role: %s", role_str);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Status: %s", status_str); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Status: %s", status_str);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Last active: %s", last_seen_str); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Last active: %s", last_seen_str);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Public key: %s", pk_string); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Public key: %s", pk_string);
} }

View File

@ -191,7 +191,7 @@ void groupchat_rejoin(ToxWindow *self, Tox *m)
GroupChat *chat = get_groupchat(self->num); GroupChat *chat = get_groupchat(self->num);
if (!chat) { if (!chat) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch GroupChat object."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch GroupChat object.");
return; return;
} }
@ -199,7 +199,7 @@ void groupchat_rejoin(ToxWindow *self, Tox *m)
uint32_t self_peer_id = tox_group_self_get_peer_id(m, self->num, &s_err); uint32_t self_peer_id = tox_group_self_get_peer_id(m, self->num, &s_err);
if (s_err != TOX_ERR_GROUP_SELF_QUERY_OK) { if (s_err != TOX_ERR_GROUP_SELF_QUERY_OK) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch self peer_id in groupchat_rejoin()"); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch self peer_id in groupchat_rejoin()");
return; return;
} }
@ -292,22 +292,22 @@ static void init_groupchat_log(ToxWindow *self, Tox *m, uint32_t groupnumber)
TOX_ERR_GROUP_STATE_QUERIES err; TOX_ERR_GROUP_STATE_QUERIES err;
if (!tox_group_get_chat_id(m, groupnumber, (uint8_t *)chat_id, &err)) { if (!tox_group_get_chat_id(m, groupnumber, (uint8_t *)chat_id, &err)) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch chat id. Logging disabled. (error: %d)", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch chat id. Logging disabled. (error: %d)", err);
return; return;
} }
if (log_init(ctx->log, chat->group_name, my_id, chat_id, LOG_TYPE_CHAT) != 0) { if (log_init(ctx->log, chat->group_name, my_id, chat_id, LOG_TYPE_CHAT) != 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Warning: Log failed to initialize."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Warning: Log failed to initialize.");
return; return;
} }
if (load_chat_history(self, ctx->log) != 0) { if (load_chat_history(self, ctx->log) != 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to load chat history."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to load chat history.");
} }
if (user_settings->autolog == AUTOLOG_ON) { if (user_settings->autolog == AUTOLOG_ON) {
if (log_enable(ctx->log) != 0) { if (log_enable(ctx->log) != 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to enable chat log."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to enable chat log.");
} }
} }
@ -363,9 +363,6 @@ int init_groupchat_win(Tox *m, uint32_t groupnumber, const char *groupname, size
void set_nick_all_groups(Tox *m, const char *new_nick, size_t length) void set_nick_all_groups(Tox *m, const char *new_nick, size_t length)
{ {
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
for (int i = 0; i < max_groupchat_index; ++i) { for (int i = 0; i < max_groupchat_index; ++i) {
if (groupchats[i].active) { if (groupchats[i].active) {
ToxWindow *self = get_window_ptr(groupchats[i].chatwin); ToxWindow *self = get_window_ptr(groupchats[i].chatwin);
@ -387,13 +384,13 @@ void set_nick_all_groups(Tox *m, const char *new_nick, size_t length)
} }
case TOX_ERR_GROUP_SELF_NAME_SET_TAKEN: { case TOX_ERR_GROUP_SELF_NAME_SET_TAKEN: {
line_info_add(self, NULL, NULL, 0, SYS_MSG, 0, RED, "-!- That nick is already in use."); line_info_add(self, false, NULL, 0, SYS_MSG, 0, RED, "-!- That nick is already in use.");
break; break;
} }
default: { default: {
if (groupchats[i].time_connected > 0) { if (groupchats[i].time_connected > 0) {
line_info_add(self, NULL, NULL, 0, SYS_MSG, 0, RED, "-!- Failed to set nick (error %d).", err); line_info_add(self, false, NULL, 0, SYS_MSG, 0, RED, "-!- Failed to set nick (error %d).", err);
} }
break; break;
@ -417,7 +414,7 @@ void set_status_all_groups(Tox *m, uint8_t status)
uint32_t self_peer_id = tox_group_self_get_peer_id(m, self->num, &s_err); uint32_t self_peer_id = tox_group_self_get_peer_id(m, self->num, &s_err);
if (s_err != TOX_ERR_GROUP_SELF_QUERY_OK) { if (s_err != TOX_ERR_GROUP_SELF_QUERY_OK) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch self peer_id."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch self peer_id.");
continue; continue;
} }
@ -625,10 +622,7 @@ static void group_onAction(ToxWindow *self, Tox *m, uint32_t groupnumber, uint32
sound_notify(self, silent, NT_WNDALERT_1, NULL); sound_notify(self, silent, NT_WNDALERT_1, NULL);
} }
char timefrmt[TIME_STR_SIZE]; line_info_add(self, true, nick, NULL, IN_ACTION, 0, 0, "%s", action);
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, IN_ACTION, 0, 0, "%s", action);
write_to_log(action, nick, ctx->log, true); write_to_log(action, nick, ctx->log, true);
} }
@ -671,10 +665,7 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, uint32_t groupnumb
sound_notify(self, silent, NT_WNDALERT_1, NULL); sound_notify(self, silent, NT_WNDALERT_1, NULL);
} }
char timefrmt[TIME_STR_SIZE]; line_info_add(self, true, nick, NULL, IN_MSG, 0, nick_clr, "%s", msg);
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, IN_MSG, 0, nick_clr, "%s", msg);
write_to_log(msg, nick, ctx->log, false); write_to_log(msg, nick, ctx->log, false);
} }
@ -692,10 +683,7 @@ static void groupchat_onGroupPrivateMessage(ToxWindow *self, Tox *m, uint32_t gr
char nick[TOX_MAX_NAME_LENGTH + 1]; char nick[TOX_MAX_NAME_LENGTH + 1];
get_group_nick_truncate(m, nick, peer_id, groupnumber); get_group_nick_truncate(m, nick, peer_id, groupnumber);
char timefrmt[TIME_STR_SIZE]; line_info_add(self, true, nick, NULL, IN_PRVT_MSG, 0, MAGENTA, "%s", msg);
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, IN_PRVT_MSG, 0, MAGENTA, "%s", msg);
write_to_log(msg, nick, ctx->log, false); write_to_log(msg, nick, ctx->log, false);
if (self->active_box != -1) { if (self->active_box != -1) {
@ -718,12 +706,9 @@ static void groupchat_onGroupTopicChange(ToxWindow *self, Tox *m, uint32_t group
groupchat_update_last_seen(groupnumber, peer_id); groupchat_update_last_seen(groupnumber, peer_id);
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
char nick[TOX_MAX_NAME_LENGTH + 1]; char nick[TOX_MAX_NAME_LENGTH + 1];
get_group_nick_truncate(m, nick, peer_id, groupnumber); get_group_nick_truncate(m, nick, peer_id, groupnumber);
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, MAGENTA, "-!- %s set the topic to: %s", nick, topic); line_info_add(self, true, NULL, NULL, SYS_MSG, 1, MAGENTA, "-!- %s set the topic to: %s", nick, topic);
char tmp_event[MAX_STR_SIZE]; char tmp_event[MAX_STR_SIZE];
snprintf(tmp_event, sizeof(tmp_event), " set the topic to %s", topic); snprintf(tmp_event, sizeof(tmp_event), " set the topic to %s", topic);
@ -738,10 +723,7 @@ static void groupchat_onGroupPeerLimit(ToxWindow *self, Tox *m, uint32_t groupnu
return; return;
} }
char timefrmt[TIME_STR_SIZE]; line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE, "-!- The group founder has set the peer limit to %d",
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- The group founder has set the peer limit to %d",
peer_limit); peer_limit);
char tmp_event[MAX_STR_SIZE]; char tmp_event[MAX_STR_SIZE];
@ -759,10 +741,7 @@ static void groupchat_onGroupPrivacyState(ToxWindow *self, Tox *m, uint32_t grou
const char *state_str = state == TOX_GROUP_PRIVACY_STATE_PUBLIC ? "public" : "private"; const char *state_str = state == TOX_GROUP_PRIVACY_STATE_PUBLIC ? "public" : "private";
char timefrmt[TIME_STR_SIZE]; line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE, "-!- The group founder has set the group to %s.",
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- The group founder has set the group to %s.",
state_str); state_str);
char tmp_event[MAX_STR_SIZE]; char tmp_event[MAX_STR_SIZE];
@ -779,17 +758,14 @@ static void groupchat_onGroupPassword(ToxWindow *self, Tox *m, uint32_t groupnum
return; return;
} }
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
if (length > 0) { if (length > 0) {
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- The group founder has password protected the group."); line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE, "-!- The group founder has password protected the group.");
char tmp_event[MAX_STR_SIZE]; char tmp_event[MAX_STR_SIZE];
snprintf(tmp_event, sizeof(tmp_event), " set a new password."); snprintf(tmp_event, sizeof(tmp_event), " set a new password.");
write_to_log(tmp_event, "The founder", ctx->log, true); write_to_log(tmp_event, "The founder", ctx->log, true);
} else { } else {
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- The group founder has removed password protection."); line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE, "-!- The group founder has removed password protection.");
char tmp_event[MAX_STR_SIZE]; char tmp_event[MAX_STR_SIZE];
snprintf(tmp_event, sizeof(tmp_event), " removed password protection."); snprintf(tmp_event, sizeof(tmp_event), " removed password protection.");
@ -866,10 +842,7 @@ static void groupchat_onGroupPeerJoin(ToxWindow *self, Tox *m, uint32_t groupnum
} }
if (timed_out(chat->time_connected, 7)) { /* ignore join messages when we first connect to the group */ if (timed_out(chat->time_connected, 7)) { /* ignore join messages when we first connect to the group */
char timefrmt[TIME_STR_SIZE]; line_info_add(self, true, chat->peer_list[i].name, NULL, CONNECTION, 0, GREEN, "has joined the room");
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, chat->peer_list[i].name, NULL, CONNECTION, 0, GREEN, "has joined the room");
write_to_log("has joined the room", chat->peer_list[i].name, self->chatwin->log, true); write_to_log("has joined the room", chat->peer_list[i].name, self->chatwin->log, true);
sound_notify(self, silent, NT_WNDALERT_2, NULL); sound_notify(self, silent, NT_WNDALERT_2, NULL);
@ -898,18 +871,15 @@ void groupchat_onGroupPeerExit(ToxWindow *self, Tox *m, uint32_t groupnumber, ui
return; return;
} }
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
if (exit_type != TOX_GROUP_EXIT_TYPE_SELF_DISCONNECTED) { if (exit_type != TOX_GROUP_EXIT_TYPE_SELF_DISCONNECTED) {
char log_str[TOX_MAX_NAME_LENGTH + MAX_STR_SIZE]; char log_str[TOX_MAX_NAME_LENGTH + MAX_STR_SIZE];
if (length > 0) { if (length > 0) {
line_info_add(self, timefrmt, name, NULL, DISCONNECTION, 0, RED, "[Quit]: %s", part_message); line_info_add(self, true, name, NULL, DISCONNECTION, 0, RED, "[Quit]: %s", part_message);
snprintf(log_str, sizeof(log_str), "has left the room (%s)", part_message); snprintf(log_str, sizeof(log_str), "has left the room (%s)", part_message);
} else { } else {
const char *exit_string = get_group_exit_string(exit_type); const char *exit_string = get_group_exit_string(exit_type);
line_info_add(self, timefrmt, name, NULL, DISCONNECTION, 0, RED, "[%s]", exit_string); line_info_add(self, true, name, NULL, DISCONNECTION, 0, RED, "[%s]", exit_string);
snprintf(log_str, sizeof(log_str), "[%s]", exit_string); snprintf(log_str, sizeof(log_str), "[%s]", exit_string);
} }
@ -955,14 +925,14 @@ static void groupchat_set_group_name(ToxWindow *self, Tox *m, uint32_t groupnumb
size_t len = tox_group_get_name_size(m, groupnumber, &err); size_t len = tox_group_get_name_size(m, groupnumber, &err);
if (err != TOX_ERR_GROUP_STATE_QUERIES_OK) { if (err != TOX_ERR_GROUP_STATE_QUERIES_OK) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve group name length (error %d)", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve group name length (error %d)", err);
return; return;
} }
char tmp_groupname[TOX_GROUP_MAX_GROUP_NAME_LENGTH + 1]; char tmp_groupname[TOX_GROUP_MAX_GROUP_NAME_LENGTH + 1];
if (!tox_group_get_name(m, groupnumber, (uint8_t *) tmp_groupname, &err)) { if (!tox_group_get_name(m, groupnumber, (uint8_t *) tmp_groupname, &err)) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve group name (error %d)", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve group name (error %d)", err);
return; return;
} }
@ -995,7 +965,7 @@ static void groupchat_onGroupSelfJoin(ToxWindow *self, Tox *m, uint32_t groupnum
size_t topic_length = tox_group_get_topic_size(m, groupnumber, &err); size_t topic_length = tox_group_get_topic_size(m, groupnumber, &err);
if (err != TOX_ERR_GROUP_STATE_QUERIES_OK) { if (err != TOX_ERR_GROUP_STATE_QUERIES_OK) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve group topic length (error %d)", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve group topic length (error %d)", err);
return; return;
} }
@ -1003,14 +973,11 @@ static void groupchat_onGroupSelfJoin(ToxWindow *self, Tox *m, uint32_t groupnum
topic[topic_length] = 0; topic[topic_length] = 0;
if (err != TOX_ERR_GROUP_STATE_QUERIES_OK) { if (err != TOX_ERR_GROUP_STATE_QUERIES_OK) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve group topic (error %d)", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve group topic (error %d)", err);
return; return;
} }
char timefrmt[TIME_STR_SIZE]; line_info_add(self, true, NULL, NULL, SYS_MSG, 1, MAGENTA, "-!- Topic set to: %s", topic);
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, MAGENTA, "-!- Topic set to: %s", topic);
if (chat->group_name_length == 0) { if (chat->group_name_length == 0) {
groupchat_set_group_name(self, m, groupnumber); groupchat_set_group_name(self, m, groupnumber);
@ -1067,10 +1034,7 @@ static void groupchat_onGroupRejected(ToxWindow *self, Tox *m, uint32_t groupnum
break; break;
} }
char timefrmt[TIME_STR_SIZE]; line_info_add(self, true, NULL, NULL, SYS_MSG, 0, RED, "-!- %s", msg);
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 0, RED, "-!- %s", msg);
} }
void groupchat_onGroupModeration(ToxWindow *self, Tox *m, uint32_t groupnumber, uint32_t src_peer_id, void groupchat_onGroupModeration(ToxWindow *self, Tox *m, uint32_t groupnumber, uint32_t src_peer_id,
@ -1100,29 +1064,26 @@ void groupchat_onGroupModeration(ToxWindow *self, Tox *m, uint32_t groupnumber,
groupchat_update_last_seen(groupnumber, src_peer_id); groupchat_update_last_seen(groupnumber, src_peer_id);
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
switch (type) { switch (type) {
case TOX_GROUP_MOD_EVENT_KICK: case TOX_GROUP_MOD_EVENT_KICK:
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, RED, "-!- %s has been kicked by %s", tgt_name, src_name); line_info_add(self, true, NULL, NULL, SYS_MSG, 1, RED, "-!- %s has been kicked by %s", tgt_name, src_name);
break; break;
case TOX_GROUP_MOD_EVENT_OBSERVER: case TOX_GROUP_MOD_EVENT_OBSERVER:
chat->peer_list[tgt_index].role = TOX_GROUP_ROLE_OBSERVER; chat->peer_list[tgt_index].role = TOX_GROUP_ROLE_OBSERVER;
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- %s has set %s's role to observer", src_name, tgt_name); line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE, "-!- %s has set %s's role to observer", src_name, tgt_name);
sort_peerlist(groupnumber); sort_peerlist(groupnumber);
break; break;
case TOX_GROUP_MOD_EVENT_USER: case TOX_GROUP_MOD_EVENT_USER:
chat->peer_list[tgt_index].role = TOX_GROUP_ROLE_USER; chat->peer_list[tgt_index].role = TOX_GROUP_ROLE_USER;
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- %s has set %s's role to user", src_name, tgt_name); line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE, "-!- %s has set %s's role to user", src_name, tgt_name);
sort_peerlist(groupnumber); sort_peerlist(groupnumber);
break; break;
case TOX_GROUP_MOD_EVENT_MODERATOR: case TOX_GROUP_MOD_EVENT_MODERATOR:
chat->peer_list[tgt_index].role = TOX_GROUP_ROLE_MODERATOR; chat->peer_list[tgt_index].role = TOX_GROUP_ROLE_MODERATOR;
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- %s has set %s's role to moderator", src_name, line_info_add(self, true, NULL, NULL, SYS_MSG, 1, BLUE, "-!- %s has set %s's role to moderator", src_name,
tgt_name); tgt_name);
sort_peerlist(groupnumber); sort_peerlist(groupnumber);
break; break;
@ -1165,9 +1126,7 @@ static void groupchat_onGroupSelfNickChange(ToxWindow *self, Tox *m, uint32_t gr
chat->peer_list[peer_index].name[length] = 0; chat->peer_list[peer_index].name[length] = 0;
chat->peer_list[peer_index].name_length = length; chat->peer_list[peer_index].name_length = length;
char timefrmt[TIME_STR_SIZE]; line_info_add(self, true, old_nick, chat->peer_list[peer_index].name, NAME_CHANGE, 0, MAGENTA, " is now known as ");
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, old_nick, chat->peer_list[peer_index].name, NAME_CHANGE, 0, MAGENTA, " is now known as ");
groupchat_update_last_seen(groupnumber, peer_id); groupchat_update_last_seen(groupnumber, peer_id);
group_update_name_list(groupnumber); group_update_name_list(groupnumber);
@ -1202,9 +1161,7 @@ static void groupchat_onGroupNickChange(ToxWindow *self, Tox *m, uint32_t groupn
chat->peer_list[peer_index].name[length] = 0; chat->peer_list[peer_index].name[length] = 0;
chat->peer_list[peer_index].name_length = length; chat->peer_list[peer_index].name_length = length;
char timefrmt[TIME_STR_SIZE]; line_info_add(self, true, oldnick, chat->peer_list[peer_index].name, NAME_CHANGE, 0, MAGENTA, " is now known as ");
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, oldnick, chat->peer_list[peer_index].name, NAME_CHANGE, 0, MAGENTA, " is now known as ");
group_update_name_list(groupnumber); group_update_name_list(groupnumber);
} }
@ -1245,9 +1202,9 @@ static void send_group_message(ToxWindow *self, Tox *m, uint32_t groupnumber, co
if (!tox_group_send_message(m, groupnumber, type, (uint8_t *) msg, strlen(msg), &err)) { if (!tox_group_send_message(m, groupnumber, type, (uint8_t *) msg, strlen(msg), &err)) {
if (err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS) { if (err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * You are silenced."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * You are silenced.");
} else { } else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send message (Error %d).", err); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send message (Error %d).", err);
} }
return; return;
@ -1256,15 +1213,11 @@ static void send_group_message(ToxWindow *self, Tox *m, uint32_t groupnumber, co
char self_nick[TOX_MAX_NAME_LENGTH + 1]; char self_nick[TOX_MAX_NAME_LENGTH + 1];
get_group_self_nick_truncate(m, self_nick, groupnumber); get_group_self_nick_truncate(m, self_nick, groupnumber);
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
if (type == TOX_MESSAGE_TYPE_NORMAL) { if (type == TOX_MESSAGE_TYPE_NORMAL) {
line_info_add(self, timefrmt, self_nick, NULL, OUT_MSG_READ, 0, 0, "%s", msg); line_info_add(self, true, self_nick, NULL, OUT_MSG_READ, 0, 0, "%s", msg);
write_to_log(msg, self_nick, ctx->log, false); write_to_log(msg, self_nick, ctx->log, false);
} else if (type == TOX_MESSAGE_TYPE_ACTION) { } else if (type == TOX_MESSAGE_TYPE_ACTION) {
line_info_add(self, timefrmt, self_nick, NULL, OUT_ACTION_READ, 0, 0, "%s", msg); line_info_add(self, true, self_nick, NULL, OUT_ACTION_READ, 0, 0, "%s", msg);
write_to_log(msg, self_nick, ctx->log, true); write_to_log(msg, self_nick, ctx->log, true);
} }
} }
@ -1276,12 +1229,12 @@ static void send_group_prvt_message(ToxWindow *self, Tox *m, uint32_t groupnumbe
GroupChat *chat = get_groupchat(groupnumber); GroupChat *chat = get_groupchat(groupnumber);
if (!chat) { if (!chat) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, "Failed to fetch GroupChat object."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, "Failed to fetch GroupChat object.");
return; return;
} }
if (data == NULL) { if (data == NULL) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, "Invalid comand."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, "Invalid comand.");
return; return;
} }
@ -1309,14 +1262,14 @@ static void send_group_prvt_message(ToxWindow *self, Tox *m, uint32_t groupnumbe
} }
if (nick == NULL) { if (nick == NULL) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name.");
return; return;
} }
int msg_len = ((int) data_len) - ((int) name_length) - 1; int msg_len = ((int) data_len) - ((int) name_length) - 1;
if (msg_len <= 0) { if (msg_len <= 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Message is empty."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Message is empty.");
return; return;
} }
@ -1326,9 +1279,9 @@ static void send_group_prvt_message(ToxWindow *self, Tox *m, uint32_t groupnumbe
if (!tox_group_send_private_message(m, groupnumber, peer_id, TOX_MESSAGE_TYPE_NORMAL, (uint8_t *) msg, msg_len, &err)) { if (!tox_group_send_private_message(m, groupnumber, peer_id, TOX_MESSAGE_TYPE_NORMAL, (uint8_t *) msg, msg_len, &err)) {
if (err == TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_PERMISSIONS) { if (err == TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_PERMISSIONS) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * You are silenced."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * You are silenced.");
} else { } else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send private message."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send private message.");
} }
return; return;
@ -1337,10 +1290,7 @@ static void send_group_prvt_message(ToxWindow *self, Tox *m, uint32_t groupnumbe
char pm_nick[TOX_MAX_NAME_LENGTH + 3]; char pm_nick[TOX_MAX_NAME_LENGTH + 3];
snprintf(pm_nick, sizeof(pm_nick), ">%s<", nick); snprintf(pm_nick, sizeof(pm_nick), ">%s<", nick);
char timefrmt[TIME_STR_SIZE]; line_info_add(self, true, pm_nick, NULL, OUT_PRVT_MSG, 0, 0, "%s", msg);
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, pm_nick, NULL, OUT_PRVT_MSG, 0, 0, "%s", msg);
write_to_log(msg, pm_nick, ctx->log, false); write_to_log(msg, pm_nick, ctx->log, false);
} }
@ -1473,7 +1423,7 @@ static bool groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
} else if (line[0]) { } else if (line[0]) {
send_group_message(self, m, self->num, line, TOX_MESSAGE_TYPE_NORMAL); send_group_message(self, m, self->num, line, TOX_MESSAGE_TYPE_NORMAL);
} else { } else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to parse message."); line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, " * Failed to parse message.");
} }
wclear(ctx->linewin); wclear(ctx->linewin);

View File

@ -106,9 +106,11 @@ static struct ui_strings {
"line_alert", "line_alert",
"line_normal", "line_normal",
"line_special", "line_special",
"group_part_message",
"mplex_away", "mplex_away",
"mplex_away_note", "mplex_away_note",
"group_part_message",
"color_bar_bg", "color_bar_bg",
"color_bar_fg", "color_bar_fg",
"color_bar_accent", "color_bar_accent",