2016-11-15 15:56:29 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-06 11:51:55 +00:00
|
|
|
class FavouriteService < BaseService
|
2017-05-29 16:22:22 +00:00
|
|
|
include Authorization
|
2019-06-04 21:11:18 +00:00
|
|
|
include Payloadable
|
2017-05-29 16:22:22 +00:00
|
|
|
|
2016-03-06 11:51:55 +00:00
|
|
|
# Favourite a status and notify remote user
|
|
|
|
# @param [Account] account
|
|
|
|
# @param [Status] status
|
|
|
|
# @return [Favourite]
|
|
|
|
def call(account, status)
|
2018-05-02 13:50:20 +00:00
|
|
|
authorize_with account, status, :favourite?
|
2016-12-29 19:33:26 +00:00
|
|
|
|
2017-06-08 13:07:39 +00:00
|
|
|
favourite = Favourite.find_by(account: account, status: status)
|
|
|
|
|
|
|
|
return favourite unless favourite.nil?
|
|
|
|
|
2016-03-06 11:51:55 +00:00
|
|
|
favourite = Favourite.create!(account: account, status: status)
|
Re-add follow recommendations API (#7918)
* Re-add follow recommendations API
GET /api/v1/suggestions
Removed in 30f9e9e624b044f021fd0d345e4b1ea189978479 due to Neo4J
dependency. The algorithm uses triadic closures, takes into account
suspensions, blocks, mutes, domain blocks, excludes locked and moved
accounts, and prefers more recently updated accounts.
* Track interactions with people you don't follow
Replying to, favouriting and reblogging someone you're not following
will make them show up in follow recommendations. The interactions
have different weights:
- Replying is 1
- Favouriting is 10 (decidedly positive interaction, but private)
- Reblogging is 20
Following them, muting or blocking will remove them from the list,
obviously.
* Remove triadic closures, ensure potential friendships are trimmed
2018-07-02 23:47:56 +00:00
|
|
|
|
2017-08-12 22:44:41 +00:00
|
|
|
create_notification(favourite)
|
Re-add follow recommendations API (#7918)
* Re-add follow recommendations API
GET /api/v1/suggestions
Removed in 30f9e9e624b044f021fd0d345e4b1ea189978479 due to Neo4J
dependency. The algorithm uses triadic closures, takes into account
suspensions, blocks, mutes, domain blocks, excludes locked and moved
accounts, and prefers more recently updated accounts.
* Track interactions with people you don't follow
Replying to, favouriting and reblogging someone you're not following
will make them show up in follow recommendations. The interactions
have different weights:
- Replying is 1
- Favouriting is 10 (decidedly positive interaction, but private)
- Reblogging is 20
Following them, muting or blocking will remove them from the list,
obviously.
* Remove triadic closures, ensure potential friendships are trimmed
2018-07-02 23:47:56 +00:00
|
|
|
bump_potential_friendship(account, status)
|
|
|
|
|
2016-03-06 11:51:55 +00:00
|
|
|
favourite
|
|
|
|
end
|
2017-02-11 23:48:53 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-08-12 22:44:41 +00:00
|
|
|
def create_notification(favourite)
|
|
|
|
status = favourite.status
|
|
|
|
|
|
|
|
if status.account.local?
|
|
|
|
NotifyService.new.call(status.account, favourite)
|
|
|
|
elsif status.account.activitypub?
|
|
|
|
ActivityPub::DeliveryWorker.perform_async(build_json(favourite), favourite.account_id, status.account.inbox_url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Re-add follow recommendations API (#7918)
* Re-add follow recommendations API
GET /api/v1/suggestions
Removed in 30f9e9e624b044f021fd0d345e4b1ea189978479 due to Neo4J
dependency. The algorithm uses triadic closures, takes into account
suspensions, blocks, mutes, domain blocks, excludes locked and moved
accounts, and prefers more recently updated accounts.
* Track interactions with people you don't follow
Replying to, favouriting and reblogging someone you're not following
will make them show up in follow recommendations. The interactions
have different weights:
- Replying is 1
- Favouriting is 10 (decidedly positive interaction, but private)
- Reblogging is 20
Following them, muting or blocking will remove them from the list,
obviously.
* Remove triadic closures, ensure potential friendships are trimmed
2018-07-02 23:47:56 +00:00
|
|
|
def bump_potential_friendship(account, status)
|
2018-07-16 16:35:43 +00:00
|
|
|
ActivityTracker.increment('activity:interactions')
|
Re-add follow recommendations API (#7918)
* Re-add follow recommendations API
GET /api/v1/suggestions
Removed in 30f9e9e624b044f021fd0d345e4b1ea189978479 due to Neo4J
dependency. The algorithm uses triadic closures, takes into account
suspensions, blocks, mutes, domain blocks, excludes locked and moved
accounts, and prefers more recently updated accounts.
* Track interactions with people you don't follow
Replying to, favouriting and reblogging someone you're not following
will make them show up in follow recommendations. The interactions
have different weights:
- Replying is 1
- Favouriting is 10 (decidedly positive interaction, but private)
- Reblogging is 20
Following them, muting or blocking will remove them from the list,
obviously.
* Remove triadic closures, ensure potential friendships are trimmed
2018-07-02 23:47:56 +00:00
|
|
|
return if account.following?(status.account_id)
|
|
|
|
PotentialFriendshipTracker.record(account.id, status.account_id, :favourite)
|
|
|
|
end
|
|
|
|
|
2017-08-12 22:44:41 +00:00
|
|
|
def build_json(favourite)
|
2019-06-04 21:11:18 +00:00
|
|
|
Oj.dump(serialize_payload(favourite, ActivityPub::LikeSerializer))
|
2017-08-12 22:44:41 +00:00
|
|
|
end
|
2016-03-06 11:51:55 +00:00
|
|
|
end
|