1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-30 02:13:28 +01:00

Add group peer kicking && update related callback

This commit is contained in:
Jfreegman 2015-05-26 01:23:09 -04:00
parent 3826fd793d
commit 526bd02189
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
9 changed files with 80 additions and 39 deletions

View File

@ -87,6 +87,7 @@ static struct cmd_func chat_commands[] = {
static struct cmd_func group_commands[] = {
{ "/chatid", cmd_chatid },
{ "/ignore", cmd_ignore },
{ "/kick", cmd_kick },
{ "/passwd", cmd_set_passwd },
{ "/peerlimit", cmd_set_peerlimit },
{ "/privacy", cmd_set_privacy },
@ -100,11 +101,12 @@ static struct cmd_func group_commands[] = {
{ NULL, NULL },
};
#define NUM_SPECIAL_COMMANDS 8
#define NUM_SPECIAL_COMMANDS 9
static const char special_commands[NUM_SPECIAL_COMMANDS][MAX_CMDNAME_SIZE] = {
"/gaccept",
"/group",
"/ignore",
"/kick",
"/nick",
"/note",
"/passwd",

View File

@ -54,7 +54,7 @@ void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Who do you want to ignore?");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified.");
return;
}
@ -62,7 +62,7 @@ void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
int peernum = group_get_nick_peernumber(self->num, nick);
if (peernum == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer '%s' does not exist", nick);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name");
return;
}
@ -77,6 +77,39 @@ void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
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])
{
if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer name must be specified.");
return;
}
const char *nick = argv[1];
int peernumber = group_get_nick_peernumber(self->num, nick);
if (peernumber == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid peer name");
return;
}
int ret = tox_group_op_kick_peer(m, self->num, (uint32_t) peernumber);
switch (ret) {
case 0: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You have kicked %s from the group.", nick);
return;
}
case -1: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to kick %s from the group.", nick);
return;
}
case -2: {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to kick %s.", nick);
return;
}
}
}
void cmd_set_passwd(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
const char *passwd = NULL;

View File

@ -28,6 +28,7 @@
void cmd_chatid(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]);
void cmd_kick(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]);
void cmd_set_peerlimit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_set_privacy(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);

View File

@ -70,9 +70,9 @@ extern struct user_settings *user_settings;
extern struct Winthread Winthread;
#ifdef AUDIO
#define AC_NUM_GROUP_COMMANDS 31
#define AC_NUM_GROUP_COMMANDS 32
#else
#define AC_NUM_GROUP_COMMANDS 27
#define AC_NUM_GROUP_COMMANDS 28
#endif /* AUDIO */
/* groupchat command names used for tab completion. */
@ -90,6 +90,7 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
{ "/help" },
{ "/ignore" },
{ "/join" },
{ "/kick" },
{ "/log" },
{ "/myid" },
{ "/nick" },
@ -210,9 +211,9 @@ void set_nick_all_groups(Tox *m, const char *nick, uint16_t length)
int ret = tox_group_set_self_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");
line_info_add(self, NULL, 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");
line_info_add(self, NULL, 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 ");
}
@ -571,32 +572,33 @@ static void groupchat_onGroupRejected(ToxWindow *self, Tox *m, int groupnum, uin
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,
uint32_t tgt_peernum, uint8_t type)
static void groupchat_onGroupModeration(ToxWindow *self, Tox *m, int groupnum, uint32_t src_peernum,
uint32_t tgt_peernum, TOX_GROUP_MOD_TYPE type)
{
if (groupnum != self->num)
return;
char src_name[TOX_MAX_NAME_LENGTH];
get_group_nick_truncate(m, src_name, src_peernum, groupnum);
char tgt_name[TOX_MAX_NAME_LENGTH];
get_group_nick_truncate(m, tgt_name, tgt_peernum, groupnum);
const char *msg = NULL;
if (get_group_nick_truncate(m, src_name, src_peernum, groupnum) == -1)
return;
if (get_group_nick_truncate(m, tgt_name, tgt_peernum, groupnum) == -1)
return;
const char *eventstr = NULL;
int colour = RED;
switch (type) {
case TOX_GC_BAN:
msg = "has banned";
case TOX_MOD_KICK:
eventstr = "kicked";
break;
case TOX_GC_PROMOTE_OP:
msg = "has given operator status to";
case TOX_MOD_BAN:
eventstr = "banned";
break;
case TOX_GC_REVOKE_OP:
msg = "has removed operator status from";
break;
case TOX_GC_SILENCE:
msg = "has silenced";
case TOX_MOD_SILENCE:
eventstr = "silenced";
break;
default:
return;
@ -604,7 +606,7 @@ static void groupchat_onGroupOpCertificate(ToxWindow *self, Tox *m, int groupnum
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, src_name, tgt_name, NAME_CHANGE, 0, MAGENTA, "%s", msg);
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, colour, "-!- %s has been %s by %s", tgt_name, eventstr, src_name);
}
static void groupchat_onGroupNickChange(ToxWindow *self, Tox *m, int groupnum, uint32_t peernum,
@ -952,10 +954,10 @@ ToxWindow new_group_chat(Tox *m, int groupnum, const char *groupname, int length
ret.onGroupPeerJoin = &groupchat_onGroupPeerJoin;
ret.onGroupPeerExit = &groupchat_onGroupPeerExit;
ret.onGroupTopicChange = &groupchat_onGroupTopicChange;
ret.onGroupOpCertificate = &groupchat_onGroupOpCertificate;
ret.onGroupNickChange = &groupchat_onGroupNickChange;
ret.onGroupSelfJoin = &groupchat_onGroupSelfJoin;
ret.onGroupRejected = &groupchat_onGroupRejected;
ret.onGroupModeration = &groupchat_onGroupModeration;
ChatContext *chatwin = calloc(1, sizeof(ChatContext));
Help *help = calloc(1, sizeof(Help));

View File

@ -245,6 +245,7 @@ static void help_draw_group(ToxWindow *self)
wprintw(win, " /chatid : Print the group chat id to share with others.\n");
wprintw(win, " /ignore <nick> : Ignore peer\n");
wprintw(win, " /kick <nick> : Kick peer\n");
wprintw(win, " /passwd <password> : Set group password (leave blank to unset)\n");
wprintw(win, " /peerlimit <num> : Set group peer limit\n");
wprintw(win, " /privacy <state> : Set group privacy state: private|public\n");
@ -310,7 +311,7 @@ void help_onKey(ToxWindow *self, wint_t key)
break;
case 'r':
help_init_window(self, 14, 80);
help_init_window(self, 15, 80);
self->help->type = HELP_GROUP;
break;

View File

@ -571,7 +571,6 @@ static void init_tox_callbacks(Tox *m)
tox_callback_group_message(m, on_group_message, NULL);
tox_callback_group_action(m, on_group_action, NULL);
tox_callback_group_private_message(m, on_group_private_message, NULL);
tox_callback_group_op_certificate(m, on_group_op_certificate, NULL);
tox_callback_group_peerlist_update(m, on_group_namelistchange, NULL);
tox_callback_group_peer_join(m, on_group_peer_join, NULL);
tox_callback_group_peer_exit(m, on_group_peer_exit, NULL);
@ -579,6 +578,7 @@ static void init_tox_callbacks(Tox *m)
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_rejected(m, on_group_rejected, NULL);
tox_callback_group_moderation(m, on_group_moderation, NULL);
}
static void init_tox_options(struct Tox_Options *tox_opts)

View File

@ -125,7 +125,9 @@ void on_group_peer_join(Tox *m, int groupnumber, uint32_t peernumber, void *user
void on_group_peer_exit(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *partmsg, uint16_t length, void *userdata);
void on_group_topic_change(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *topic, uint16_t length, void *userdata);
void on_group_nick_change(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *newname, uint16_t length, void *userdata);
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_rejected(Tox *m, int groupnumber, uint8_t type, void *userdata);
void on_group_moderation(Tox *m, int groupnumber, uint32_t source_peernum, uint32_t target_peernum,
TOX_GROUP_MOD_TYPE type, void *userdata);
#endif /* #define TOXIC_H */

View File

@ -272,17 +272,6 @@ 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)
{
size_t i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onGroupOpCertificate != NULL)
windows[i].onGroupOpCertificate(&windows[i], m, groupnumber, src_peernum, tgt_peernum, cert_type);
}
}
void on_group_self_join(Tox *m, int groupnumber, void *userdata)
{
size_t i;
@ -303,6 +292,17 @@ void on_group_rejected(Tox *m, int groupnumber, uint8_t type, void *userdata)
}
}
void on_group_moderation(Tox *m, int groupnumber, uint32_t source_peernum, uint32_t target_peernum,
TOX_GROUP_MOD_TYPE type, void *userdata)
{
size_t i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onGroupModeration != NULL)
windows[i].onGroupModeration(&windows[i], m, groupnumber, source_peernum, target_peernum, type);
}
}
void on_file_chunk_request(Tox *m, uint32_t friendnumber, uint32_t filenumber, uint64_t position,
size_t length, void *userdata)
{

View File

@ -130,7 +130,6 @@ struct ToxWindow {
void(*onGroupMessage)(ToxWindow *, Tox *, int, int, const char *, uint16_t);
void(*onGroupAction)(ToxWindow *, Tox *, int, int, const char *, uint16_t);
void(*onGroupPrivateMessage)(ToxWindow *, Tox *, int, uint32_t, const char *, uint16_t);
void(*onGroupOpCertificate)(ToxWindow *, Tox *, int, uint32_t, uint32_t, uint8_t);
void(*onGroupNamelistChange)(ToxWindow *, Tox *, int);
void(*onGroupPeerJoin)(ToxWindow *, Tox *, int, uint32_t);
void(*onGroupPeerExit)(ToxWindow *, Tox *, int, uint32_t, const char *, uint16_t);
@ -138,6 +137,7 @@ struct ToxWindow {
void(*onGroupTopicChange)(ToxWindow *, Tox *, int, uint32_t, const char *, uint16_t);
void(*onGroupSelfJoin)(ToxWindow *, Tox *, int);
void(*onGroupRejected)(ToxWindow *, Tox *, int, uint8_t);
void(*onGroupModeration)(ToxWindow *, Tox *, int, uint32_t, uint32_t, TOX_GROUP_MOD_TYPE);
#ifdef AUDIO