PeerTube/server/lib/activitypub/send/send-like.ts

41 lines
1.3 KiB
TypeScript
Raw Normal View History

2017-11-23 07:19:55 -06:00
import { Transaction } from 'sequelize'
import { ActivityAudience, ActivityLike } from '@shared/models'
2018-07-30 10:02:40 -05:00
import { logger } from '../../../helpers/logger'
2020-06-18 03:45:25 -05:00
import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../types/models'
import { audiencify, getAudience } from '../audience'
import { getVideoLikeActivityPubUrlByLocalActor } from '../url'
import { sendVideoActivityToOrigin } from './shared/send-utils'
2017-11-23 07:19:55 -06:00
2020-01-31 09:56:52 -06:00
function sendLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) {
2018-07-30 10:02:40 -05:00
logger.info('Creating job to like %s.', video.url)
2018-09-14 09:51:35 -05:00
const activityBuilder = (audience: ActivityAudience) => {
2020-11-20 04:21:08 -06:00
const url = getVideoLikeActivityPubUrlByLocalActor(byActor, video)
2017-11-23 07:19:55 -06:00
2018-09-14 09:51:35 -05:00
return buildLikeActivity(url, byActor, video, audience)
}
2017-11-23 07:19:55 -06:00
return sendVideoActivityToOrigin(activityBuilder, { byActor, video, transaction: t })
2017-11-23 07:19:55 -06:00
}
2019-08-15 04:53:26 -05:00
function buildLikeActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityLike {
if (!audience) audience = getAudience(byActor)
return audiencify(
{
id: url,
2018-11-14 08:01:28 -06:00
type: 'Like' as 'Like',
actor: byActor.url,
object: video.url
},
audience
)
2017-11-23 07:19:55 -06:00
}
// ---------------------------------------------------------------------------
export {
sendLike,
2018-09-11 09:27:07 -05:00
buildLikeActivity
2017-11-23 07:19:55 -06:00
}