Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Commit

Permalink
Support 140+ chars tweets
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Aug 4, 2020
1 parent 770b6ec commit a4f4666
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Change Log
## Unreleased
- Support over-140-char tweets properly
- Focus on an invisible element with Tab when focusing on the editor
- Since v1.6.7, the focus had unintended behaviors. This fixes the issue of v1.6.7+.

Expand Down
2 changes: 1 addition & 1 deletion src/components/tweet.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class Tweet extends React.Component {
}

autolinkedText(tweet) {
let text = tweet.text;
let text = tweet.full_text || tweet.text; // full_text doesn't appear on search. TODO: make sure full_text is always available

for (let entity of tweet.entities.urls) {
text = text.replace(entity.url, entity.expanded_url);
Expand Down
33 changes: 19 additions & 14 deletions src/utils/twitter-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class TwitterClient {
}

homeTimeline(params, callback) {
this.client.get('statuses/home_timeline', params, (error, tweets, response) => {
this.client.get('statuses/home_timeline', this.extendParams(params), (error, tweets, response) => {
if (error) {
console.log(JSON.stringify(error));
return;
Expand All @@ -44,7 +44,7 @@ export default class TwitterClient {
}

mentionsTimeline(params, callback) {
this.client.get('statuses/mentions_timeline', params, (error, tweets, response) => {
this.client.get('statuses/mentions_timeline', this.extendParams(params), (error, tweets, response) => {
if (error) {
console.log(JSON.stringify(error));
return;
Expand All @@ -54,7 +54,7 @@ export default class TwitterClient {
}

favoritesList(params, callback) {
this.client.get('favorites/list', params, (error, tweets, response) => {
this.client.get('favorites/list', this.extendParams(params), (error, tweets, response) => {
if (error) {
console.log(JSON.stringify(error));
return;
Expand All @@ -64,7 +64,7 @@ export default class TwitterClient {
}

filterStream(track, callback) {
this.client.stream('statuses/filter', { track: track }, (stream) => {
this.client.stream('statuses/filter', this.extendParams({ track: track }), (stream) => {
callback(stream);
});
}
Expand All @@ -86,7 +86,7 @@ Nocturn prohibits over 20 mentions per minute.`);
}
}

this.client.post('statuses/update', params, (error, data, response) => {
this.client.post('statuses/update', this.extendParams(params), (error, data, response) => {
if (data.error) {
TwitterClient.handleError('tweet', data.error);
return;
Expand All @@ -100,7 +100,7 @@ Nocturn prohibits over 20 mentions per minute.`);
}

favoriteStatus(tweetId, callback) {
this.client.post('favorites/create', { id: tweetId }, (error, data, response) => {
this.client.post('favorites/create', this.extendParams({ id: tweetId }), (error, data, response) => {
if (data.error) {
TwitterClient.handleError('favorite', data.error);
return;
Expand All @@ -110,7 +110,7 @@ Nocturn prohibits over 20 mentions per minute.`);
}

unfavoriteStatus(tweetId, callback) {
this.client.post('favorites/destroy', { id: tweetId }, (error, data, response) => {
this.client.post('favorites/destroy', this.extendParams({ id: tweetId }), (error, data, response) => {
if (data.error) {
TwitterClient.handleError('unfavorite', data.error);
return;
Expand All @@ -120,7 +120,7 @@ Nocturn prohibits over 20 mentions per minute.`);
}

retweetStatus(tweetId, callback) {
this.client.post(`statuses/retweet/${tweetId}`, {}, (error, data, response) => {
this.client.post(`statuses/retweet/${tweetId}`, this.extendParams({}), (error, data, response) => {
if (data.error) {
TwitterClient.handleError('retweet', data.error);
return;
Expand All @@ -130,7 +130,7 @@ Nocturn prohibits over 20 mentions per minute.`);
}

deleteStatus(tweetId, callback) {
this.client.post(`statuses/destroy/${tweetId}`, {}, (error, data, response) => {
this.client.post(`statuses/destroy/${tweetId}`, this.extendParams({}), (error, data, response) => {
if (data.error) {
TwitterClient.handleError('delete', data.error);
return;
Expand All @@ -140,7 +140,7 @@ Nocturn prohibits over 20 mentions per minute.`);
}

verifyCredentials(callback) {
this.client.get('account/verify_credentials', {}, (error, data, response) => {
this.client.get('account/verify_credentials', this.extendParams({}), (error, data, response) => {
if (error) {
console.log(JSON.stringify(error));
return;
Expand All @@ -150,7 +150,7 @@ Nocturn prohibits over 20 mentions per minute.`);
}

listsList(callback) {
this.client.get('lists/list', {}, (error, data, response) => {
this.client.get('lists/list', this.extendParams({}), (error, data, response) => {
if (error) {
console.log(JSON.stringify(error));
return;
Expand All @@ -160,7 +160,7 @@ Nocturn prohibits over 20 mentions per minute.`);
}

listStatuses(id, count, callback) {
this.client.get('lists/statuses', { list_id: id, count: count }, (error, tweets, response) => {
this.client.get('lists/statuses', this.extendParams({ list_id: id, count: count }), (error, tweets, response) => {
if (error) {
console.log(JSON.stringify(error));
return;
Expand All @@ -170,7 +170,7 @@ Nocturn prohibits over 20 mentions per minute.`);
}

listStatusesBySlug(owner, slug, count, callback) {
this.client.get('lists/statuses', { owner_screen_name: owner, slug: slug, count: count }, (error, tweets, response) => {
this.client.get('lists/statuses', this.extendParams({ owner_screen_name: owner, slug: slug, count: count }), (error, tweets, response) => {
if (error) {
console.log(JSON.stringify(error));
return;
Expand All @@ -182,7 +182,7 @@ Nocturn prohibits over 20 mentions per minute.`);
searchTweets(query, count, callback) {
if (query === '') return;

this.client.get('search/tweets', { q: query, count: count }, (error, data, response) => {
this.client.get('search/tweets', this.extendParams({ q: query, count: count }), (error, data, response) => {
if (error) {
console.log(JSON.stringify(error));
return;
Expand All @@ -191,6 +191,11 @@ Nocturn prohibits over 20 mentions per minute.`);
});
}

// https://developer.twitter.com/en/docs/tweets/tweet-updates
extendParams(params) {
return Object.assign({}, params, { tweet_mode: 'extended' });
}

static handleError(action, error) {
alert(`Failed to ${action}!
Error: ${JSON.stringify(error)}`);
Expand Down

0 comments on commit a4f4666

Please sign in to comment.