mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 15:43:24 +01:00
use/display nicks instead of friend numbers for groupchat invites
This commit is contained in:
parent
84422b5845
commit
42de821e3c
@ -21,6 +21,7 @@ extern ToxWindow *prompt;
|
||||
|
||||
typedef struct {
|
||||
uint8_t name[TOX_MAX_NAME_LENGTH];
|
||||
uint8_t namelength;
|
||||
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
|
||||
uint16_t statusmsg_len;
|
||||
int num;
|
||||
@ -58,6 +59,7 @@ void friendlist_onNickChange(ToxWindow *self, int num, uint8_t *str, uint16_t le
|
||||
return;
|
||||
|
||||
memcpy((char *) &friends[num].name, (char *) str, len);
|
||||
friends[num].namelength = len;
|
||||
}
|
||||
|
||||
void friendlist_onStatusChange(ToxWindow *self, Tox *m, int num, TOX_USERSTATUS status)
|
||||
@ -91,9 +93,12 @@ int friendlist_onFriendAdded(Tox *m, int num)
|
||||
friends[i].chatwin = -1;
|
||||
friends[i].online = false;
|
||||
friends[i].status = TOX_USERSTATUS_NONE;
|
||||
friends[i].namelength = tox_getname(m, num, friends[i].name);
|
||||
|
||||
if (tox_getname(m, num, friends[i].name) == -1 || friends[i].name[0] == '\0')
|
||||
if (friends[i].namelength == -1 || friends[i].name[0] == '\0') {
|
||||
strcpy((char *) friends[i].name, UNKNOWN_NAME);
|
||||
friends[i].namelength = strlen(UNKNOWN_NAME) + 1;
|
||||
}
|
||||
|
||||
if (i == num_friends)
|
||||
++num_friends;
|
||||
@ -251,6 +256,21 @@ void disable_chatwin(int f_num)
|
||||
friends[f_num].chatwin = -1;
|
||||
}
|
||||
|
||||
/* Returns the respective friend number of name. Returns -1 on no match
|
||||
This should be used instead of tox_getname for retrieving */
|
||||
int get_friendnum(uint8_t *name)
|
||||
{
|
||||
int i;
|
||||
int len = strlen(name);
|
||||
|
||||
for (i = 0; i < num_friends; ++i) {
|
||||
if (strncmp(friends[i].name, name, len) == 0)
|
||||
return friends[i].num;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void friendlist_onInit(ToxWindow *self, Tox *m)
|
||||
{
|
||||
|
||||
|
@ -7,5 +7,6 @@
|
||||
ToxWindow new_friendlist();
|
||||
int friendlist_onFriendAdded(Tox *m, int num);
|
||||
void disable_chatwin(int f_num);
|
||||
int get_friendnum(uint8_t *name);
|
||||
|
||||
#endif /* end of include guard: FRIENDLIST_H_53I41IM */
|
||||
|
29
src/prompt.c
29
src/prompt.c
@ -340,8 +340,8 @@ void cmd_help(ToxWindow *self, Tox *m, int argc, char **argv)
|
||||
wprintw(self->window, " status <type> <message> : Set your status with optional note\n");
|
||||
wprintw(self->window, " note <message> : Set a personal note\n");
|
||||
wprintw(self->window, " nick <nickname> : Set your nickname\n");
|
||||
wprintw(self->window, " join <n> : Join a group chat (must be invited)\n");
|
||||
wprintw(self->window, " invite <f> <g> : Invite friend f to groupchat g\n");
|
||||
wprintw(self->window, " join <n> : Join a group chat\n");
|
||||
wprintw(self->window, " invite <nick> <n> : Invite friend to a groupchat\n");
|
||||
wprintw(self->window, " groupchat : Create a group chat\n");
|
||||
wprintw(self->window, " myid : Print your ID\n");
|
||||
wprintw(self->window, " quit/exit : Exit Toxic\n");
|
||||
@ -368,15 +368,25 @@ void cmd_invite(ToxWindow *self, Tox *m, int argc, char **argv)
|
||||
return;
|
||||
}
|
||||
|
||||
int friendnum = atoi(argv[1]);
|
||||
uint8_t *friendname = argv[1];
|
||||
int groupnum = atoi(argv[2]);
|
||||
|
||||
if (friendname[0] == '\"')
|
||||
friendname[strlen(++friendname)-1] = L'\0';
|
||||
|
||||
int friendnum = get_friendnum(friendname);
|
||||
|
||||
if (friendnum == -1) {
|
||||
wprintw(self->window, "Friend '%s' not found.\n", friendname);
|
||||
return;
|
||||
}
|
||||
|
||||
if (tox_invite_friend(m, friendnum, groupnum) == -1) {
|
||||
wprintw(self->window, "Failed to invite friend.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
wprintw(self->window, "Invited friend %d to group chat %d.\n", friendnum, groupnum);
|
||||
wprintw(self->window, "Invited friend %s to group chat %d.\n", friendname, groupnum);
|
||||
}
|
||||
|
||||
void cmd_join(ToxWindow *self, Tox *m, int argc, char **argv)
|
||||
@ -779,7 +789,16 @@ void prompt_onFriendRequest(ToxWindow *self, uint8_t *key, uint8_t *data, uint16
|
||||
|
||||
void prompt_onGroupInvite(ToxWindow *self, Tox *m, int friendnumber, uint8_t *group_pub_key)
|
||||
{
|
||||
wprintw(self->window, "\nGroup chat invite from: %d\n", friendnumber);
|
||||
if (friendnumber < 0)
|
||||
return;
|
||||
|
||||
uint8_t name[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
|
||||
if (tox_getname(m, friendnumber, name) == -1)
|
||||
return;
|
||||
|
||||
name[TOXIC_MAX_NAME_LENGTH] = '\0'; /* enforce client max name length */
|
||||
wprintw(self->window, "\nGroup chat invite from %s.\n", name);
|
||||
|
||||
int ngc = get_num_groupchats();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user