2017-11-23 07:19:55 -06:00
|
|
|
import { Transaction } from 'sequelize'
|
2017-12-12 10:53:50 -06:00
|
|
|
import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub'
|
2017-11-23 07:19:55 -06:00
|
|
|
import { getVideoLikeActivityPubUrl } from '../url'
|
2018-09-14 09:51:35 -05:00
|
|
|
import { sendVideoRelatedActivity } from './utils'
|
|
|
|
import { audiencify, getAudience } from '../audience'
|
2018-07-30 10:02:40 -05:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2019-08-15 04:53:26 -05:00
|
|
|
import { MActor, MActorAudience, MVideoAccountLight, MVideoUrl } from '../../../typings/models'
|
2017-11-23 07:19:55 -06:00
|
|
|
|
2019-08-15 04:53:26 -05:00
|
|
|
async 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) => {
|
|
|
|
const url = getVideoLikeActivityPubUrl(byActor, video)
|
2017-11-23 07:19:55 -06:00
|
|
|
|
2018-09-14 09:51:35 -05:00
|
|
|
return buildLikeActivity(url, byActor, video, audience)
|
2018-03-27 06:33:56 -05:00
|
|
|
}
|
2017-11-23 07:19:55 -06:00
|
|
|
|
2018-09-14 09:51:35 -05:00
|
|
|
return sendVideoRelatedActivity(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 {
|
2018-06-12 13:04:58 -05:00
|
|
|
if (!audience) audience = getAudience(byActor)
|
|
|
|
|
|
|
|
return audiencify(
|
|
|
|
{
|
|
|
|
id: url,
|
2018-11-14 08:01:28 -06:00
|
|
|
type: 'Like' as 'Like',
|
2018-06-12 13:04:58 -05:00
|
|
|
actor: byActor.url,
|
|
|
|
object: video.url
|
|
|
|
},
|
|
|
|
audience
|
|
|
|
)
|
2017-11-23 07:19:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2018-03-27 06:33:56 -05:00
|
|
|
sendLike,
|
2018-09-11 09:27:07 -05:00
|
|
|
buildLikeActivity
|
2017-11-23 07:19:55 -06:00
|
|
|
}
|