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 17:22:22 +01:00
|
|
|
include Authorization
|
2019-06-04 22:11:18 +01:00
|
|
|
include Payloadable
|
2017-05-29 17:22:22 +01: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 14:50:20 +01:00
|
|
|
authorize_with account, status, :favourite?
|
2016-12-29 19:33:26 +00:00
|
|
|
|
2017-06-08 14:07:39 +01: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 8efa081f210d72ed450c39ac4cde0fd84fb3d3fb 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 00:47:56 +01:00
|
|
|
|
2022-02-24 23:34:14 +00:00
|
|
|
Trends.statuses.register(status)
|
|
|
|
|
2017-08-12 23:44:41 +01:00
|
|
|
create_notification(favourite)
|
2023-12-19 10:59:43 +00:00
|
|
|
increment_statistics
|
Re-add follow recommendations API (#7918)
* Re-add follow recommendations API
GET /api/v1/suggestions
Removed in 8efa081f210d72ed450c39ac4cde0fd84fb3d3fb 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 00:47:56 +01:00
|
|
|
|
2016-03-06 11:51:55 +00:00
|
|
|
favourite
|
|
|
|
end
|
2017-02-11 23:48:53 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-08-12 23:44:41 +01:00
|
|
|
def create_notification(favourite)
|
|
|
|
status = favourite.status
|
|
|
|
|
|
|
|
if status.account.local?
|
2022-03-04 00:06:33 +00:00
|
|
|
LocalNotificationWorker.perform_async(status.account_id, favourite.id, 'Favourite', 'favourite')
|
2017-08-12 23:44:41 +01:00
|
|
|
elsif status.account.activitypub?
|
|
|
|
ActivityPub::DeliveryWorker.perform_async(build_json(favourite), favourite.account_id, status.account.inbox_url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-12-19 10:59:43 +00:00
|
|
|
def increment_statistics
|
2018-07-16 17:35:43 +01:00
|
|
|
ActivityTracker.increment('activity:interactions')
|
Re-add follow recommendations API (#7918)
* Re-add follow recommendations API
GET /api/v1/suggestions
Removed in 8efa081f210d72ed450c39ac4cde0fd84fb3d3fb 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 00:47:56 +01:00
|
|
|
end
|
|
|
|
|
2017-08-12 23:44:41 +01:00
|
|
|
def build_json(favourite)
|
2019-06-04 22:11:18 +01:00
|
|
|
Oj.dump(serialize_payload(favourite, ActivityPub::LikeSerializer))
|
2017-08-12 23:44:41 +01:00
|
|
|
end
|
2016-03-06 11:51:55 +00:00
|
|
|
end
|