mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Federate likes/dislikes
This commit is contained in:
parent
d52eb8f656
commit
0032ebe94a
27 changed files with 548 additions and 62 deletions
|
@ -1,10 +1,14 @@
|
|||
import { Transaction } from 'sequelize'
|
||||
import { ActivityFollow, ActivityUndo } from '../../../../shared/models/activitypub/activity'
|
||||
import { ActivityCreate, ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub/activity'
|
||||
import { AccountInstance } from '../../../models'
|
||||
import { AccountFollowInstance } from '../../../models/account/account-follow-interface'
|
||||
import { unicastTo } from './misc'
|
||||
import { broadcastToFollowers, getAccountsToForwardVideoAction, unicastTo } from './misc'
|
||||
import { followActivityData } from './send-follow'
|
||||
import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl } from '../url'
|
||||
import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
|
||||
import { VideoInstance } from '../../../models/video/video-interface'
|
||||
import { likeActivityData } from './send-like'
|
||||
import { createActivityData, createDislikeActivityData } from './send-create'
|
||||
import { getServerAccount } from '../../../helpers/utils'
|
||||
|
||||
async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transaction) {
|
||||
const me = accountFollow.AccountFollower
|
||||
|
@ -19,15 +23,72 @@ async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transact
|
|||
return unicastTo(data, me, following.inboxUrl, t)
|
||||
}
|
||||
|
||||
async function sendUndoLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
||||
const likeUrl = getVideoLikeActivityPubUrl(byAccount, video)
|
||||
const undoUrl = getUndoActivityPubUrl(likeUrl)
|
||||
|
||||
const object = await likeActivityData(likeUrl, byAccount, video)
|
||||
const data = await undoActivityData(undoUrl, byAccount, object)
|
||||
|
||||
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
||||
}
|
||||
|
||||
async function sendUndoLikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
||||
const likeUrl = getVideoLikeActivityPubUrl(byAccount, video)
|
||||
const undoUrl = getUndoActivityPubUrl(likeUrl)
|
||||
|
||||
const object = await likeActivityData(likeUrl, byAccount, video)
|
||||
const data = await undoActivityData(undoUrl, byAccount, object)
|
||||
|
||||
const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video)
|
||||
const serverAccount = await getServerAccount()
|
||||
|
||||
const followersException = [ byAccount ]
|
||||
return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException)
|
||||
}
|
||||
|
||||
async function sendUndoDislikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
||||
const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video)
|
||||
const undoUrl = getUndoActivityPubUrl(dislikeUrl)
|
||||
|
||||
const dislikeActivity = createDislikeActivityData(byAccount, video)
|
||||
const object = await createActivityData(undoUrl, byAccount, dislikeActivity)
|
||||
|
||||
const data = await undoActivityData(undoUrl, byAccount, object)
|
||||
|
||||
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
||||
}
|
||||
|
||||
async function sendUndoDislikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
||||
const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video)
|
||||
const undoUrl = getUndoActivityPubUrl(dislikeUrl)
|
||||
|
||||
const dislikeActivity = createDislikeActivityData(byAccount, video)
|
||||
const object = await createActivityData(undoUrl, byAccount, dislikeActivity)
|
||||
|
||||
const data = await undoActivityData(undoUrl, byAccount, object)
|
||||
|
||||
const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video)
|
||||
const serverAccount = await getServerAccount()
|
||||
|
||||
const followersException = [ byAccount ]
|
||||
return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException)
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
sendUndoFollow
|
||||
sendUndoFollow,
|
||||
sendUndoLikeToOrigin,
|
||||
sendUndoLikeToVideoFollowers,
|
||||
sendUndoDislikeToOrigin,
|
||||
sendUndoDislikeToVideoFollowers
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function undoActivityData (url: string, byAccount: AccountInstance, object: ActivityFollow) {
|
||||
async function undoActivityData (url: string, byAccount: AccountInstance, object: ActivityFollow | ActivityLike | ActivityCreate) {
|
||||
const activity: ActivityUndo = {
|
||||
type: 'Undo',
|
||||
id: url,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue