aboutsummaryrefslogtreecommitdiffstats
path: root/root_commands.c
diff options
context:
space:
mode:
authorjgeboski <jgeboski@gmail.com>2016-06-22 14:54:52 -0400
committerMarius Halden <marius.h@lden.org>2016-06-29 22:22:10 +0200
commitb3f154dd5c4d14fb0b466ffe347084ae7eac2295 (patch)
treec5861e51c0f74e4735cbac8594d4ef6984f31218 /root_commands.c
parent311758008fbbe3eed1f50fdea4dc62644df9e455 (diff)
Added an interface for the listing of existing chatrooms
Several protocols can provide a list of existing chatrooms that a user is able join. This is crucial for the usage of several protocols, most notably Purple and Facebook. Plugins wishing to support this extended functionality must implement the new prpl->chat_list() function. This implemented function will in most cases send a remote request for the list of chatrooms. Once the list of chatrooms is obtained, a bee_chat_info_t GSList must be created and assigned to the im_connection->chatlist field. Then a call to the bee_chat_list_finish() is needed to display the list to the user. The chat list is maintained entirely by the plugin, so it is important to ensure all pointers related to the chat list remain valid until the chat list is set to NULL. This list is used internally by bitlbee to calculate indexes, which then allows the user to join a chat with an index, rather than some random identifier. It also important to ensure the list is properly freed whenever it is updated, or when the account is disconnect via the prpl->logout() function. On the user interface side of things, the 'chat list' subcommand was recommissioned. For a user to list the existing chat rooms: chat list <account id> Afterwards a user can join a chatroom in the list with its index. This extends the functionality of the 'chat add' subcommand by adding in support for the exclamation point operator to denote an index. chat add <account id> !<index> [channel]
Diffstat (limited to 'root_commands.c')
-rw-r--r--root_commands.c80
1 files changed, 75 insertions, 5 deletions
diff --git a/root_commands.c b/root_commands.c
index 9acc30f0..86133244 100644
--- a/root_commands.c
+++ b/root_commands.c
@@ -1217,8 +1217,10 @@ static void cmd_chat(irc_t *irc, char **cmd)
account_t *acc;
if (g_strcasecmp(cmd[1], "add") == 0) {
- char *channel, *s;
+ bee_chat_info_t *ci;
+ char *channel, *room, *s;
struct irc_channel *ic;
+ guint i;
MIN_ARGS(3);
@@ -1230,8 +1232,22 @@ static void cmd_chat(irc_t *irc, char **cmd)
return;
}
+ if (cmd[3][0] == '!') {
+ i = g_ascii_strtoull(cmd[3] + 1, NULL, 10);
+ ci = g_slist_nth_data(acc->ic->chatlist, i - 1);
+
+ if (ci == NULL) {
+ irc_rootmsg(irc, "Invalid chatroom index");
+ return;
+ }
+
+ room = ci->title;
+ } else {
+ room = cmd[3];
+ }
+
if (cmd[4] == NULL) {
- channel = g_strdup(cmd[3]);
+ channel = g_strdup(room);
if ((s = strchr(channel, '@'))) {
*s = 0;
}
@@ -1251,7 +1267,7 @@ static void cmd_chat(irc_t *irc, char **cmd)
set_setstr(&ic->set, "type", "chat") &&
set_setstr(&ic->set, "chat_type", "room") &&
set_setstr(&ic->set, "account", cmd[2]) &&
- set_setstr(&ic->set, "room", cmd[3])) {
+ set_setstr(&ic->set, "room", room)) {
irc_rootmsg(irc, "Chatroom successfully added.");
} else {
if (ic) {
@@ -1261,6 +1277,18 @@ static void cmd_chat(irc_t *irc, char **cmd)
irc_rootmsg(irc, "Could not add chatroom.");
}
g_free(channel);
+ } else if (g_strcasecmp(cmd[1], "list") == 0) {
+ MIN_ARGS(2);
+
+ if (!(acc = account_get(irc->b, cmd[2]))) {
+ irc_rootmsg(irc, "Invalid account");
+ return;
+ } else if (!acc->prpl->chat_list) {
+ irc_rootmsg(irc, "Existing chatrooms not supported on that account.");
+ return;
+ }
+
+ acc->prpl->chat_list(acc->ic, cmd[3]);
} else if (g_strcasecmp(cmd[1], "with") == 0) {
irc_user_t *iu;
@@ -1275,8 +1303,7 @@ static void cmd_chat(irc_t *irc, char **cmd)
} else {
irc_rootmsg(irc, "Can't open a groupchat with %s.", cmd[2]);
}
- } else if (g_strcasecmp(cmd[1], "list") == 0 ||
- g_strcasecmp(cmd[1], "set") == 0 ||
+ } else if (g_strcasecmp(cmd[1], "set") == 0 ||
g_strcasecmp(cmd[1], "del") == 0) {
irc_rootmsg(irc,
"Warning: The \002chat\002 command was mostly replaced with the \002channel\002 command.");
@@ -1288,6 +1315,49 @@ static void cmd_chat(irc_t *irc, char **cmd)
}
}
+void cmd_chat_list_finish(struct im_connection *ic)
+{
+ account_t *acc = ic->acc;
+ bee_chat_info_t *ci;
+ char *hformat, *iformat, *topic;
+ GSList *l;
+ GString *userc;
+ guint i = 0;
+ irc_t *irc = ic->bee->ui_data;
+
+ if (ic->chatlist == NULL) {
+ irc_rootmsg(irc, "No existing chatrooms");
+ return;
+ }
+
+ if (strchr(irc->umode, 'b') != NULL) {
+ hformat = "%s\t%s\t%s\t%s";
+ iformat = "%u\t%s\t%s\t%s";
+ } else {
+ hformat = "%s %-20s %s %s";
+ iformat = "%5u %-20.20s %5s %s";
+ }
+
+ irc_rootmsg(irc, hformat, "Index", "Title", "Users", "Topic");
+ userc = g_string_new(NULL);
+
+ for (l = ic->chatlist; l; l = l->next) {
+ ci = l->data;
+ topic = ci->topic ? ci->topic : "";
+
+ if (ci->userc >= 0) {
+ g_string_printf(userc, "%d", ci->userc);
+ } else {
+ g_string_assign(userc, "-");
+ }
+
+ irc_rootmsg(irc, iformat, ++i, ci->title, userc->str, topic);
+ }
+
+ irc_rootmsg(irc, "%u %s chatrooms", i, acc->tag);
+ g_string_free(userc, TRUE);
+}
+
static void cmd_group(irc_t *irc, char **cmd)
{
GSList *l;