]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-undo.ts
Refractor retry transaction function
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-undo.ts
index 37db58e1a06780f1bb84fbc29269b5b13b725511..b6de107ad9a3250f00e5beefdbe6294f2e667da2 100644 (file)
@@ -18,13 +18,13 @@ async function processUndoActivity (activity: ActivityUndo) {
   const actorUrl = getActorUrl(activity.actor)
 
   if (activityToUndo.type === 'Like') {
-    return processUndoLike(actorUrl, activity)
+    return retryTransactionWrapper(processUndoLike, actorUrl, activity)
   } else if (activityToUndo.type === 'Create' && activityToUndo.object.type === 'Dislike') {
-    return processUndoDislike(actorUrl, activity)
+    return retryTransactionWrapper(processUndoDislike, actorUrl, activity)
   } else if (activityToUndo.type === 'Follow') {
-    return processUndoFollow(actorUrl, activityToUndo)
+    return retryTransactionWrapper(processUndoFollow, actorUrl, activityToUndo)
   } else if (activityToUndo.type === 'Announce') {
-    return processUndoAnnounce(actorUrl, activityToUndo)
+    return retryTransactionWrapper(processUndoAnnounce, actorUrl, activityToUndo)
   }
 
   logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id })
@@ -40,16 +40,7 @@ export {
 
 // ---------------------------------------------------------------------------
 
-function processUndoLike (actorUrl: string, activity: ActivityUndo) {
-  const options = {
-    arguments: [ actorUrl, activity ],
-    errorMessage: 'Cannot undo like with many retries.'
-  }
-
-  return retryTransactionWrapper(undoLike, options)
-}
-
-async function undoLike (actorUrl: string, activity: ActivityUndo) {
+async function processUndoLike (actorUrl: string, activity: ActivityUndo) {
   const likeActivity = activity.object as ActivityLike
 
   const { video } = await getOrCreateAccountAndVideoAndChannel(likeActivity.object)
@@ -73,16 +64,7 @@ async function undoLike (actorUrl: string, activity: ActivityUndo) {
   })
 }
 
-function processUndoDislike (actorUrl: string, activity: ActivityUndo) {
-  const options = {
-    arguments: [ actorUrl, activity ],
-    errorMessage: 'Cannot undo dislike with many retries.'
-  }
-
-  return retryTransactionWrapper(undoDislike, options)
-}
-
-async function undoDislike (actorUrl: string, activity: ActivityUndo) {
+async function processUndoDislike (actorUrl: string, activity: ActivityUndo) {
   const dislike = activity.object.object as DislikeObject
 
   const { video } = await getOrCreateAccountAndVideoAndChannel(dislike.object)
@@ -107,15 +89,6 @@ async function undoDislike (actorUrl: string, activity: ActivityUndo) {
 }
 
 function processUndoFollow (actorUrl: string, followActivity: ActivityFollow) {
-  const options = {
-    arguments: [ actorUrl, followActivity ],
-    errorMessage: 'Cannot undo follow with many retries.'
-  }
-
-  return retryTransactionWrapper(undoFollow, options)
-}
-
-function undoFollow (actorUrl: string, followActivity: ActivityFollow) {
   return sequelizeTypescript.transaction(async t => {
     const follower = await ActorModel.loadByUrl(actorUrl, t)
     const following = await ActorModel.loadByUrl(followActivity.object, t)
@@ -130,15 +103,6 @@ function undoFollow (actorUrl: string, followActivity: ActivityFollow) {
 }
 
 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)