forked from TryGhost/Ghost
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpending-activity.ts
More file actions
77 lines (71 loc) · 2.2 KB
/
Copy pathpending-activity.ts
File metadata and controls
77 lines (71 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import {Activity, ActorProperties} from '@tryghost/admin-x-framework/api/activitypub';
export const PENDING_ACTIVITY_PREFIX = 'pending-';
export function generatePendingActivityId() {
return `${PENDING_ACTIVITY_PREFIX}${crypto.randomUUID()}`;
}
export function isPendingActivity(id: string) {
return id.startsWith(PENDING_ACTIVITY_PREFIX);
}
export function generatePendingActivity(actorProps: ActorProperties, id: string, content: string, imageUrl?: string): Activity {
const actor: ActorProperties = {
id: actorProps.url,
icon: actorProps.icon,
name: actorProps.name,
preferredUsername: actorProps.preferredUsername,
// These are not used but needed to comply with the ActorProperties type
'@context': '',
discoverable: false,
featured: '',
followers: '',
following: '',
image: {url: ''},
inbox: '',
manuallyApprovesFollowers: false,
outbox: '',
publicKey: {
id: '',
owner: '',
publicKeyPem: ''
},
published: '',
summary: '',
type: 'Person',
url: ''
};
return {
id,
type: 'Create',
actor,
object: {
type: 'Note',
name: '',
content: content,
summary: null,
url: '',
attributedTo: actor,
image: imageUrl || '',
published: new Date().toISOString(),
attachment: [],
preview: {
type: 'Note',
content: content
},
// These are used in the app, but are not part of the ObjectProperties type
id,
replyCount: 0,
likeCount: 0,
liked: false,
reposted: false,
repostCount: 0,
authored: true,
// These are not used but needed to comply with the ObjectProperties type
'@context': ''
},
// These are not used but needed to comply with the Activity type
'@context': '',
to: ''
};
}
export function formatPendingActivityContent(content: string) {
return content.replace(/\n/g, '<br />');
}