send/receive user hashtags via AP (#4064)
This commit is contained in:
parent
d140548784
commit
a6e7bbc306
6 changed files with 29 additions and 14 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue