2016-11-16 02:56:29 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-06 22:51:55 +11:00
|
|
|
class FavouriteService < BaseService
|
2017-05-30 02:22:22 +10:00
|
|
|
include Authorization
|
2019-06-05 07:11:18 +10:00
|
|
|
include Payloadable
|
2017-05-30 02:22:22 +10:00
|
|
|
|
2016-03-06 22:51:55 +11:00
|
|
|
# Favourite a status and notify remote user
|
|
|
|
# @param [Account] account
|
|
|
|
# @param [Status] status
|
|
|
|
# @return [Favourite]
|
|
|
|
def call(account, status)
|
2018-05-02 23:50:20 +10:00
|
|
|
authorize_with account, status, :favourite?
|
2016-12-30 06:33:26 +11:00
|
|
|
|
2017-06-08 23:07:39 +10:00
|
|
|
favourite = Favourite.find_by(account: account, status: status)
|
|
|
|
|
|
|
|
return favourite unless favourite.nil?
|
|
|
|
|
2016-03-06 22:51:55 +11: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 09:47:56 +10:00
|
|
|
|
2017-08-13 08:44:41 +10:00
|
|
|
create_notification(favourite)
|
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 09:47:56 +10:00
|
|
|
bump_potential_friendship(account, status)
|
|
|
|
|
2016-03-06 22:51:55 +11:00
|
|
|
favourite
|
|
|
|
end
|
2017-02-12 10:48:53 +11:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-08-13 08:44:41 +10:00
|
|
|
def create_notification(favourite)
|
|
|
|
status = favourite.status
|
|
|
|
|
|
|
|
if status.account.local?
|
|
|
|
NotifyService.new.call(status.account, favourite)
|
|
|
|
elsif status.account.ostatus?
|
|
|
|
NotificationWorker.perform_async(build_xml(favourite), favourite.account_id, status.account_id)
|
|
|
|
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 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 09:47:56 +10:00
|
|
|
def bump_potential_friendship(account, status)
|
2018-07-17 02:35:43 +10: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 09:47:56 +10:00
|
|
|
return if account.following?(status.account_id)
|
|
|
|
PotentialFriendshipTracker.record(account.id, status.account_id, :favourite)
|
|
|
|
end
|
|
|
|
|
2017-08-13 08:44:41 +10:00
|
|
|
def build_json(favourite)
|
2019-06-05 07:11:18 +10:00
|
|
|
Oj.dump(serialize_payload(favourite, ActivityPub::LikeSerializer))
|
2017-08-13 08:44:41 +10:00
|
|
|
end
|
|
|
|
|
2017-02-12 10:48:53 +11:00
|
|
|
def build_xml(favourite)
|
2017-07-19 09:37:26 +10:00
|
|
|
OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.favourite_salmon(favourite))
|
2017-02-12 10:48:53 +11:00
|
|
|
end
|
2016-03-06 22:51:55 +11:00
|
|
|
end
|