summaryrefslogtreecommitdiff
path: root/src/remote/activitypub
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2019-01-31 20:42:45 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2019-01-31 20:42:45 +0900
commita6e7bbc306a93bd56bb1941e29d6fc474c9c36d5 (patch)
tree4ec964d4d2efc3b1c5ec82c097c6d3667c17c30f /src/remote/activitypub
parentUpdate @types/koa-router requirement from 7.0.38 to 7.0.39 (#4052) (diff)
downloadsharkey-a6e7bbc306a93bd56bb1941e29d6fc474c9c36d5.tar.gz
sharkey-a6e7bbc306a93bd56bb1941e29d6fc474c9c36d5.tar.bz2
sharkey-a6e7bbc306a93bd56bb1941e29d6fc474c9c36d5.zip
send/receive user hashtags via AP (#4064)
Diffstat (limited to 'src/remote/activitypub')
-rw-r--r--src/remote/activitypub/models/note.ts13
-rw-r--r--src/remote/activitypub/models/person.ts8
-rw-r--r--src/remote/activitypub/models/tag.ts11
-rw-r--r--src/remote/activitypub/renderer/person.ts4
4 files changed, 23 insertions, 13 deletions
diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts
index 0f2e515260..1b61435aa2 100644
--- a/src/remote/activitypub/models/note.ts
+++ b/src/remote/activitypub/models/note.ts
@@ -11,7 +11,7 @@ import { resolveImage } from './image';
import { IRemoteUser, IUser } from '../../../models/user';
import { fromHtml } from '../../../mfm/fromHtml';
import Emoji, { IEmoji } from '../../../models/emoji';
-import { ITag } from './tag';
+import { ITag, extractHashtags } from './tag';
import { toUnicode } from 'punycode';
import { unique, concat, difference } from '../../../prelude/array';
import { extractPollFromQuestion } from './question';
@@ -239,14 +239,3 @@ async function extractMentionedUsers(actor: IRemoteUser, to: string[], cc: strin
return users.filter(x => x != null);
}
-
-function extractHashtags(tags: ITag[]) {
- if (!tags) return [];
-
- const hashtags = tags.filter(tag => tag.type === 'Hashtag' && typeof tag.name == 'string');
-
- return hashtags.map(tag => {
- const m = tag.name.match(/^#(.+)/);
- return m ? m[1] : null;
- }).filter(x => x != null);
-}
diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts
index 54e57f7330..16f1086b86 100644
--- a/src/remote/activitypub/models/person.ts
+++ b/src/remote/activitypub/models/person.ts
@@ -17,7 +17,7 @@ import registerInstance from '../../../services/register-instance';
import Instance from '../../../models/instance';
import getDriveFileUrl from '../../../misc/get-drive-file-url';
import { IEmoji } from '../../../models/emoji';
-import { ITag } from './tag';
+import { ITag, extractHashtags } from './tag';
import Following from '../../../models/following';
import { IIdentifier } from './identifier';
@@ -140,6 +140,8 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<IU
const { fields, services } = analyzeAttachments(person.attachment);
+ const tags = extractHashtags(person.tag);
+
const isBot = object.type == 'Service';
// Create user
@@ -171,6 +173,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<IU
url: person.url,
fields,
...services,
+ tags,
isBot,
isCat: (person as any).isCat === true
}) as IRemoteUser;
@@ -334,6 +337,8 @@ export async function updatePerson(uri: string, resolver?: Resolver, hint?: obje
const { fields, services } = analyzeAttachments(person.attachment);
+ const tags = extractHashtags(person.tag);
+
const updates = {
lastFetchedAt: new Date(),
inbox: person.inbox,
@@ -349,6 +354,7 @@ export async function updatePerson(uri: string, resolver?: Resolver, hint?: obje
endpoints: person.endpoints,
fields,
...services,
+ tags,
isBot: object.type == 'Service',
isCat: (person as any).isCat === true,
isLocked: person.manuallyApprovesFollowers,
diff --git a/src/remote/activitypub/models/tag.ts b/src/remote/activitypub/models/tag.ts
index b64d6bd4a7..0a1e6e29f9 100644
--- a/src/remote/activitypub/models/tag.ts
+++ b/src/remote/activitypub/models/tag.ts
@@ -13,3 +13,14 @@ export type ITag = {
icon?: IIcon;
identifier?: IIdentifier;
};
+
+export function extractHashtags(tags: ITag[]) {
+ if (!tags) return [];
+
+ const hashtags = tags.filter(tag => tag.type === 'Hashtag' && typeof tag.name == 'string');
+
+ return hashtags.map(tag => {
+ const m = tag.name.match(/^#(.+)/);
+ return m ? m[1] : null;
+ }).filter(x => x != null);
+}
diff --git a/src/remote/activitypub/renderer/person.ts b/src/remote/activitypub/renderer/person.ts
index 68f0bd83fe..77e60cd61a 100644
--- a/src/remote/activitypub/renderer/person.ts
+++ b/src/remote/activitypub/renderer/person.ts
@@ -8,6 +8,7 @@ import DriveFile from '../../../models/drive-file';
import { getEmojis } from './note';
import renderEmoji from './emoji';
import { IIdentifier } from '../models/identifier';
+import renderHashtag from './hashtag';
export default async (user: ILocalUser) => {
const id = `${config.url}/users/${user._id}`;
@@ -67,8 +68,11 @@ export default async (user: ILocalUser) => {
const emojis = await getEmojis(user.emojis);
const apemojis = emojis.map(emoji => renderEmoji(emoji));
+ const hashtagTags = (user.tags || []).map(tag => renderHashtag(tag));
+
const tag = [
...apemojis,
+ ...hashtagTags,
];
return {