mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 23:13:25 +00:00
Add support to linkify links and mentions on twitter
This converts links in tweets to a tags. We also convert the displayed text to the target of the twitter short URL. Mentions are linked to the users twitter page. (imported from commit 192d5546a7eea82759f9ae30d82c102aed15ff71)
This commit is contained in:
committed by
Waseem Daher
parent
45d3bb4f04
commit
1352dccea5
@@ -2,10 +2,8 @@ from __future__ import absolute_import
|
||||
|
||||
import ujson
|
||||
|
||||
def twitter(tweet_id):
|
||||
if tweet_id not in ["112652479837110273", "287977969287315456", "287977969287315457"]:
|
||||
return None
|
||||
return ujson.loads("""{
|
||||
|
||||
NORMAL_TWEET = """{
|
||||
"coordinates": null,
|
||||
"created_at": "Sat Sep 10 22:23:38 +0000 2011",
|
||||
"truncated": false,
|
||||
@@ -62,5 +60,109 @@ def twitter(tweet_id):
|
||||
"show_all_inline_media": false
|
||||
},
|
||||
"in_reply_to_screen_name": "twitter",
|
||||
"in_reply_to_status_id": null
|
||||
}""")
|
||||
"in_reply_to_status_id": null,
|
||||
"user_mentions": [
|
||||
{
|
||||
"screen_name": "twitter",
|
||||
"name": "Twitter",
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"screen_name": "seepicturely",
|
||||
"name": "Seepicturely",
|
||||
"id": 2
|
||||
},
|
||||
{
|
||||
"screen_name": "boscomonkey",
|
||||
"name": "Bosco So",
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"screen_name": "episod",
|
||||
"name": "Taylor Singletary",
|
||||
"id": 4
|
||||
}
|
||||
],
|
||||
"urls": {
|
||||
"http://t.co/6J2EgYM": "http://instagram.com/p/MuW67/"
|
||||
}
|
||||
}"""
|
||||
|
||||
MENTION_IN_LINK_TWEET = """{
|
||||
"coordinates": null,
|
||||
"created_at": "Sat Sep 10 22:23:38 +0000 2011",
|
||||
"truncated": false,
|
||||
"favorited": false,
|
||||
"id_str": "112652479837110273",
|
||||
"in_reply_to_user_id_str": "783214",
|
||||
"text": "http://t.co/@foo",
|
||||
"contributors": null,
|
||||
"id": 112652479837110273,
|
||||
"retweet_count": 0,
|
||||
"in_reply_to_status_id_str": null,
|
||||
"geo": null,
|
||||
"retweeted": false,
|
||||
"possibly_sensitive": false,
|
||||
"in_reply_to_user_id": 783214,
|
||||
"user": {
|
||||
"profile_sidebar_border_color": "eeeeee",
|
||||
"profile_background_tile": true,
|
||||
"profile_sidebar_fill_color": "efefef",
|
||||
"name": "Eoin McMillan ",
|
||||
"profile_image_url": "http://a1.twimg.com/profile_images/1380912173/Screen_shot_2011-06-03_at_7.35.36_PM_normal.png",
|
||||
"created_at": "Mon May 16 20:07:59 +0000 2011",
|
||||
"location": "Twitter",
|
||||
"profile_link_color": "009999",
|
||||
"follow_request_sent": null,
|
||||
"is_translator": false,
|
||||
"id_str": "299862462",
|
||||
"favourites_count": 0,
|
||||
"default_profile": false,
|
||||
"url": "http://www.eoin.me",
|
||||
"contributors_enabled": false,
|
||||
"id": 299862462,
|
||||
"utc_offset": null,
|
||||
"profile_image_url_https": "https://si0.twimg.com/profile_images/1380912173/Screen_shot_2011-06-03_at_7.35.36_PM_normal.png",
|
||||
"profile_use_background_image": true,
|
||||
"listed_count": 0,
|
||||
"followers_count": 9,
|
||||
"lang": "en",
|
||||
"profile_text_color": "333333",
|
||||
"protected": false,
|
||||
"profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme14/bg.gif",
|
||||
"description": "Eoin's photography account. See @mceoin for tweets.",
|
||||
"geo_enabled": false,
|
||||
"verified": false,
|
||||
"profile_background_color": "131516",
|
||||
"time_zone": null,
|
||||
"notifications": null,
|
||||
"statuses_count": 255,
|
||||
"friends_count": 0,
|
||||
"default_profile_image": false,
|
||||
"profile_background_image_url": "http://a1.twimg.com/images/themes/theme14/bg.gif",
|
||||
"screen_name": "imeoin",
|
||||
"following": null,
|
||||
"show_all_inline_media": false
|
||||
},
|
||||
"in_reply_to_screen_name": "twitter",
|
||||
"in_reply_to_status_id": null,
|
||||
"user_mentions": [
|
||||
{
|
||||
"screen_name": "foo",
|
||||
"name": "Foo",
|
||||
"id": 1
|
||||
}
|
||||
],
|
||||
"urls": {
|
||||
"http://t.co/@foo": "http://foo.com"
|
||||
}
|
||||
}"""
|
||||
|
||||
|
||||
def twitter(tweet_id):
|
||||
if tweet_id in ["112652479837110273", "287977969287315456", "287977969287315457"]:
|
||||
return ujson.loads(NORMAL_TWEET)
|
||||
elif tweet_id == "287977969287315458":
|
||||
return ujson.loads(MENTION_IN_LINK_TWEET)
|
||||
else:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user