Ignore:
Timestamp:
2015-05-04T21:58:50Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
5726a0d
Parents:
531eabd (diff), 5ca1416 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Catch up with master.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter_lib.c

    r531eabd rb1dc403  
    460460#endif
    461461
    462 static char* expand_entities(char* text, const json_value *entities);
     462static void expand_entities(char **text, const json_value *node);
    463463
    464464/**
     
    473473{
    474474        struct twitter_xml_status *txs;
    475         const json_value *rt = NULL, *entities = NULL;
     475        const json_value *rt = NULL;
    476476
    477477        if (node->type != json_object) {
     
    501501                } else if (strcmp("in_reply_to_status_id", k) == 0 && v->type == json_integer) {
    502502                        txs->reply_to = v->u.integer;
    503                 } else if (strcmp("entities", k) == 0 && v->type == json_object) {
    504                         entities = v;
    505503                }
    506504        }
     
    516514                        txs_free(rtxs);
    517515                }
    518         } else if (entities) {
    519                 txs->text = expand_entities(txs->text, entities);
     516        } else {
     517                expand_entities(&txs->text, node);
    520518        }
    521519
     
    534532{
    535533        struct twitter_xml_status *txs;
    536         const json_value *entities = NULL;
    537534
    538535        if (node->type != json_object) {
     
    561558        }
    562559
    563         if (entities) {
    564                 txs->text = expand_entities(txs->text, entities);
    565         }
     560        expand_entities(&txs->text, node);
    566561
    567562        if (txs->text && txs->user && txs->id) {
     
    573568}
    574569
    575 static char* expand_entities(char* text, const json_value *entities)
    576 {
     570static void expand_entities(char **text, const json_value *node)
     571{
     572        json_value *entities, *quoted;
     573        char *quote_url = NULL, *quote_text = NULL;
     574
     575        if (!((entities = json_o_get(node, "entities")) && entities->type == json_object))
     576                return;
     577        if ((quoted = json_o_get(node, "quoted_status")) && quoted->type == json_object) {
     578                /* New "retweets with comments" feature. Note that this info
     579                 * seems to be included in the streaming API only! Grab the
     580                 * full message and try to insert it when we run into the
     581                 * Tweet entity. */
     582                struct twitter_xml_status *txs = twitter_xt_get_status(quoted);
     583                quote_text = g_strdup_printf("@%s: %s", txs->user->screen_name, txs->text);
     584                quote_url = g_strdup_printf("%s/status/%" G_GUINT64_FORMAT, txs->user->screen_name, txs->id);
     585                txs_free(txs);
     586        } else {
     587                quoted = NULL;
     588        }
     589
    577590        JSON_O_FOREACH(entities, k, v) {
    578591                int i;
     
    586599
    587600                for (i = 0; i < v->u.array.length; i++) {
     601                        const char *format = "%s%s <%s>%s";
     602
    588603                        if (v->u.array.values[i]->type != json_object) {
    589604                                continue;
     
    592607                        const char *kort = json_o_str(v->u.array.values[i], "url");
    593608                        const char *disp = json_o_str(v->u.array.values[i], "display_url");
     609                        const char *full = json_o_str(v->u.array.values[i], "expanded_url");
    594610                        char *pos, *new;
    595611
    596                         if (!kort || !disp || !(pos = strstr(text, kort))) {
     612                        if (!kort || !disp || !(pos = strstr(*text, kort))) {
    597613                                continue;
    598614                        }
     615                        if (quote_url && strstr(full, quote_url)) {
     616                                format = "%s<%s> [%s]%s";
     617                                disp = quote_text;
     618                        }
    599619
    600620                        *pos = '\0';
    601                         new = g_strdup_printf("%s%s <%s>%s", text, kort,
     621                        new = g_strdup_printf(format, *text, kort,
    602622                                              disp, pos + strlen(kort));
    603623
    604                         g_free(text);
    605                         text = new;
    606                 }
    607         }
    608 
    609         return text;
     624                        g_free(*text);
     625                        *text = new;
     626                }
     627        }
     628        g_free(quote_text);
     629        g_free(quote_url);
    610630}
    611631
     
    681701        if (g_strcasecmp(txs->user->screen_name, td->user) == 0) {
    682702                td->log[td->log_id].id = txs->rt_id;
     703                /* More useful than NULL. */
     704                td->log[td->log_id].bu = &twitter_log_local_user;
    683705        }
    684706
     
    832854
    833855        last_id_str = g_strdup_printf("%" G_GUINT64_FORMAT, td->timeline_id);
    834         set_setstr(&ic->acc->set, "last_tweet", last_id_str);
     856        set_setstr(&ic->acc->set, "_last_tweet", last_id_str);
    835857        g_free(last_id_str);
    836858}
     
    862884
    863885                imcb_error(ic, "Stream closed (%s)", req->status_string);
     886                if (req->status_code == 401) {
     887                        imcb_error(ic, "Check your system clock.");
     888                }
    864889                imc_logout(ic, TRUE);
    865890                return;
Note: See TracChangeset for help on using the changeset viewer.