Changeset a33ee0f for root_commands.c


Ignore:
Timestamp:
2016-09-20T03:39:05Z (3 years ago)
Author:
jgeboski <jgeboski@…>
Branches:
master
Children:
725f942
Parents:
67ea361
git-author:
jgeboski <jgeboski@…> (22-06-16 18:54:52)
git-committer:
jgeboski <jgeboski@…> (20-09-16 03:39:05)
Message:

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]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • root_commands.c

    r67ea361 ra33ee0f  
    12181218
    12191219        if (g_strcasecmp(cmd[1], "add") == 0) {
    1220                 char *channel, *s;
     1220                bee_chat_info_t *ci;
     1221                char *channel, *room, *s;
    12211222                struct irc_channel *ic;
     1223                guint i;
    12221224
    12231225                MIN_ARGS(3);
     
    12311233                }
    12321234
     1235                if (cmd[3][0] == '!') {
     1236                        if (!acc->prpl->chat_list) {
     1237                                irc_rootmsg(irc, "Listing chatrooms not supported on that account.");
     1238                                return;
     1239                        }
     1240
     1241                        i = g_ascii_strtoull(cmd[3] + 1, NULL, 10);
     1242                        ci = g_slist_nth_data(acc->ic->chatlist, i - 1);
     1243
     1244                        if (ci == NULL) {
     1245                                irc_rootmsg(irc, "Invalid chatroom index");
     1246                                return;
     1247                        }
     1248
     1249                        room = ci->title;
     1250                } else {
     1251                        room = cmd[3];
     1252                }
     1253
    12331254                if (cmd[4] == NULL) {
    1234                         channel = g_strdup(cmd[3]);
     1255                        channel = g_strdup(room);
    12351256                        if ((s = strchr(channel, '@'))) {
    12361257                                *s = 0;
     
    12521273                    set_setstr(&ic->set, "chat_type", "room") &&
    12531274                    set_setstr(&ic->set, "account", cmd[2]) &&
    1254                     set_setstr(&ic->set, "room", cmd[3])) {
     1275                    set_setstr(&ic->set, "room", room)) {
    12551276                        irc_rootmsg(irc, "Chatroom successfully added.");
    12561277                } else {
     
    12621283                }
    12631284                g_free(channel);
     1285        } else if (g_strcasecmp(cmd[1], "list") == 0) {
     1286                MIN_ARGS(2);
     1287
     1288                if (!(acc = account_get(irc->b, cmd[2]))) {
     1289                        irc_rootmsg(irc, "Invalid account");
     1290                        return;
     1291                } else if (!acc->prpl->chat_list) {
     1292                        irc_rootmsg(irc, "Listing chatrooms not supported on that account.");
     1293                        return;
     1294                }
     1295
     1296                acc->prpl->chat_list(acc->ic, cmd[3]);
    12641297        } else if (g_strcasecmp(cmd[1], "with") == 0) {
    12651298                irc_user_t *iu;
     
    12761309                        irc_rootmsg(irc, "Can't open a groupchat with %s.", cmd[2]);
    12771310                }
    1278         } else if (g_strcasecmp(cmd[1], "list") == 0 ||
    1279                    g_strcasecmp(cmd[1], "set") == 0 ||
     1311        } else if (g_strcasecmp(cmd[1], "set") == 0 ||
    12801312                   g_strcasecmp(cmd[1], "del") == 0) {
    12811313                irc_rootmsg(irc,
     
    12871319                            cmd[1]);
    12881320        }
     1321}
     1322
     1323void cmd_chat_list_finish(struct im_connection *ic)
     1324{
     1325        account_t *acc = ic->acc;
     1326        bee_chat_info_t *ci;
     1327        char *hformat, *iformat, *topic;
     1328        GSList *l;
     1329        guint i = 0;
     1330        irc_t *irc = ic->bee->ui_data;
     1331
     1332        if (ic->chatlist == NULL) {
     1333                irc_rootmsg(irc, "No existing chatrooms");
     1334                return;
     1335        }
     1336
     1337        if (strchr(irc->umode, 'b') != NULL) {
     1338                hformat = "%s\t%s\t%s";
     1339                iformat = "%u\t%s\t%s";
     1340        } else {
     1341                hformat = "%s  %-20s  %s";
     1342                iformat = "%5u  %-20.20s  %s";
     1343        }
     1344
     1345        irc_rootmsg(irc, hformat, "Index", "Title", "Topic");
     1346
     1347        for (l = ic->chatlist; l; l = l->next) {
     1348                ci = l->data;
     1349                topic = ci->topic ? ci->topic : "";
     1350                irc_rootmsg(irc, iformat, ++i, ci->title, topic);
     1351        }
     1352
     1353        irc_rootmsg(irc, "%u %s chatrooms", i, acc->tag);
    12891354}
    12901355
Note: See TracChangeset for help on using the changeset viewer.