mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-12-05 02:08:56 +09:00
wip
This commit is contained in:
parent
553fccd719
commit
92dd4b3e5a
@ -11,3 +11,30 @@ export type IMessagingHistory = {
|
|||||||
partnerId: mongo.ObjectID;
|
partnerId: mongo.ObjectID;
|
||||||
messageId: mongo.ObjectID;
|
messageId: mongo.ObjectID;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MessagingHistoryを物理削除します
|
||||||
|
*/
|
||||||
|
export async function deleteMessagingHistory(messagingHistory: string | mongo.ObjectID | IMessagingHistory) {
|
||||||
|
let m: IMessagingHistory;
|
||||||
|
|
||||||
|
// Populate
|
||||||
|
if (mongo.ObjectID.prototype.isPrototypeOf(messagingHistory)) {
|
||||||
|
m = await MessagingHistory.findOne({
|
||||||
|
_id: messagingHistory
|
||||||
|
});
|
||||||
|
} else if (typeof messagingHistory === 'string') {
|
||||||
|
m = await MessagingHistory.findOne({
|
||||||
|
_id: new mongo.ObjectID(messagingHistory)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
m = messagingHistory as IMessagingHistory;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m == null) return;
|
||||||
|
|
||||||
|
// このMessagingHistoryを削除
|
||||||
|
await MessagingHistory.remove({
|
||||||
|
_id: m._id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@ import deepcopy = require('deepcopy');
|
|||||||
import { pack as packUser } from './user';
|
import { pack as packUser } from './user';
|
||||||
import { pack as packFile } from './drive-file';
|
import { pack as packFile } from './drive-file';
|
||||||
import db from '../db/mongodb';
|
import db from '../db/mongodb';
|
||||||
|
import MessagingHistory, { deleteMessagingHistory } from './messaging-history';
|
||||||
|
|
||||||
const MessagingMessage = db.get<IMessagingMessage>('messagingMessages');
|
const MessagingMessage = db.get<IMessagingMessage>('messagingMessages');
|
||||||
export default MessagingMessage;
|
export default MessagingMessage;
|
||||||
@ -22,13 +23,40 @@ export function isValidText(text: string): boolean {
|
|||||||
return text.length <= 1000 && text.trim() != '';
|
return text.length <= 1000 && text.trim() != '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MessagingMessageを物理削除します
|
||||||
|
*/
|
||||||
|
export async function deleteMessagingMessage(messagingMessage: string | mongo.ObjectID | IMessagingMessage) {
|
||||||
|
let m: IMessagingMessage;
|
||||||
|
|
||||||
|
// Populate
|
||||||
|
if (mongo.ObjectID.prototype.isPrototypeOf(messagingMessage)) {
|
||||||
|
m = await MessagingMessage.findOne({
|
||||||
|
_id: messagingMessage
|
||||||
|
});
|
||||||
|
} else if (typeof messagingMessage === 'string') {
|
||||||
|
m = await MessagingMessage.findOne({
|
||||||
|
_id: new mongo.ObjectID(messagingMessage)
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
m = messagingMessage as IMessagingMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m == null) return;
|
||||||
|
|
||||||
|
// このMessagingMessageを指すMessagingHistoryをすべて削除
|
||||||
|
await Promise.all((
|
||||||
|
await MessagingHistory.find({ messageId: m._id })
|
||||||
|
).map(x => deleteMessagingHistory(x)));
|
||||||
|
|
||||||
|
// このMessagingMessageを削除
|
||||||
|
await MessagingMessage.remove({
|
||||||
|
_id: m._id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pack a messaging message for API response
|
* Pack a messaging message for API response
|
||||||
*
|
|
||||||
* @param {any} message
|
|
||||||
* @param {any} me?
|
|
||||||
* @param {any} options?
|
|
||||||
* @return {Promise<any>}
|
|
||||||
*/
|
*/
|
||||||
export const pack = (
|
export const pack = (
|
||||||
message: any,
|
message: any,
|
||||||
|
@ -11,6 +11,8 @@ import AccessToken, { deleteAccessToken } from './access-token';
|
|||||||
import NoteWatching, { deleteNoteWatching } from './note-watching';
|
import NoteWatching, { deleteNoteWatching } from './note-watching';
|
||||||
import Favorite, { deleteFavorite } from './favorite';
|
import Favorite, { deleteFavorite } from './favorite';
|
||||||
import NoteReaction, { deleteNoteReaction } from './note-reaction';
|
import NoteReaction, { deleteNoteReaction } from './note-reaction';
|
||||||
|
import MessagingMessage, { deleteMessagingMessage } from './messaging-message';
|
||||||
|
import MessagingHistory, { deleteMessagingHistory } from './messaging-history';
|
||||||
|
|
||||||
const User = db.get<IUser>('users');
|
const User = db.get<IUser>('users');
|
||||||
|
|
||||||
@ -173,8 +175,19 @@ export async function deleteUser(user: string | mongo.ObjectID | IUser) {
|
|||||||
).map(x => deleteFavorite(x)));
|
).map(x => deleteFavorite(x)));
|
||||||
|
|
||||||
// このユーザーのMessageをすべて削除
|
// このユーザーのMessageをすべて削除
|
||||||
|
await Promise.all((
|
||||||
|
await MessagingMessage.find({ userId: u._id })
|
||||||
|
).map(x => deleteMessagingMessage(x)));
|
||||||
|
|
||||||
// このユーザーへのMessageをすべて削除
|
// このユーザーへのMessageをすべて削除
|
||||||
|
await Promise.all((
|
||||||
|
await MessagingMessage.find({ recipientId: u._id })
|
||||||
|
).map(x => deleteMessagingMessage(x)));
|
||||||
|
|
||||||
|
// このユーザーの関わるMessagingHistoryをすべて削除
|
||||||
|
await Promise.all((
|
||||||
|
await MessagingHistory.find({ $or: [{ partnerId: u._id }, { userId: u._id }] })
|
||||||
|
).map(x => deleteMessagingHistory(x)));
|
||||||
|
|
||||||
// このユーザーのDriveFileをすべて削除
|
// このユーザーのDriveFileをすべて削除
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user