1
0
Fork 0
peertube/server/lib/activitypub/send/send-like.ts

41 lines
1.3 KiB
TypeScript
Raw Normal View History

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