Permalink
Browse files

Fix #584. Read image preview URLs from entities

Previously, the code that generates image previews reads URLs from the
tweet body text. This worked before as the t.co URLs were expanded
before image previews are processed. However, the t.co expansion code
was moved to after the image preview code in a previous bugfix, breaking
the image preview functionality for URLs.

To fix this, the image preview code now reads the URLs directly from the
entities provided by Twitter, instead of reading it from tweet body.
  • Loading branch information...
Volvagia356 committed Aug 12, 2015
1 parent 0081461 commit 452fc0924a98923bdcea33a5c0eaadcb18981f4c
Showing with 48 additions and 44 deletions.
  1. +48 −44 data/js/ui.template.js
@@ -1276,52 +1276,56 @@ form_preview:
function form_preview(tweet) {
var html_arr = [];
var link_reg = ui.Template.preview_link_reg;
urls = tweet.entities.urls
for (var pvd_name in link_reg) {
var match = link_reg[pvd_name].reg.exec(tweet.text);
while (match != null) {
switch (pvd_name) {
case 'img.ly':
case 'twitgoo.com':
html_arr.push(
ui.Template.form_media(
match[0], link_reg[pvd_name].base + match[1],
link_reg[pvd_name].direct_base + match[1]));
break;
case 'twitpic.com':
html_arr.push(
ui.Template.form_media(
match[0], link_reg[pvd_name].base + match[1]));
break;
case 'instagr.am':
html_arr.push(
ui.Template.form_media(
match[0], match[0] + link_reg[pvd_name].tail,
match[0] + link_reg[pvd_name].direct_tail));
break;
case 'yfrog.com':
case 'moby.to':
case 'picplz.com':
html_arr.push(
ui.Template.form_media(
match[0], match[0] + link_reg[pvd_name].tail));
break;
case 'plixi.com':
html_arr.push(
ui.Template.form_media(
match[0], link_reg[pvd_name].base +match[0]));
break;
case 'raw':
html_arr.push(
ui.Template.form_media(
match[0], match[0], match[0]));
break;
case 'youtube.com':
html_arr.push(
ui.Template.form_media(
match[0], link_reg[pvd_name].base + match[2] + link_reg[pvd_name].tail));
break;
for (var i = 0, l = urls.length; i < l; i += 1) {
var url = urls[i]
var match = link_reg[pvd_name].reg.exec(url.expanded_url);
while (match != null) {
switch (pvd_name) {
case 'img.ly':
case 'twitgoo.com':
html_arr.push(
ui.Template.form_media(
match[0], link_reg[pvd_name].base + match[1],
link_reg[pvd_name].direct_base + match[1]));
break;
case 'twitpic.com':
html_arr.push(
ui.Template.form_media(
match[0], link_reg[pvd_name].base + match[1]));
break;
case 'instagr.am':
html_arr.push(
ui.Template.form_media(
match[0], match[0] + link_reg[pvd_name].tail,
match[0] + link_reg[pvd_name].direct_tail));
break;
case 'yfrog.com':
case 'moby.to':
case 'picplz.com':
html_arr.push(
ui.Template.form_media(
match[0], match[0] + link_reg[pvd_name].tail));
break;
case 'plixi.com':
html_arr.push(
ui.Template.form_media(
match[0], link_reg[pvd_name].base +match[0]));
break;
case 'raw':
html_arr.push(
ui.Template.form_media(
match[0], match[0], match[0]));
break;
case 'youtube.com':
html_arr.push(
ui.Template.form_media(
match[0], link_reg[pvd_name].base + match[2] + link_reg[pvd_name].tail));
break;
}
match = link_reg[pvd_name].reg.exec(url.expanded_url);
}
match = link_reg[pvd_name].reg.exec(tweet.text);
}
}
// twitter official picture service

0 comments on commit 452fc09

Please sign in to comment.