mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 01:53:02 +01:00
fix nick truncating
This commit is contained in:
parent
60f9be7234
commit
f1a3ed379e
30
src/chat.c
30
src/chat.c
@ -191,8 +191,7 @@ static void chat_onAction(ToxWindow *self, Tox *m, int32_t num, const char *acti
|
|||||||
|
|
||||||
char nick[TOX_MAX_NAME_LENGTH];
|
char nick[TOX_MAX_NAME_LENGTH];
|
||||||
int n_len = tox_get_name(m, num, (uint8_t *) nick);
|
int n_len = tox_get_name(m, num, (uint8_t *) nick);
|
||||||
|
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);
|
||||||
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);;
|
|
||||||
nick[n_len] = '\0';
|
nick[n_len] = '\0';
|
||||||
|
|
||||||
char timefrmt[TIME_STR_SIZE];
|
char timefrmt[TIME_STR_SIZE];
|
||||||
@ -208,7 +207,15 @@ static void chat_onNickChange(ToxWindow *self, Tox *m, int32_t num, const char *
|
|||||||
if (self->num != num)
|
if (self->num != num)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
snprintf(self->name, sizeof(self->name), "%s", nick);
|
StatusBar *statusbar = self->stb;
|
||||||
|
|
||||||
|
char tmpname[TOX_MAX_NAME_LENGTH];
|
||||||
|
strcpy(tmpname, nick);
|
||||||
|
int n_len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
||||||
|
tmpname[n_len] = '\0';
|
||||||
|
|
||||||
|
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", tmpname);
|
||||||
|
snprintf(self->name, sizeof(self->name), "%s", tmpname);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void chat_onStatusChange(ToxWindow *self, Tox *m, int32_t num, uint8_t status)
|
static void chat_onStatusChange(ToxWindow *self, Tox *m, int32_t num, uint8_t status)
|
||||||
@ -786,7 +793,7 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
|
|||||||
wattron(statusbar->topline, COLOR_PAIR(YELLOW));
|
wattron(statusbar->topline, COLOR_PAIR(YELLOW));
|
||||||
|
|
||||||
wattron(statusbar->topline, A_BOLD);
|
wattron(statusbar->topline, A_BOLD);
|
||||||
wprintw(statusbar->topline, " %s ", self->name);
|
wprintw(statusbar->topline, " %s ", statusbar->nick);
|
||||||
wattroff(statusbar->topline, A_BOLD);
|
wattroff(statusbar->topline, A_BOLD);
|
||||||
|
|
||||||
if (friends[self->num].is_typing)
|
if (friends[self->num].is_typing)
|
||||||
@ -794,7 +801,7 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
|
|||||||
} else {
|
} else {
|
||||||
wprintw(statusbar->topline, " o");
|
wprintw(statusbar->topline, " o");
|
||||||
wattron(statusbar->topline, A_BOLD);
|
wattron(statusbar->topline, A_BOLD);
|
||||||
wprintw(statusbar->topline, " %s ", self->name);
|
wprintw(statusbar->topline, " %s ", statusbar->nick);
|
||||||
wattroff(statusbar->topline, A_BOLD);
|
wattroff(statusbar->topline, A_BOLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -874,6 +881,13 @@ static void chat_onInit(ToxWindow *self, Tox *m)
|
|||||||
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
|
||||||
statusbar->statusmsg_len = s_len;
|
statusbar->statusmsg_len = s_len;
|
||||||
|
|
||||||
|
char nick[TOX_MAX_NAME_LENGTH];
|
||||||
|
int n_len = tox_get_name(m, self->num, (uint8_t *) nick);
|
||||||
|
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);
|
||||||
|
nick[n_len] = '\0';
|
||||||
|
snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
|
||||||
|
statusbar->nick_len = n_len;
|
||||||
|
|
||||||
/* Init subwindows */
|
/* Init subwindows */
|
||||||
ChatContext *ctx = self->chatwin;
|
ChatContext *ctx = self->chatwin;
|
||||||
|
|
||||||
@ -938,8 +952,10 @@ ToxWindow new_chat(Tox *m, int32_t friendnum)
|
|||||||
ret.device_selection[0] = ret.device_selection[1] = -1;
|
ret.device_selection[0] = ret.device_selection[1] = -1;
|
||||||
#endif /* _SUPPORT_AUDIO */
|
#endif /* _SUPPORT_AUDIO */
|
||||||
|
|
||||||
char name[TOX_MAX_NAME_LENGTH] = {'\0'};
|
char name[TOX_MAX_NAME_LENGTH];
|
||||||
tox_get_name(m, friendnum, (uint8_t *) name);
|
int len = tox_get_name(m, friendnum, (uint8_t *) name);
|
||||||
|
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
||||||
|
name[len] = '\0';
|
||||||
snprintf(ret.name, sizeof(ret.name), "%s", name);
|
snprintf(ret.name, sizeof(ret.name), "%s", name);
|
||||||
|
|
||||||
ChatContext *chatwin = calloc(1, sizeof(ChatContext));
|
ChatContext *chatwin = calloc(1, sizeof(ChatContext));
|
||||||
|
@ -138,8 +138,12 @@ static void friendlist_onNickChange(ToxWindow *self, Tox *m, int32_t num, const
|
|||||||
if (len > TOX_MAX_NAME_LENGTH || num >= max_friends_index)
|
if (len > TOX_MAX_NAME_LENGTH || num >= max_friends_index)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
snprintf(friends[num].name, sizeof(friends[num].name), "%s", nick);
|
char tempname[TOX_MAX_NAME_LENGTH];
|
||||||
friends[num].namelength = strlen(friends[num].name);
|
strcpy(tempname, nick);
|
||||||
|
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
||||||
|
tempname[len] = '\0';
|
||||||
|
snprintf(friends[num].name, sizeof(friends[num].name), "%s", tempname);
|
||||||
|
friends[num].namelength = len;
|
||||||
sort_friendlist_index();
|
sort_friendlist_index();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,17 +178,21 @@ void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort)
|
|||||||
friends[i].chatwin = -1;
|
friends[i].chatwin = -1;
|
||||||
friends[i].online = false;
|
friends[i].online = false;
|
||||||
friends[i].status = TOX_USERSTATUS_NONE;
|
friends[i].status = TOX_USERSTATUS_NONE;
|
||||||
friends[i].namelength = tox_get_name(m, num, (uint8_t *) friends[i].name);
|
|
||||||
friends[i].logging_on = (bool) user_settings->autolog == AUTOLOG_ON;
|
friends[i].logging_on = (bool) user_settings->autolog == AUTOLOG_ON;
|
||||||
tox_get_client_id(m, num, (uint8_t *) friends[i].pub_key);
|
tox_get_client_id(m, num, (uint8_t *) friends[i].pub_key);
|
||||||
update_friend_last_online(i, tox_get_last_online(m, i));
|
update_friend_last_online(i, tox_get_last_online(m, i));
|
||||||
|
|
||||||
if (friends[i].namelength == -1 || friends[i].name[0] == '\0') {
|
char tempname[TOX_MAX_NAME_LENGTH] = {0};
|
||||||
|
int len = tox_get_name(m, num, (uint8_t *) tempname);
|
||||||
|
|
||||||
|
if (len == -1 || tempname[0] == '\0') {
|
||||||
strcpy(friends[i].name, UNKNOWN_NAME);
|
strcpy(friends[i].name, UNKNOWN_NAME);
|
||||||
friends[i].namelength = strlen(UNKNOWN_NAME);
|
friends[i].namelength = strlen(UNKNOWN_NAME);
|
||||||
} else { /* Enforce toxic's maximum name length */
|
} else { /* Enforce toxic's maximum name length */
|
||||||
friends[i].namelength = MIN(friends[i].namelength, TOXIC_MAX_NAME_LENGTH);
|
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
||||||
friends[i].name[friends[i].namelength] = '\0';
|
friends[i].namelength = len;
|
||||||
|
tempname[len] = '\0';
|
||||||
|
snprintf(friends[i].name, sizeof(friends[i].name), "%s", tempname);
|
||||||
}
|
}
|
||||||
|
|
||||||
num_friends = tox_count_friendlist(m);
|
num_friends = tox_count_friendlist(m);
|
||||||
@ -285,7 +293,7 @@ static void delete_friend(Tox *m, int32_t f_num)
|
|||||||
/* activates delete friend popup */
|
/* activates delete friend popup */
|
||||||
static void del_friend_activate(ToxWindow *self, Tox *m, int32_t f_num)
|
static void del_friend_activate(ToxWindow *self, Tox *m, int32_t f_num)
|
||||||
{
|
{
|
||||||
pendingdelete.popup = newwin(3, 22 + TOXIC_MAX_NAME_LENGTH, 8, 8);
|
pendingdelete.popup = newwin(3, 22 + TOXIC_MAX_NAME_LENGTH - 1, 8, 8);
|
||||||
pendingdelete.active = true;
|
pendingdelete.active = true;
|
||||||
pendingdelete.num = f_num;
|
pendingdelete.num = f_num;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ struct LastOnline {
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char name[TOX_MAX_NAME_LENGTH];
|
char name[TOXIC_MAX_NAME_LENGTH];
|
||||||
int namelength;
|
int namelength;
|
||||||
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
|
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
|
||||||
uint16_t statusmsg_len;
|
uint16_t statusmsg_len;
|
||||||
|
@ -133,7 +133,6 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
|||||||
|
|
||||||
char nick[TOX_MAX_NAME_LENGTH];
|
char nick[TOX_MAX_NAME_LENGTH];
|
||||||
int n_len = tox_group_peername(m, groupnum, peernum, (uint8_t *) nick);
|
int n_len = tox_group_peername(m, groupnum, peernum, (uint8_t *) nick);
|
||||||
|
|
||||||
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1); /* enforce client max name length */
|
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1); /* enforce client max name length */
|
||||||
nick[n_len] = '\0';
|
nick[n_len] = '\0';
|
||||||
|
|
||||||
@ -147,7 +146,7 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
|||||||
|
|
||||||
int nick_clr = strcmp(nick, selfnick) == 0 ? GREEN : CYAN;
|
int nick_clr = strcmp(nick, selfnick) == 0 ? GREEN : CYAN;
|
||||||
|
|
||||||
bool nick_match = strcasestr(msg, selfnick) && strncmp(selfnick, nick, TOXIC_MAX_NAME_LENGTH);
|
bool nick_match = strcasestr(msg, selfnick) && strncmp(selfnick, nick, TOXIC_MAX_NAME_LENGTH - 1);
|
||||||
|
|
||||||
if (nick_match) {
|
if (nick_match) {
|
||||||
alert_type = WINDOW_ALERT_0;
|
alert_type = WINDOW_ALERT_0;
|
||||||
|
@ -115,7 +115,7 @@ struct ToxWindow {
|
|||||||
|
|
||||||
#endif /* _SUPPORT_AUDIO */
|
#endif /* _SUPPORT_AUDIO */
|
||||||
|
|
||||||
char name[TOX_MAX_NAME_LENGTH];
|
char name[TOXIC_MAX_NAME_LENGTH];
|
||||||
int32_t num; /* corresponds to friendnumber in chat windows */
|
int32_t num; /* corresponds to friendnumber in chat windows */
|
||||||
bool active;
|
bool active;
|
||||||
int x;
|
int x;
|
||||||
@ -141,8 +141,8 @@ struct StatusBar {
|
|||||||
WINDOW *topline;
|
WINDOW *topline;
|
||||||
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
|
char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
|
||||||
uint16_t statusmsg_len;
|
uint16_t statusmsg_len;
|
||||||
char nick[TOX_MAX_NAME_LENGTH];
|
char nick[TOXIC_MAX_NAME_LENGTH];
|
||||||
uint16_t nick_len;
|
int nick_len;
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
bool is_online;
|
bool is_online;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user