diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-20 09:43:39 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | 54141398354e6e7b94aa3065a705a1251390111c (patch) | |
tree | 8d30d1b9ea8acbe04f6d404125b04fc0c9897b70 /server/lib/activitypub/send/send-undo.ts | |
parent | eb8b27c93e61a896a08923dc1ca3c87ba8cf4948 (diff) | |
download | PeerTube-54141398354e6e7b94aa3065a705a1251390111c.tar.gz PeerTube-54141398354e6e7b94aa3065a705a1251390111c.tar.zst PeerTube-54141398354e6e7b94aa3065a705a1251390111c.zip |
Refractor activity pub lib/helpers
Diffstat (limited to 'server/lib/activitypub/send/send-undo.ts')
-rw-r--r-- | server/lib/activitypub/send/send-undo.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts new file mode 100644 index 000000000..39da824f3 --- /dev/null +++ b/server/lib/activitypub/send/send-undo.ts | |||
@@ -0,0 +1,39 @@ | |||
1 | import { Transaction } from 'sequelize' | ||
2 | import { ActivityFollow, ActivityUndo } from '../../../../shared/models/activitypub/activity' | ||
3 | import { AccountInstance } from '../../../models' | ||
4 | import { AccountFollowInstance } from '../../../models/account/account-follow-interface' | ||
5 | import { unicastTo } from './misc' | ||
6 | import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl } from '../../../helpers/activitypub' | ||
7 | import { followActivityData } from './send-follow' | ||
8 | |||
9 | async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transaction) { | ||
10 | const me = accountFollow.AccountFollower | ||
11 | const following = accountFollow.AccountFollowing | ||
12 | |||
13 | const followUrl = getAccountFollowActivityPubUrl(accountFollow) | ||
14 | const undoUrl = getUndoActivityPubUrl(followUrl) | ||
15 | |||
16 | const object = await followActivityData(followUrl, me, following) | ||
17 | const data = await undoActivityData(undoUrl, me, object) | ||
18 | |||
19 | return unicastTo(data, me, following.inboxUrl, t) | ||
20 | } | ||
21 | |||
22 | // --------------------------------------------------------------------------- | ||
23 | |||
24 | export { | ||
25 | sendUndoFollow | ||
26 | } | ||
27 | |||
28 | // --------------------------------------------------------------------------- | ||
29 | |||
30 | async function undoActivityData (url: string, byAccount: AccountInstance, object: ActivityFollow) { | ||
31 | const activity: ActivityUndo = { | ||
32 | type: 'Undo', | ||
33 | id: url, | ||
34 | actor: byAccount.url, | ||
35 | object | ||
36 | } | ||
37 | |||
38 | return activity | ||
39 | } | ||