summaryrefslogtreecommitdiff
path: root/src/remote/activitypub
diff options
context:
space:
mode:
authormei23 <m@m544.net>2018-08-14 20:13:32 +0900
committermei23 <m@m544.net>2018-08-14 20:13:32 +0900
commit0986301788a40663ced0aa9d6d8a97b099b622b1 (patch)
treee68319f2e89dcd852ee7cf700dc0c6e033c97897 /src/remote/activitypub
parent5.23.2 (diff)
downloadsharkey-0986301788a40663ced0aa9d6d8a97b099b622b1.tar.gz
sharkey-0986301788a40663ced0aa9d6d8a97b099b622b1.tar.bz2
sharkey-0986301788a40663ced0aa9d6d8a97b099b622b1.zip
Implement ActivityPub Followers/Following/Outbox
Diffstat (limited to 'src/remote/activitypub')
-rw-r--r--src/remote/activitypub/renderer/follow-user.ts16
-rw-r--r--src/remote/activitypub/renderer/ordered-collection-page.ts23
-rw-r--r--src/remote/activitypub/renderer/ordered-collection.ts25
3 files changed, 58 insertions, 6 deletions
diff --git a/src/remote/activitypub/renderer/follow-user.ts b/src/remote/activitypub/renderer/follow-user.ts
new file mode 100644
index 0000000000..9a488d392b
--- /dev/null
+++ b/src/remote/activitypub/renderer/follow-user.ts
@@ -0,0 +1,16 @@
+import config from '../../../config';
+import * as mongo from 'mongodb';
+import User, { isLocalUser } from '../../../models/user';
+
+/**
+ * Convert (local|remote)(Follower|Followee)ID to URL
+ * @param id Follower|Followee ID
+ */
+export default async function renderFollowUser(id: mongo.ObjectID): Promise<any> {
+
+ const user = await User.findOne({
+ _id: id
+ });
+
+ return isLocalUser(user) ? `${config.url}/users/${user._id}` : user.uri;
+}
diff --git a/src/remote/activitypub/renderer/ordered-collection-page.ts b/src/remote/activitypub/renderer/ordered-collection-page.ts
new file mode 100644
index 0000000000..83af07870e
--- /dev/null
+++ b/src/remote/activitypub/renderer/ordered-collection-page.ts
@@ -0,0 +1,23 @@
+/**
+ * Render OrderedCollectionPage
+ * @param id URL of self
+ * @param totalItems Number of total items
+ * @param orderedItems Items
+ * @param partOf URL of base
+ * @param prev URL of prev page (optional)
+ * @param next URL of next page (optional)
+ */
+export default function(id: string, totalItems: any, orderedItems: any, partOf: string, prev: string, next: string) {
+ const page = {
+ id,
+ partOf,
+ type: 'OrderedCollectionPage',
+ totalItems,
+ orderedItems
+ } as any;
+
+ if (prev) page.prev = prev;
+ if (next) page.next = next;
+
+ return page;
+}
diff --git a/src/remote/activitypub/renderer/ordered-collection.ts b/src/remote/activitypub/renderer/ordered-collection.ts
index 9d543b1e1b..3c448cf873 100644
--- a/src/remote/activitypub/renderer/ordered-collection.ts
+++ b/src/remote/activitypub/renderer/ordered-collection.ts
@@ -1,6 +1,19 @@
-export default (id: string, totalItems: any, orderedItems: any) => ({
- id,
- type: 'OrderedCollection',
- totalItems,
- orderedItems
-});
+/**
+ * Render OrderedCollection
+ * @param id URL of self
+ * @param totalItems Total number of items
+ * @param first URL of first page (optional)
+ * @param last URL of last page (optional)
+ */
+export default function(id: string, totalItems: any, first: string, last: string) {
+ const page: any = {
+ id,
+ type: 'OrderedCollection',
+ totalItems,
+ };
+
+ if (first) page.first = first;
+ if (last) page.last = last;
+
+ return page;
+}