blob: 4b6f65e8d1358506653c3d0f2cfa1fa6aa1efbc5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
class Retweet < ActiveRecord::Base
belongs_to :tweet
belongs_to :user
after_create do
Tweet.update_counters(self.tweet_id, retweets_count: 1, reactions_count: 1)
end
after_destroy do
Tweet.update_counters(self.tweet_id, retweets_count: -1, reactions_count: -1)
end
def self.from_json(json)
tweet = Tweet.from_json(json[:retweeted_status])
user = User.from_json(json[:user])
retweet = Retweet.new(id: json[:id], tweet: tweet, user: user)
if retweet.save
logger.debug("Successfully created a retweet: #{retweet.id}")
else
logger.debug("Failed to create a retweet: #{retweet}")
end
retweet
end
end
|