Changeset b61c74c for protocols


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.. :-/

Location:
protocols/twitter
Files:
3 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;
  • protocols/twitter/twitter_lib.c

    rb3d99e3 rb61c74c  
    10831083                     ic, 1, args, 2);
    10841084}
     1085
     1086/**
     1087 * Favourite a tweet.
     1088 */
     1089void twitter_favourite_tweet(struct im_connection *ic, guint64 id)
     1090{
     1091        char *url;
     1092        url = g_strdup_printf("%s%llu%s", TWITTER_FAVORITE_CREATE_URL,
     1093                              (unsigned long long) id, ".xml");
     1094        twitter_http(ic, url, twitter_http_post, ic, 1, NULL, 0);
     1095        g_free(url);
     1096}
  • protocols/twitter/twitter_lib.h

    rb3d99e3 rb61c74c  
    9191void twitter_status_retweet(struct im_connection *ic, guint64 id);
    9292void twitter_report_spam(struct im_connection *ic, char *screen_name);
     93void twitter_favourite_tweet(struct im_connection *ic, guint64 id);
    9394
    9495#endif //_TWITTER_LIB_H
Note: See TracChangeset for help on using the changeset viewer.