Ignore:
Timestamp:
2012-09-15T16:24:52Z (12 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
ddca104
Parents:
b3d99e3
Message:

Merge Twitter favourite command from Flexo/#983. Leaving out the unfavourite
command for reasons given there.

At this point there are loads of command and stuff is getting a little messy
maybe.. :-/

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter.c

    rb3d99e3 rb61c74c  
    490490}
    491491
     492/** Convert the given bitlbee tweet ID, bitlbee username, or twitter tweet ID
     493 *  into a twitter tweet ID.
     494 *
     495 *  Returns 0 if the user provides garbage.
     496 */
     497static guint64 twitter_message_id_from_command_arg(struct im_connection *ic, struct twitter_data *td, char *arg) {
     498        struct twitter_user_data *tud;
     499        bee_user_t *bu;
     500        guint64 id = 0;
     501        if (g_str_has_prefix(arg, "#") &&
     502                sscanf(arg + 1, "%" G_GUINT64_FORMAT, &id) == 1) {
     503                if (id < TWITTER_LOG_LENGTH && td->log)
     504                        id = td->log[id].id;
     505        } else if ((bu = bee_user_by_handle(ic->bee, ic, arg)) &&
     506                (tud = bu->data) && tud->last_id)
     507                id = tud->last_id;
     508        else if (sscanf(arg, "%" G_GUINT64_FORMAT, &id) == 1){
     509                if (id < TWITTER_LOG_LENGTH && td->log)
     510                        id = td->log[id].id;
     511        }
     512        return id;
     513}
     514
    492515static void twitter_handle_command(struct im_connection *ic, char *message)
    493516{
     
    517540                        twitter_msg(ic, "Could not undo last action");
    518541
     542                g_free(cmds);
     543                return;
     544        } else if (g_strcasecmp(cmd[0], "favourite") == 0 && cmd[1]) {
     545                guint64 id;
     546                if ((id = twitter_message_id_from_command_arg(ic, td, cmd[1]))) {
     547                        twitter_favourite_tweet(ic, id);
     548                } else {
     549                        twitter_msg(ic, "Please provide a message ID or username.");
     550                }
    519551                g_free(cmds);
    520552                return;
     
    546578                return;
    547579        } else if (g_strcasecmp(cmd[0], "rt") == 0 && cmd[1]) {
    548                 struct twitter_user_data *tud;
    549                 bee_user_t *bu;
    550                 guint64 id;
    551 
    552                 if (g_str_has_prefix(cmd[1], "#") &&
    553                     sscanf(cmd[1] + 1, "%" G_GUINT64_FORMAT, &id) == 1) {
    554                         if (id < TWITTER_LOG_LENGTH && td->log)
    555                                 id = td->log[id].id;
    556                 } else if ((bu = bee_user_by_handle(ic->bee, ic, cmd[1])) &&
    557                     (tud = bu->data) && tud->last_id)
    558                         id = tud->last_id;
    559                 else if (sscanf(cmd[1], "%" G_GUINT64_FORMAT, &id) == 1){
    560                         if (id < TWITTER_LOG_LENGTH && td->log)
    561                                 id = td->log[id].id;
    562                 }
     580                guint64 id = twitter_message_id_from_command_arg(ic, td, cmd[1]);
    563581
    564582                td->last_status_id = 0;
Note: See TracChangeset for help on using the changeset viewer.