+async function shareByVideoChannel (video: VideoModel, t: Transaction) {
+ const videoChannelShareUrl = getAnnounceActivityPubUrl(video.url, video.VideoChannel.Actor)
+ return VideoShareModel.findOrCreate({
+ defaults: {
+ actorId: video.VideoChannel.actorId,
+ videoId: video.id,
+ url: videoChannelShareUrl
+ },
+ where: {
+ url: videoChannelShareUrl
+ },
+ transaction: t
+ }).then(([ videoChannelShare, created ]) => {
+ if (created) return sendVideoAnnounce(video.VideoChannel.Actor, videoChannelShare, video, t)
+
+ return undefined
+ })
+}
+
+async function undoShareByVideoChannel (video: VideoModel, oldVideoChannel: VideoChannelModel, t: Transaction) {
+ // Load old share
+ const oldShare = await VideoShareModel.load(oldVideoChannel.actorId, video.id, t)
+ if (!oldShare) return new Error('Cannot find old video channel share ' + oldVideoChannel.actorId + ' for video ' + video.id)
+
+ await sendUndoAnnounce(oldVideoChannel.Actor, oldShare, video, t)
+ await oldShare.destroy({ transaction: t })