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