メッセージ (トーク/チャット) 削除の連合 (#6789)
This commit is contained in:
parent
c055b4d32d
commit
cd0b0012d9
@ -2,7 +2,8 @@ import config from '../../config';
|
|||||||
import { Note } from '../../models/entities/note';
|
import { Note } from '../../models/entities/note';
|
||||||
import { User, IRemoteUser } from '../../models/entities/user';
|
import { User, IRemoteUser } from '../../models/entities/user';
|
||||||
import { UserPublickey } from '../../models/entities/user-publickey';
|
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 { IObject, getApId } from './type';
|
||||||
import { resolvePerson } from './models/person';
|
import { resolvePerson } from './models/person';
|
||||||
import { ensure } from '../../prelude/ensure';
|
import { ensure } from '../../prelude/ensure';
|
||||||
@ -33,6 +34,24 @@ export default class DbResolver {
|
|||||||
return null;
|
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
|
* AP Person => Misskey User in DB
|
||||||
*/
|
*/
|
||||||
|
@ -3,6 +3,7 @@ import deleteNode from '../../../../services/note/delete';
|
|||||||
import { apLogger } from '../../logger';
|
import { apLogger } from '../../logger';
|
||||||
import DbResolver from '../../db-resolver';
|
import DbResolver from '../../db-resolver';
|
||||||
import { getApLock } from '../../../../misc/app-lock';
|
import { getApLock } from '../../../../misc/app-lock';
|
||||||
|
import { deleteMessage } from '../../../../services/messages/delete';
|
||||||
|
|
||||||
const logger = apLogger;
|
const logger = apLogger;
|
||||||
|
|
||||||
@ -16,7 +17,16 @@ export default async function(actor: IRemoteUser, uri: string): Promise<string>
|
|||||||
const note = await dbResolver.getNoteFromApId(uri);
|
const note = await dbResolver.getNoteFromApId(uri);
|
||||||
|
|
||||||
if (note == null) {
|
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) {
|
if (note.userId !== actor.id) {
|
||||||
@ -24,7 +34,7 @@ export default async function(actor: IRemoteUser, uri: string): Promise<string>
|
|||||||
}
|
}
|
||||||
|
|
||||||
await deleteNode(actor, note);
|
await deleteNode(actor, note);
|
||||||
return 'ok: deleted';
|
return 'ok: note deleted';
|
||||||
} finally {
|
} finally {
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import $ from 'cafy';
|
import $ from 'cafy';
|
||||||
import { ID } from '../../../../../misc/cafy-id';
|
import { ID } from '../../../../../misc/cafy-id';
|
||||||
import define from '../../../define';
|
import define from '../../../define';
|
||||||
import { publishMessagingStream, publishGroupMessagingStream } from '../../../../../services/stream';
|
|
||||||
import * as ms from 'ms';
|
import * as ms from 'ms';
|
||||||
import { ApiError } from '../../../error';
|
import { ApiError } from '../../../error';
|
||||||
import { MessagingMessages } from '../../../../../models';
|
import { MessagingMessages } from '../../../../../models';
|
||||||
|
import { deleteMessage } from '../../../../../services/messages/delete';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
@ -53,12 +53,5 @@ export default define(meta, async (ps, user) => {
|
|||||||
throw new ApiError(meta.errors.noSuchMessage);
|
throw new ApiError(meta.errors.noSuchMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
await MessagingMessages.delete(message.id);
|
await deleteMessage(message);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
31
src/services/messages/delete.ts
Normal file
31
src/services/messages/delete.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user