aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-undo.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-13 14:27:40 +0200
committerChocobozzz <me@florianbigard.com>2018-06-13 14:27:40 +0200
commit90d4bb8125e80c8060416d4d135ddeaf0a622ede (patch)
treeb3b7181329a08ecc930b54fe7b48095c4155393c /server/lib/activitypub/process/process-undo.ts
parent3cd0734fd9b0ff21aaef02317a874e8f1c06e027 (diff)
downloadPeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.tar.gz
PeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.tar.zst
PeerTube-90d4bb8125e80c8060416d4d135ddeaf0a622ede.zip
Refractor retry transaction function
Diffstat (limited to 'server/lib/activitypub/process/process-undo.ts')
-rw-r--r--server/lib/activitypub/process/process-undo.ts48
1 files changed, 6 insertions, 42 deletions
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts
index 37db58e1a..b6de107ad 100644
--- a/server/lib/activitypub/process/process-undo.ts
+++ b/server/lib/activitypub/process/process-undo.ts
@@ -18,13 +18,13 @@ async function processUndoActivity (activity: ActivityUndo) {
18 const actorUrl = getActorUrl(activity.actor) 18 const actorUrl = getActorUrl(activity.actor)
19 19
20 if (activityToUndo.type === 'Like') { 20 if (activityToUndo.type === 'Like') {
21 return processUndoLike(actorUrl, activity) 21 return retryTransactionWrapper(processUndoLike, actorUrl, activity)
22 } else if (activityToUndo.type === 'Create' && activityToUndo.object.type === 'Dislike') { 22 } else if (activityToUndo.type === 'Create' && activityToUndo.object.type === 'Dislike') {
23 return processUndoDislike(actorUrl, activity) 23 return retryTransactionWrapper(processUndoDislike, actorUrl, activity)
24 } else if (activityToUndo.type === 'Follow') { 24 } else if (activityToUndo.type === 'Follow') {
25 return processUndoFollow(actorUrl, activityToUndo) 25 return retryTransactionWrapper(processUndoFollow, actorUrl, activityToUndo)
26 } else if (activityToUndo.type === 'Announce') { 26 } else if (activityToUndo.type === 'Announce') {
27 return processUndoAnnounce(actorUrl, activityToUndo) 27 return retryTransactionWrapper(processUndoAnnounce, actorUrl, activityToUndo)
28 } 28 }
29 29
30 logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id }) 30 logger.warn('Unknown activity object type %s -> %s when undo activity.', activityToUndo.type, { activity: activity.id })
@@ -40,16 +40,7 @@ export {
40 40
41// --------------------------------------------------------------------------- 41// ---------------------------------------------------------------------------
42 42
43function processUndoLike (actorUrl: string, activity: ActivityUndo) { 43async function processUndoLike (actorUrl: string, activity: ActivityUndo) {
44 const options = {
45 arguments: [ actorUrl, activity ],
46 errorMessage: 'Cannot undo like with many retries.'
47 }
48
49 return retryTransactionWrapper(undoLike, options)
50}
51
52async function undoLike (actorUrl: string, activity: ActivityUndo) {
53 const likeActivity = activity.object as ActivityLike 44 const likeActivity = activity.object as ActivityLike
54 45
55 const { video } = await getOrCreateAccountAndVideoAndChannel(likeActivity.object) 46 const { video } = await getOrCreateAccountAndVideoAndChannel(likeActivity.object)
@@ -73,16 +64,7 @@ async function undoLike (actorUrl: string, activity: ActivityUndo) {
73 }) 64 })
74} 65}
75 66
76function processUndoDislike (actorUrl: string, activity: ActivityUndo) { 67async function processUndoDislike (actorUrl: string, activity: ActivityUndo) {
77 const options = {
78 arguments: [ actorUrl, activity ],
79 errorMessage: 'Cannot undo dislike with many retries.'
80 }
81
82 return retryTransactionWrapper(undoDislike, options)
83}
84
85async function undoDislike (actorUrl: string, activity: ActivityUndo) {
86 const dislike = activity.object.object as DislikeObject 68 const dislike = activity.object.object as DislikeObject
87 69
88 const { video } = await getOrCreateAccountAndVideoAndChannel(dislike.object) 70 const { video } = await getOrCreateAccountAndVideoAndChannel(dislike.object)
@@ -107,15 +89,6 @@ async function undoDislike (actorUrl: string, activity: ActivityUndo) {
107} 89}
108 90
109function processUndoFollow (actorUrl: string, followActivity: ActivityFollow) { 91function processUndoFollow (actorUrl: string, followActivity: ActivityFollow) {
110 const options = {
111 arguments: [ actorUrl, followActivity ],
112 errorMessage: 'Cannot undo follow with many retries.'
113 }
114
115 return retryTransactionWrapper(undoFollow, options)
116}
117
118function undoFollow (actorUrl: string, followActivity: ActivityFollow) {
119 return sequelizeTypescript.transaction(async t => { 92 return sequelizeTypescript.transaction(async t => {
120 const follower = await ActorModel.loadByUrl(actorUrl, t) 93 const follower = await ActorModel.loadByUrl(actorUrl, t)
121 const following = await ActorModel.loadByUrl(followActivity.object, t) 94 const following = await ActorModel.loadByUrl(followActivity.object, t)
@@ -130,15 +103,6 @@ function undoFollow (actorUrl: string, followActivity: ActivityFollow) {
130} 103}
131 104
132function processUndoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) { 105function processUndoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) {
133 const options = {
134 arguments: [ actorUrl, announceActivity ],
135 errorMessage: 'Cannot undo announce with many retries.'
136 }
137
138 return retryTransactionWrapper(undoAnnounce, options)
139}
140
141function undoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) {
142 return sequelizeTypescript.transaction(async t => { 106 return sequelizeTypescript.transaction(async t => {
143 const byAccount = await AccountModel.loadByUrl(actorUrl, t) 107 const byAccount = await AccountModel.loadByUrl(actorUrl, t)
144 if (!byAccount) throw new Error('Unknown account ' + actorUrl) 108 if (!byAccount) throw new Error('Unknown account ' + actorUrl)