Merge branch 'develop' of https://github.com/syuilo/misskey into develop

This commit is contained in:
syuilo 2020-11-01 12:26:58 +09:00
commit 580f6a5b6c
4 changed files with 65 additions and 12 deletions

View file

@ -2,7 +2,8 @@ import config from '../../config';
import { Note } from '../../models/entities/note';
import { User, IRemoteUser } from '../../models/entities/user';
import { UserPublickey } from '../../models/entities/user-publickey';
import { Notes, Users, UserPublickeys } from '../../models';
import { MessagingMessage } from '../../models/entities/messaging-message';
import { Notes, Users, UserPublickeys, MessagingMessages } from '../../models';
import { IObject, getApId } from './type';
import { resolvePerson } from './models/person';
import { ensure } from '../../prelude/ensure';
@ -33,6 +34,24 @@ export default class DbResolver {
return null;
}
public async getMessageFromApId(value: string | IObject): Promise<MessagingMessage | null> {
const parsed = this.parseUri(value);
if (parsed.id) {
return (await MessagingMessages.findOne({
id: parsed.id
})) || null;
}
if (parsed.uri) {
return (await MessagingMessages.findOne({
uri: parsed.uri
})) || null;
}
return null;
}
/**
* AP Person => Misskey User in DB
*/

View file

@ -3,6 +3,7 @@ import deleteNode from '../../../../services/note/delete';
import { apLogger } from '../../logger';
import DbResolver from '../../db-resolver';
import { getApLock } from '../../../../misc/app-lock';
import { deleteMessage } from '../../../../services/messages/delete';
const logger = apLogger;
@ -16,7 +17,16 @@ export default async function(actor: IRemoteUser, uri: string): Promise<string>
const note = await dbResolver.getNoteFromApId(uri);
if (note == null) {
return 'note not found';
const message = await dbResolver.getMessageFromApId(uri);
if (message == null) return 'message not found';
if (message.userId !== actor.id) {
return '投稿を削除しようとしているユーザーは投稿の作成者ではありません';
}
await deleteMessage(message);
return 'ok: message deleted';
}
if (note.userId !== actor.id) {
@ -24,7 +34,7 @@ export default async function(actor: IRemoteUser, uri: string): Promise<string>
}
await deleteNode(actor, note);
return 'ok: deleted';
return 'ok: note deleted';
} finally {
unlock();
}

View file

@ -1,10 +1,10 @@
import $ from 'cafy';
import { ID } from '../../../../../misc/cafy-id';
import define from '../../../define';
import { publishMessagingStream, publishGroupMessagingStream } from '../../../../../services/stream';
import * as ms from 'ms';
import { ApiError } from '../../../error';
import { MessagingMessages } from '../../../../../models';
import { deleteMessage } from '../../../../../services/messages/delete';
export const meta = {
desc: {
@ -53,12 +53,5 @@ export default define(meta, async (ps, user) => {
throw new ApiError(meta.errors.noSuchMessage);
}
await MessagingMessages.delete(message.id);
if (message.recipientId) {
publishMessagingStream(message.userId, message.recipientId, 'deleted', message.id);
publishMessagingStream(message.recipientId, message.userId, 'deleted', message.id);
} else if (message.groupId) {
publishGroupMessagingStream(message.groupId, 'deleted', message.id);
}
await deleteMessage(message);
});

View file

@ -0,0 +1,31 @@
import config from '../../config';
import { ensure } from '../../prelude/ensure';
import { MessagingMessages, Users } from '../../models';
import { MessagingMessage } from '../../models/entities/messaging-message';
import { publishGroupMessagingStream, publishMessagingStream } from '../stream';
import { renderActivity } from '../../remote/activitypub/renderer';
import renderDelete from '../../remote/activitypub/renderer/delete';
import renderTombstone from '../../remote/activitypub/renderer/tombstone';
import { deliver } from '../../queue';
export async function deleteMessage(message: MessagingMessage) {
await MessagingMessages.delete(message.id);
postDeleteMessage(message);
}
async function postDeleteMessage(message: MessagingMessage) {
if (message.recipientId) {
const user = await Users.findOne(message.userId).then(ensure);
const recipient = await Users.findOne(message.recipientId).then(ensure);
if (Users.isLocalUser(user)) publishMessagingStream(message.userId, message.recipientId, 'deleted', message.id);
if (Users.isLocalUser(recipient)) publishMessagingStream(message.recipientId, message.userId, 'deleted', message.id);
if (Users.isLocalUser(user) && Users.isRemoteUser(recipient)) {
const activity = renderActivity(renderDelete(renderTombstone(`${config.url}/notes/${message.id}`), user));
deliver(user, activity, recipient.inbox);
}
} else if (message.groupId) {
publishGroupMessagingStream(message.groupId, 'deleted', message.id);
}
}