forked from TryGhost/Ghost
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivitypub.ts
More file actions
164 lines (149 loc) · 3.87 KB
/
Copy pathactivitypub.ts
File metadata and controls
164 lines (149 loc) · 3.87 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import {createMutation, createQueryWithId} from '../utils/api/hooks';
import {JSONObject} from './config';
export type ActivityPubContext = string | (string | JSONObject)[];
export type ActivityPubAttachment = {
type: string;
mediaType?: string;
name?: string;
url: string;
};
export type ObjectMetadata = {
ghostAuthors?: Array<{
name: string;
profile_image: string;
}>;
};
export type FollowItem = {
id: string;
preferredUsername: string;
};
export type ObjectProperties = {
'@context': ActivityPubContext;
id: string;
type: 'Article' | 'Link' | 'Note' | 'Tombstone';
name: string;
content: string | null;
summary: string | null;
url?: string | undefined;
attributedTo?: ActorProperties | string | ActorProperties[] | JSONObject | JSONObject[];
image?: string | {
url: string;
mediaType?: string;
type?: string;
};
attachment?: ActivityPubAttachment | ActivityPubAttachment[];
published?: string;
createdAt?: string;
preview?: {type: string, content: string | null};
replyCount: number;
likeCount: number;
liked?: boolean;
reposted?: boolean;
repostCount: number;
authored: boolean;
metadata?: ObjectMetadata;
}
export type ActorProperties = {
'@context': ActivityPubContext;
attachment?: {
type: string;
name: string;
value: string;
}[];
discoverable: boolean;
featured: string;
followers: string;
following: string;
id: string | null;
image: {
url: string;
};
icon: {
url: string;
};
inbox: string;
manuallyApprovesFollowers: boolean;
name: string;
outbox: string;
preferredUsername: string;
handle?: string;
followedByMe?: boolean;
followsMe?: boolean;
followingCount?: number;
followerCount?: number;
bio?: string;
avatarUrl?: string | null;
publicKey: {
id: string;
owner: string;
publicKeyPem: string;
};
published: string;
summary: string;
type: 'Person';
url: string;
}
export type Activity = {
'@context': string;
id: string;
type: string;
actor: ActorProperties;
object: ObjectProperties;
to: string;
}
export type InboxResponseData = {
'@context': string;
id: string;
summary: string;
type: 'OrderedCollection';
totalItems: number;
items: Activity[];
}
export type FollowingResponseData = {
'@context': string;
id: string;
summary: string;
type: string;
totalItems: number;
items: FollowItem[];
}
type FollowRequestProps = {
username: string
}
export const useFollow = createMutation<object, FollowRequestProps>({
method: 'POST',
useActivityPub: true,
path: data => `/actions/follow/${data.username}`
});
export const useUnfollow = createMutation<object, FollowRequestProps>({
method: 'POST',
useActivityPub: true,
path: data => `/actions/unfollow/${data.username}`
});
// This is a frontend root, not using the Ghost admin API
export const useBrowseInboxForUser = createQueryWithId<InboxResponseData>({
dataType: 'InboxResponseData',
useActivityPub: true,
headers: {
Accept: 'application/activity+json'
},
path: id => `/reader/${id}`
});
// This is a frontend root, not using the Ghost admin API
export const useBrowseFollowingForUser = createQueryWithId<FollowingResponseData>({
dataType: 'FollowingResponseData',
useActivityPub: true,
headers: {
Accept: 'application/activity+json'
},
path: id => `/following/${id}`
});
// This is a frontend root, not using the Ghost admin API
export const useBrowseFollowersForUser = createQueryWithId<FollowingResponseData>({
dataType: 'FollowingResponseData',
useActivityPub: true,
headers: {
Accept: 'application/activity+json'
},
path: id => `/followers/${id}`
});