1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-15 05:13:03 +01:00

add group rejoin command

This commit is contained in:
Jfreegman 2015-03-07 00:05:54 -05:00
parent 5859763f04
commit 2bcce234a8
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
5 changed files with 66 additions and 50 deletions

View File

@ -82,9 +82,10 @@ static struct cmd_func chat_commands[] = {
}; };
static struct cmd_func group_commands[] = { static struct cmd_func group_commands[] = {
{ "/topic", cmd_set_topic },
{ "/chatid", cmd_chatid }, { "/chatid", cmd_chatid },
{ "/ignore", cmd_ignore }, { "/ignore", cmd_ignore },
{ "/rejoin", cmd_rejoin },
{ "/topic", cmd_set_topic },
{ "/unignore", cmd_unignore }, { "/unignore", cmd_unignore },
#ifdef AUDIO #ifdef AUDIO
{ "/mute", cmd_mute }, { "/mute", cmd_mute },

View File

@ -29,48 +29,15 @@
#include "log.h" #include "log.h"
#include "groupchat.h" #include "groupchat.h"
void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
if (argc < 1) {
char cur_topic[MAX_STR_SIZE];
int tlen = tox_group_get_topic(m, self->num, (uint8_t *) cur_topic);
if (tlen > 0) {
cur_topic[tlen] = '\0';
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Topic is set to: %s", cur_topic);
} else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Topic is not set");
}
return;
}
const char *topic = argv[1];
if (tox_group_set_topic(m, self->num, (uint8_t *) topic, strlen(topic)) != 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set topic.");
return;
}
char timefrmt[TIME_STR_SIZE];
char selfnick[TOX_MAX_NAME_LENGTH];
get_time_str(timefrmt, sizeof(timefrmt));
int sn_len = tox_group_get_self_name(m, self->num, (uint8_t *) selfnick);
selfnick[sn_len] = '\0';
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, MAGENTA, "-!- You set the topic to: %s", topic);
char tmp_event[MAX_STR_SIZE];
snprintf(tmp_event, sizeof(tmp_event), "set topic to %s", topic);
write_to_log(tmp_event, selfnick, self->chatwin->log, true);
}
void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
char chatid[TOX_GROUP_CHAT_ID_SIZE * 2 + 1] = {0}; char chatid[TOX_GROUP_CHAT_ID_SIZE * 2 + 1] = {0};
char chat_public_key[TOX_GROUP_CHAT_ID_SIZE]; char chat_public_key[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_chat_id(m, self->num, (uint8_t *) chat_public_key);
if (tox_group_get_chat_id(m, self->num, (uint8_t *) chat_public_key) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error retreiving chat id.");
return;
}
size_t i; size_t i;
@ -109,6 +76,51 @@ 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); line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- Ignoring %s", nick);
} }
void cmd_rejoin(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
if (tox_group_reconnect(m, self->num) == -1)
return;
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Reconnecting to group...");
}
void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
if (argc < 1) {
char cur_topic[MAX_STR_SIZE];
int tlen = tox_group_get_topic(m, self->num, (uint8_t *) cur_topic);
if (tlen > 0) {
cur_topic[tlen] = '\0';
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Topic is set to: %s", cur_topic);
} else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Topic is not set");
}
return;
}
const char *topic = argv[1];
if (tox_group_set_topic(m, self->num, (uint8_t *) topic, strlen(topic)) != 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set topic.");
return;
}
char timefrmt[TIME_STR_SIZE];
char selfnick[TOX_MAX_NAME_LENGTH];
get_time_str(timefrmt, sizeof(timefrmt));
int sn_len = tox_group_get_self_name(m, self->num, (uint8_t *) selfnick);
selfnick[sn_len] = '\0';
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, MAGENTA, "-!- You set the topic to: %s", topic);
char tmp_event[MAX_STR_SIZE];
snprintf(tmp_event, sizeof(tmp_event), "set topic to %s", topic);
write_to_log(tmp_event, selfnick, self->chatwin->log, true);
}
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) {

View File

@ -26,9 +26,10 @@
#include "windows.h" #include "windows.h"
#include "toxic.h" #include "toxic.h"
void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_chatid(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]);
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]);
void cmd_rejoin(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_set_topic(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]);
#endif /* GROUP_COMMANDS_H */ #endif /* GROUP_COMMANDS_H */

View File

@ -70,9 +70,9 @@ extern struct user_settings *user_settings;
extern struct Winthread Winthread; extern struct Winthread Winthread;
#ifdef AUDIO #ifdef AUDIO
#define AC_NUM_GROUP_COMMANDS 26 #define AC_NUM_GROUP_COMMANDS 27
#else #else
#define AC_NUM_GROUP_COMMANDS 22 #define AC_NUM_GROUP_COMMANDS 23
#endif /* AUDIO */ #endif /* AUDIO */
/* groupchat command names used for tab completion. */ /* groupchat command names used for tab completion. */
@ -89,16 +89,17 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
{ "/group" }, { "/group" },
{ "/help" }, { "/help" },
{ "/ignore" }, { "/ignore" },
{ "/unignore" },
{ "/join" }, { "/join" },
{ "/log" }, { "/log" },
{ "/myid" }, { "/myid" },
{ "/nick" }, { "/nick" },
{ "/note" }, { "/note" },
{ "/quit" }, { "/quit" },
{ "/rejoin" },
{ "/requests" }, { "/requests" },
{ "/status" }, { "/status" },
{ "/topic" }, { "/topic" },
{ "/unignore" },
#ifdef AUDIO #ifdef AUDIO
@ -546,16 +547,16 @@ static void groupchat_onGroupRejected(ToxWindow *self, Tox *m, int groupnum, uin
switch (type) { switch (type) {
case TOX_GJ_NICK_TAKEN: case TOX_GJ_NICK_TAKEN:
msg = "That nick is already in use. Please change your nick with the '/nick' command."; msg = "Nick already in use. Change your nick and use the 'rejoin' command.";
break; break;
case TOX_GJ_GROUP_FULL: case TOX_GJ_GROUP_FULL:
msg = "Group is full."; msg = "Group is full. Try again with the 'rejoin' command.";
break; break;
case TOX_GJ_INVITES_DISABLED: case TOX_GJ_INVITES_DISABLED:
msg = "Invites for this group have been disabled."; msg = "Invites for this group have been disabled.";
break; break;
case TOX_GJ_INVITE_FAILED: case TOX_GJ_INVITE_FAILED:
msg = "Invite failed."; msg = "Invite failed. Try again with the 'rejoin' command.";
break; break;
default: default:
return; return;

View File

@ -242,9 +242,10 @@ static void help_draw_group(ToxWindow *self)
wprintw(win, "Group commands:\n"); wprintw(win, "Group commands:\n");
wattroff(win, A_BOLD | COLOR_PAIR(RED)); wattroff(win, A_BOLD | COLOR_PAIR(RED));
wprintw(win, " /topic <msg> : Set group topic (show current topic if no msg)\n");
wprintw(win, " /chatid : Print the group chat id to share with others.\n"); wprintw(win, " /chatid : Print the group chat id to share with others.\n");
wprintw(win, " /ignore <nick> : Ignore peer\n"); wprintw(win, " /ignore <nick> : Ignore peer\n");
wprintw(win, " /rejoin : Rejoin the group (only works if not connected)\n");
wprintw(win, " /topic <msg> : Set group topic (show current topic if no msg)\n");
wprintw(win, " /unignore <nick> : Unignore peer \n\n"); wprintw(win, " /unignore <nick> : Unignore peer \n\n");
#ifdef AUDIO #ifdef AUDIO
@ -312,9 +313,9 @@ void help_onKey(ToxWindow *self, wint_t key)
case 'r': case 'r':
#ifdef AUDIO #ifdef AUDIO
help_init_window(self, 13, 80); help_init_window(self, 14, 80);
#else #else
help_init_window(self, 9, 80); help_init_window(self, 10, 80);
#endif #endif
self->help->type = HELP_GROUP; self->help->type = HELP_GROUP;
break; break;