2019-08-18 03:42:58 +00:00
|
|
|
import { v4 as uuid } from 'uuid';
|
2022-08-03 11:18:33 +00:00
|
|
|
import config from '@/config/index.js';
|
2022-02-27 02:07:39 +00:00
|
|
|
import { getUserKeypair } from '@/misc/keypair-store.js';
|
|
|
|
import { User } from '@/models/entities/user.js';
|
2022-08-03 11:18:33 +00:00
|
|
|
import { IActivity } from '../type.js';
|
|
|
|
import { LdSignature } from '../misc/ld-signature.js';
|
2018-08-25 04:11:54 +00:00
|
|
|
|
2020-05-10 09:42:31 +00:00
|
|
|
export const renderActivity = (x: any): IActivity | null => {
|
2018-11-16 18:25:48 +00:00
|
|
|
if (x == null) return null;
|
|
|
|
|
2022-05-29 06:15:52 +00:00
|
|
|
if (typeof x === 'object' && x.id == null) {
|
2019-08-18 03:42:58 +00:00
|
|
|
x.id = `${config.url}/${uuid()}`;
|
2018-08-25 04:11:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Object.assign({
|
|
|
|
'@context': [
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
2021-05-19 07:00:08 +00:00
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
{
|
2023-05-30 15:53:50 +00:00
|
|
|
xsd: 'http://www.w3.org/2001/XMLSchema#',
|
2021-05-19 07:00:08 +00:00
|
|
|
// as non-standards
|
2023-05-30 15:53:50 +00:00
|
|
|
manuallyApprovesFollowers: {
|
|
|
|
'@id': 'as:manuallyApprovesFollowers',
|
|
|
|
'@type': 'xsd:boolean',
|
|
|
|
},
|
|
|
|
sensitive: {
|
|
|
|
'@id': 'as:sensitive',
|
|
|
|
'@type': 'xsd:boolean',
|
|
|
|
},
|
2021-05-19 07:00:08 +00:00
|
|
|
Hashtag: 'as:Hashtag',
|
|
|
|
// Mastodon
|
|
|
|
toot: 'http://joinmastodon.org/ns#',
|
|
|
|
Emoji: 'toot:Emoji',
|
2023-05-30 15:53:50 +00:00
|
|
|
featured: {
|
|
|
|
'@id': 'toot:featured',
|
|
|
|
'@type': '@id',
|
|
|
|
},
|
|
|
|
discoverable: {
|
|
|
|
'@id': 'toot:discoverable',
|
|
|
|
'@type': 'xsd:boolean',
|
|
|
|
},
|
2023-01-04 19:56:06 +00:00
|
|
|
// Fedibird
|
2023-05-30 15:53:50 +00:00
|
|
|
quoteUri: {
|
|
|
|
'@id': 'http://fedibird.com/ns#quoteUri',
|
|
|
|
'@type': '@id',
|
|
|
|
},
|
2021-05-19 07:00:08 +00:00
|
|
|
// schema
|
2023-05-30 15:53:50 +00:00
|
|
|
schema: 'http://schema.org/',
|
|
|
|
PropertyValue: {
|
|
|
|
'@id': 'schema:PropertyValue',
|
|
|
|
'@context': {
|
|
|
|
'value': 'schema:value',
|
|
|
|
'name': 'schema:name',
|
|
|
|
},
|
|
|
|
},
|
2021-05-19 07:00:08 +00:00
|
|
|
// Misskey
|
2022-01-22 16:52:35 +00:00
|
|
|
misskey: 'https://misskey-hub.net/ns#',
|
2023-05-30 15:53:50 +00:00
|
|
|
'_misskey_quote': {
|
|
|
|
'@id': 'misskey:_misskey_quote',
|
|
|
|
'@type': '@id',
|
|
|
|
},
|
|
|
|
'_misskey_talk': {
|
|
|
|
'@id': 'misskey:_misskey_talk',
|
|
|
|
'@type': 'xsd:boolean',
|
|
|
|
},
|
|
|
|
'isCat': {
|
|
|
|
'@id': 'misskey:isCat',
|
|
|
|
'@type': 'xsd:boolean',
|
|
|
|
},
|
2021-05-19 07:00:08 +00:00
|
|
|
// vcard
|
|
|
|
vcard: 'http://www.w3.org/2006/vcard/ns#',
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
|
|
|
],
|
2018-08-25 04:11:54 +00:00
|
|
|
}, x);
|
|
|
|
};
|
2020-05-10 09:42:31 +00:00
|
|
|
|
2021-03-24 02:05:37 +00:00
|
|
|
export const attachLdSignature = async (activity: any, user: { id: User['id']; host: null; }): Promise<IActivity | null> => {
|
2020-05-10 09:42:31 +00:00
|
|
|
if (activity == null) return null;
|
|
|
|
|
2021-03-22 06:14:54 +00:00
|
|
|
const keypair = await getUserKeypair(user.id);
|
2020-05-10 09:42:31 +00:00
|
|
|
|
|
|
|
const ldSignature = new LdSignature();
|
|
|
|
ldSignature.debug = false;
|
2022-08-10 14:36:54 +00:00
|
|
|
return await ldSignature.signRsaSignature2017(activity, keypair.privateKey, `${config.url}/users/${user.id}#main-key`);
|
2020-05-10 09:42:31 +00:00
|
|
|
};
|