-import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub'
+import { ActivityAnnounce, ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub'
import { DislikeObject } from '../../../../shared/models/activitypub/objects'
import { getActorUrl } from '../../../helpers/activitypub'
import { retryTransactionWrapper } from '../../../helpers/database-utils'
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
import { ActorModel } from '../../../models/activitypub/actor'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
-import { forwardActivity } from '../send/misc'
+import { forwardVideoRelatedActivity } from '../send/utils'
import { getOrCreateAccountAndVideoAndChannel } from '../videos'
+import { VideoShareModel } from '../../../models/video/video-share'
async function processUndoActivity (activity: ActivityUndo) {
const activityToUndo = activity.object
return processUndoDislike(actorUrl, activity)
} else if (activityToUndo.type === 'Follow') {
return processUndoFollow(actorUrl, activityToUndo)
+ } else if (activityToUndo.type === 'Announce') {
+ return processUndoAnnounce(actorUrl, activityToUndo)
}
logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id })
if (video.isOwned()) {
// Don't resend the activity to the sender
const exceptions = [ byAccount.Actor ]
- await forwardActivity(activity, t, exceptions)
+
+ await forwardVideoRelatedActivity(activity, t, exceptions, video)
}
})
}
if (video.isOwned()) {
// Don't resend the activity to the sender
const exceptions = [ byAccount.Actor ]
- await forwardActivity(activity, t, exceptions)
+
+ await forwardVideoRelatedActivity(activity, t, exceptions, video)
}
})
}
return undefined
})
}
+
+function processUndoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) {
+ const options = {
+ arguments: [ actorUrl, announceActivity ],
+ errorMessage: 'Cannot undo announce with many retries.'
+ }
+
+ return retryTransactionWrapper(undoAnnounce, options)
+}
+
+function undoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) {
+ return sequelizeTypescript.transaction(async t => {
+ const byAccount = await AccountModel.loadByUrl(actorUrl, t)
+ if (!byAccount) throw new Error('Unknown account ' + actorUrl)
+
+ const share = await VideoShareModel.loadByUrl(announceActivity.id, t)
+ if (!share) throw new Error(`'Unknown video share ${announceActivity.id}.`)
+
+ await share.destroy({ transaction: t })
+
+ if (share.Video.isOwned()) {
+ // Don't resend the activity to the sender
+ const exceptions = [ byAccount.Actor ]
+
+ await forwardVideoRelatedActivity(announceActivity, t, exceptions, share.Video)
+ }
+ })
+}