2016-11-15 17:56:29 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-06 13:51:55 +02:00
|
|
|
class FavouriteService < BaseService
|
2017-05-29 19:22:22 +03:00
|
|
|
include Authorization
|
2019-06-05 00:11:18 +03:00
|
|
|
include Payloadable
|
2017-05-29 19:22:22 +03:00
|
|
|
|
2016-03-06 13:51:55 +02:00
|
|
|
# Favourite a status and notify remote user
|
|
|
|
# @param [Account] account
|
|
|
|
# @param [Status] status
|
|
|
|
# @return [Favourite]
|
|
|
|
def call(account, status)
|
2018-05-02 16:50:20 +03:00
|
|
|
authorize_with account, status, :favourite?
|
2016-12-29 21:33:26 +02:00
|
|
|
|
2017-06-08 16:07:39 +03:00
|
|
|
favourite = Favourite.find_by(account: account, status: status)
|
|
|
|
|
|
|
|
return favourite unless favourite.nil?
|
|
|
|
|
2016-03-06 13:51:55 +02: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-03 02:47:56 +03:00
|
|
|
|
2022-02-25 01:34:14 +02:00
|
|
|
Trends.statuses.register(status)
|
|
|
|
|
2017-08-13 01:44:41 +03: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-03 02:47:56 +03:00
|
|
|
bump_potential_friendship(account, status)
|
|
|
|
|
2016-03-06 13:51:55 +02:00
|
|
|
favourite
|
|
|
|
end
|
2017-02-12 01:48:53 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-08-13 01:44:41 +03:00
|
|
|
def create_notification(favourite)
|
|
|
|
status = favourite.status
|
|
|
|
|
|
|
|
if status.account.local?
|
2022-03-04 02:06:33 +02:00
|
|
|
LocalNotificationWorker.perform_async(status.account_id, favourite.id, 'Favourite', 'favourite')
|
2017-08-13 01:44:41 +03:00
|
|
|
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-03 02:47:56 +03:00
|
|
|
def bump_potential_friendship(account, status)
|
2018-07-16 19:35:43 +03: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-03 02:47:56 +03:00
|
|
|
return if account.following?(status.account_id)
|
2023-02-20 07:58:28 +02:00
|
|
|
|
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-03 02:47:56 +03:00
|
|
|
PotentialFriendshipTracker.record(account.id, status.account_id, :favourite)
|
|
|
|
end
|
|
|
|
|
2017-08-13 01:44:41 +03:00
|
|
|
def build_json(favourite)
|
2019-06-05 00:11:18 +03:00
|
|
|
Oj.dump(serialize_payload(favourite, ActivityPub::LikeSerializer))
|
2017-08-13 01:44:41 +03:00
|
|
|
end
|
2016-03-06 13:51:55 +02:00
|
|
|
end
|