mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-15 04:53:02 +01:00
implement group join rejection callback
This commit is contained in:
parent
ff3da5f657
commit
89637e7d2f
@ -196,8 +196,14 @@ void set_nick_all_groups(Tox *m, const char *nick, uint16_t length)
|
||||
for (i = 0; i < max_groupchat_index; ++i) {
|
||||
if (groupchats[i].active) {
|
||||
ToxWindow *self = get_window_ptr(groupchats[i].chatwin);
|
||||
tox_group_set_name(m, groupchats[i].groupnumber, (uint8_t *) nick, length);
|
||||
line_info_add(self, timefrmt, NULL, nick, NAME_CHANGE, 0, MAGENTA, "You are now known as ");
|
||||
int ret = tox_group_set_name(m, groupchats[i].groupnumber, (uint8_t *) nick, length);
|
||||
|
||||
if (ret == -1 && groupchats[i].is_connected)
|
||||
line_info_add(self, timefrmt, NULL, 0, SYS_MSG, 0, 0, "Invalid nick");
|
||||
else if (ret == -2)
|
||||
line_info_add(self, timefrmt, NULL, 0, SYS_MSG, 0, RED, "-!- That nick is already in use");
|
||||
else
|
||||
line_info_add(self, timefrmt, NULL, nick, NAME_CHANGE, 0, MAGENTA, "You are now known as ");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -482,6 +488,15 @@ static void groupchat_onGroupSelfJoin(ToxWindow *self, Tox *m, int groupnum)
|
||||
char timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < max_groupchat_index; ++i) {
|
||||
if (groupchats[i].active && groupchats[i].groupnumber == groupnum) {
|
||||
groupchats[i].is_connected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 0, MAGENTA, "-!- Topic set to: %s", topic);
|
||||
}
|
||||
|
||||
@ -490,7 +505,46 @@ static void groupchat_onGroupSelfTimeout(ToxWindow *self, Tox *m, int groupnum)
|
||||
if (groupnum != self->num)
|
||||
return;
|
||||
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Disconnected from group. Attempting to reconnect...");
|
||||
int i;
|
||||
|
||||
for (i = 0; i < max_groupchat_index; ++i) {
|
||||
if (groupchats[i].active && groupchats[i].groupnumber == groupnum) {
|
||||
groupchats[i].is_connected = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
|
||||
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 0, RED, "-!- Disconnected from group");
|
||||
}
|
||||
|
||||
static void groupchat_onGroupRejected(ToxWindow *self, Tox *m, int groupnum, uint8_t type)
|
||||
{
|
||||
if (groupnum != self->num)
|
||||
return;
|
||||
|
||||
const char *msg;
|
||||
|
||||
switch (type) {
|
||||
case TOX_GJ_NICK_TAKEN:
|
||||
msg = "That nick is already in use. Please change your nick with the '/nick' command.";
|
||||
break;
|
||||
case TOX_GJ_GROUP_FULL:
|
||||
msg = "Group is full.";
|
||||
break;
|
||||
case TOX_GJ_INVITES_DISABLED:
|
||||
msg = "Invites for this group have been disabled.";
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
char timefrmt[TIME_STR_SIZE];
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
|
||||
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 0, RED, "-!- %s", msg);
|
||||
}
|
||||
|
||||
static void groupchat_onGroupOpCertificate(ToxWindow *self, Tox *m, int groupnum, uint32_t src_peernum,
|
||||
@ -929,6 +983,7 @@ ToxWindow new_group_chat(Tox *m, int groupnum, const char *groupname, int length
|
||||
ret.onGroupNickChange = &groupchat_onGroupNickChange;
|
||||
ret.onGroupSelfJoin = &groupchat_onGroupSelfJoin;
|
||||
ret.onGroupSelfTimeout = &groupchat_onGroupSelfTimeout;
|
||||
ret.onGroupRejected = &groupchat_onGroupRejected;
|
||||
|
||||
#ifdef AUDIO
|
||||
ret.onWriteDevice = &groupchat_onWriteDevice;
|
||||
|
@ -62,6 +62,7 @@ typedef struct {
|
||||
int groupnumber;
|
||||
int chatwin;
|
||||
bool active;
|
||||
bool is_connected;
|
||||
int num_peers;
|
||||
int side_pos; /* current position of the sidebar - used for scrolling up and down */
|
||||
uint8_t *peer_names;
|
||||
|
@ -321,6 +321,7 @@ static Tox *init_tox(void)
|
||||
tox_callback_group_topic_change(m, on_group_topic_change, NULL);
|
||||
tox_callback_group_self_join(m, on_group_self_join, NULL);
|
||||
tox_callback_group_self_timeout(m, on_group_self_timeout, NULL);
|
||||
tox_callback_group_rejected(m, on_group_rejected, NULL);
|
||||
|
||||
tox_set_name(m, (uint8_t *) "Toxic User", strlen("Toxic User"));
|
||||
|
||||
|
@ -122,6 +122,7 @@ void on_group_nick_change(Tox *m, int groupnumber, uint32_t peernumber, const ui
|
||||
void on_group_op_certificate(Tox *m, int groupnumber, uint32_t src_peernum, uint32_t tgt_peernum, uint8_t cert_type, void *userdata);
|
||||
void on_group_self_join(Tox *m, int groupnumber, void *userdata);
|
||||
void on_group_self_timeout(Tox *m, int groupnumber, void *userdata);
|
||||
void on_group_rejected(Tox *m, int groupnumber, uint8_t type, void *userdata);
|
||||
|
||||
#ifdef AUDIO
|
||||
void write_device_callback_group(Tox *m, int groupnum, int peernum, const int16_t *pcm, unsigned int samples,
|
||||
|
@ -305,6 +305,16 @@ void on_group_self_timeout(Tox *m, int groupnumber, void *userdata)
|
||||
}
|
||||
}
|
||||
|
||||
void on_group_rejected(Tox *m, int groupnumber, uint8_t type, void *userdata)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i].onGroupRejected != NULL)
|
||||
windows[i].onGroupRejected(&windows[i], m, groupnumber, type);
|
||||
}
|
||||
}
|
||||
|
||||
void on_file_sendrequest(Tox *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize,
|
||||
const uint8_t *filename, uint16_t filename_length, void *userdata)
|
||||
{
|
||||
|
@ -134,6 +134,7 @@ struct ToxWindow {
|
||||
void(*onGroupTopicChange)(ToxWindow *, Tox *, int, uint32_t, const char *, uint16_t);
|
||||
void(*onGroupSelfJoin)(ToxWindow *, Tox *, int);
|
||||
void(*onGroupSelfTimeout)(ToxWindow *, Tox *, int);
|
||||
void(*onGroupRejected)(ToxWindow *, Tox *, int, uint8_t);
|
||||
|
||||
#ifdef AUDIO
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user