Changeset a33ee0f


Ignore:
Timestamp:
2016-09-20T03:39:05Z (8 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]

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • bitlbee.h

    r67ea361 ra33ee0f  
    173173gboolean root_command_add(const char *command, int params, void (*func)(irc_t *, char **args), int flags);
    174174gboolean cmd_identify_finish(gpointer data, gint fd, b_input_condition cond);
     175void cmd_chat_list_finish(struct im_connection *ic);
    175176gboolean bitlbee_shutdown(gpointer data, gint fd, b_input_condition cond);
    176177
  • doc/user-guide/commands.xml

    r67ea361 ra33ee0f  
    264264
    265265                <bitlbee-command name="add">
    266                         <syntax>chat add &lt;account id&gt; &lt;room&gt; [&lt;channel&gt;]</syntax>
     266                        <syntax>chat add &lt;account id&gt; &lt;room|!index&gt; [&lt;channel&gt;]</syntax>
    267267
    268268                        <description>
     
    280280                        </description>
    281281
     282                </bitlbee-command>
     283
     284                <bitlbee-command name="list">
     285                        <syntax>chat list &lt;account id&gt; [&lt;server&gt;]</syntax>
     286
     287                        <description>
     288                                <para>
     289                                        List existing chatrooms provided by an account. BitlBee needs this to propogate an internal list of chats. The existing chat can then be added with <emphasis>chat add</emphasis>.
     290                                </para>
     291                        </description>
    282292                </bitlbee-command>
    283293
  • protocols/bee.h

    r67ea361 ra33ee0f  
    8383        void *data; /* Can be used by the IM module. */
    8484} bee_user_t;
     85
     86typedef struct bee_chat_info {
     87        char *title;
     88        char *topic;
     89} bee_chat_info_t;
    8590
    8691/* This one's mostly used so save space and make it easier (cheaper) to
     
    185190G_MODULE_EXPORT void imcb_chat_invite(struct im_connection *ic, const char *name, const char *who, const char *msg);
    186191
     192G_MODULE_EXPORT void bee_chat_list_finish(struct im_connection *ic);
     193
    187194#endif /* __BEE_H__ */
  • protocols/bee_chat.c

    r67ea361 ra33ee0f  
    274274        }
    275275}
     276
     277void bee_chat_list_finish(struct im_connection *ic)
     278{
     279        cmd_chat_list_finish(ic);
     280}
  • protocols/nogaim.h

    r67ea361 ra33ee0f  
    9696
    9797        GSList *groupchats;
     98        GSList *chatlist;
    9899};
    99100
     
    263264        gboolean (* handle_is_self) (struct im_connection *, const char *who);
    264265
     266        /* This sets/updates the im_connection->chatlist field with a
     267         * bee_chat_info_t GSList. This function should ensure the
     268         * bee_chat_list_finish() function gets called at some point
     269         * after the chat list is completely updated.
     270         */
     271        void (* chat_list) (struct im_connection *, const char *server);
     272
    265273        /* Some placeholders so eventually older plugins may cooperate with newer BitlBees. */
    266274        void *resv1;
  • 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.