Bug 1314435 - Add like action to tweets. r=clokep

This commit is contained in:
freaktechnik 2016-11-01 20:56:56 +00:00
Родитель da72306be5
Коммит 1fb45b396b
2 изменённых файлов: 24 добавлений и 0 удалений

Просмотреть файл

@ -17,6 +17,8 @@ error.tooLong=Status is over 140 characters.
error.general=An error %1$S occurred while sending: %2$S
error.retweet=An error %1$S occurred while retweeting: %2$S
error.delete=An error %1$S occurred while deleting: %2$S
error.like=An error %1$S occured while liking: %2$S
error.unlike=An error %1$S occured while unliking: %2$S
# LOCALIZATION NOTE (error.descriptionTooLong)
# %S is the truncated string that was sent to the server.
error.descriptionTooLong=Description is over the maximum length (160 characters), it was automatically truncated to: %S.
@ -36,6 +38,8 @@ action.delete=Delete
# %S will be replaced by the screen name of a twitter user.
action.follow=Follow %S
action.stopFollowing=Stop following %S
action.like=Like
action.unlike=Remove Like
# LOCALIZATION NOTE (event.follow, event.unfollow, event.followed):
# This will be displayed in system messages inside the timeline conversation.

Просмотреть файл

@ -78,6 +78,11 @@ Tweet.prototype = {
let screenName = this._tweet.user.screen_name;
actions.push(new Action(_("action." + action, screenName),
function() { account[action](screenName); }));
const favAction = this._tweet.favorited ? "unlike" : "like";
actions.push(new Action(_("action." + favAction), () => {
this.conversation.like(this._tweet, this._tweet.favorited);
}, this));
}
else if (this.outgoing && !this._deleted) {
actions.push(
@ -392,6 +397,15 @@ TimelineConversation.prototype = {
}, this);
this.sendTyping("");
},
like: function(aTweet, aRemoveLike = false) {
this._account.like(aTweet, aRemoveLike, function() {
aTweet.favorited = !aRemoveLike;
}, function(aException, aData) {
const messageName = aRemoveLike ? "unlike" : "like";
this.systemMessage(_("error." + messageName,
this.parseError(aData), aTweet.text), true);
}, this);
},
sendTyping: function(aString) {
if (aString.length == 0 && this.inReplyToStatusId) {
delete this.inReplyToStatusId;
@ -662,6 +676,12 @@ Account.prototype = {
this.signAndSend("1.1/direct_messages/new.json", null, POSTData, aOnSent,
aOnError, aThis);
},
like: function(aTweet, aRemoveLike, aOnSent, aOnError, aThis) {
const action = aRemoveLike ? "destroy" : "create";
const url = `1.1/favorites/${action}.json`;
const POSTData = [["id", aTweet.id_str]];
this.signAndSend(url, null, POSTData, aOnSent, aOnError, aThis);
},
_friends: null,
follow: function(aUserName) {