mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-13 21:40:45 +01:00
Create ActivityでattributedToの補完とaudienceのコピーを行うように (#5873)
* attributedTo * Create * copy audiences between activity <=> object * やっぱり匿名GETのpublicは必要 * fix
This commit is contained in:
parent
b2859bcd2a
commit
aa573c0063
3 changed files with 23 additions and 12 deletions
|
@ -3,6 +3,7 @@ import { IRemoteUser } from '../../../../models/entities/user';
|
||||||
import createNote from './note';
|
import createNote from './note';
|
||||||
import { ICreate, getApId, validPost } from '../../type';
|
import { ICreate, getApId, validPost } from '../../type';
|
||||||
import { apLogger } from '../../logger';
|
import { apLogger } from '../../logger';
|
||||||
|
import { toArray, concat, unique } from '../../../../prelude/array';
|
||||||
|
|
||||||
const logger = apLogger;
|
const logger = apLogger;
|
||||||
|
|
||||||
|
@ -11,6 +12,22 @@ export default async (actor: IRemoteUser, activity: ICreate): Promise<void> => {
|
||||||
|
|
||||||
logger.info(`Create: ${uri}`);
|
logger.info(`Create: ${uri}`);
|
||||||
|
|
||||||
|
// copy audiences between activity <=> object.
|
||||||
|
if (typeof activity.object === 'object') {
|
||||||
|
const to = unique(concat([toArray(activity.to), toArray(activity.object.to)]));
|
||||||
|
const cc = unique(concat([toArray(activity.cc), toArray(activity.object.cc)]));
|
||||||
|
|
||||||
|
activity.to = to;
|
||||||
|
activity.cc = cc;
|
||||||
|
activity.object.to = to;
|
||||||
|
activity.object.cc = cc;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there is no attributedTo, use Activity actor.
|
||||||
|
if (typeof activity.object === 'object' && !activity.object.attributedTo) {
|
||||||
|
activity.object.attributedTo = activity.actor;
|
||||||
|
}
|
||||||
|
|
||||||
const resolver = new Resolver();
|
const resolver = new Resolver();
|
||||||
|
|
||||||
const object = await resolver.resolve(activity.object).catch(e => {
|
const object = await resolver.resolve(activity.object).catch(e => {
|
||||||
|
|
|
@ -15,7 +15,7 @@ export default async function(resolver: Resolver, actor: IRemoteUser, note: IObj
|
||||||
try {
|
try {
|
||||||
const exist = await fetchNote(note);
|
const exist = await fetchNote(note);
|
||||||
if (exist == null) {
|
if (exist == null) {
|
||||||
await createNote(note, resolver, silent, activity);
|
await createNote(note, resolver, silent);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
unlock();
|
unlock();
|
||||||
|
|
|
@ -17,7 +17,7 @@ import { deliverQuestionUpdate } from '../../../services/note/polls/update';
|
||||||
import { extractDbHost, toPuny } from '../../../misc/convert-host';
|
import { extractDbHost, toPuny } from '../../../misc/convert-host';
|
||||||
import { Notes, Emojis, Polls, MessagingMessages } from '../../../models';
|
import { Notes, Emojis, Polls, MessagingMessages } from '../../../models';
|
||||||
import { Note } from '../../../models/entities/note';
|
import { Note } from '../../../models/entities/note';
|
||||||
import { IObject, getOneApId, getApId, validPost, ICreate, isCreate, IPost } from '../type';
|
import { IObject, getOneApId, getApId, validPost, IPost } from '../type';
|
||||||
import { Emoji } from '../../../models/entities/emoji';
|
import { Emoji } from '../../../models/entities/emoji';
|
||||||
import { genId } from '../../../misc/gen-id';
|
import { genId } from '../../../misc/gen-id';
|
||||||
import { fetchMeta } from '../../../misc/fetch-meta';
|
import { fetchMeta } from '../../../misc/fetch-meta';
|
||||||
|
@ -78,7 +78,7 @@ export async function fetchNote(value: string | IObject, resolver?: Resolver): P
|
||||||
/**
|
/**
|
||||||
* Noteを作成します。
|
* Noteを作成します。
|
||||||
*/
|
*/
|
||||||
export async function createNote(value: string | IObject, resolver?: Resolver, silent = false, activity?: ICreate): Promise<Note | null> {
|
export async function createNote(value: string | IObject, resolver?: Resolver, silent = false): Promise<Note | null> {
|
||||||
if (resolver == null) resolver = new Resolver();
|
if (resolver == null) resolver = new Resolver();
|
||||||
|
|
||||||
const object: any = await resolver.resolve(value);
|
const object: any = await resolver.resolve(value);
|
||||||
|
@ -112,18 +112,12 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s
|
||||||
|
|
||||||
const noteAudience = await parseAudience(actor, note.to, note.cc);
|
const noteAudience = await parseAudience(actor, note.to, note.cc);
|
||||||
let visibility = noteAudience.visibility;
|
let visibility = noteAudience.visibility;
|
||||||
let visibleUsers = noteAudience.visibleUsers;
|
const visibleUsers = noteAudience.visibleUsers;
|
||||||
let apMentions = noteAudience.mentionedUsers;
|
const apMentions = noteAudience.mentionedUsers;
|
||||||
|
|
||||||
// Audience (to, cc) が指定されてなかった場合
|
// Audience (to, cc) が指定されてなかった場合
|
||||||
if (visibility === 'specified' && visibleUsers.length === 0) {
|
if (visibility === 'specified' && visibleUsers.length === 0) {
|
||||||
if (activity && isCreate(activity)) {
|
if (typeof value === 'string') { // 入力がstringならばresolverでGETが発生している
|
||||||
// Create 起因ならば Activity を見る
|
|
||||||
const activityAudience = await parseAudience(actor, activity.to, activity.cc);
|
|
||||||
visibility = activityAudience.visibility;
|
|
||||||
visibleUsers = activityAudience.visibleUsers;
|
|
||||||
apMentions = activityAudience.mentionedUsers;
|
|
||||||
} else if (typeof value === 'string') { // 入力がstringならばresolverでGETが発生している
|
|
||||||
// こちらから匿名GET出来たものならばpublic
|
// こちらから匿名GET出来たものならばpublic
|
||||||
visibility = 'public';
|
visibility = 'public';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue