mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-21 17:37:29 -07:00
Implement messaging/messages/read
This commit is contained in:
parent
5aa14820f1
commit
df20013938
1 changed files with 43 additions and 0 deletions
43
src/server/api/endpoints/messaging/messages/read.ts
Normal file
43
src/server/api/endpoints/messaging/messages/read.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import $ from 'cafy'; import ID from '../../../../../misc/cafy-id';
|
||||
import Message from '../../../../../models/messaging-message';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import read from '../../../common/read-messaging-message';
|
||||
import getParams from '../../../get-params';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
ja: '指定した自分宛てのメッセージを既読にします。',
|
||||
en: 'Mark as read a message of messaging.'
|
||||
},
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'messaging-write',
|
||||
|
||||
params: {
|
||||
messageId: $.type(ID).note({
|
||||
desc: {
|
||||
ja: '既読にするメッセージのID',
|
||||
en: 'The ID of a message that you want to mark as read'
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) throw psErr;
|
||||
|
||||
const message = await Message.findOne({
|
||||
_id: ps.messageId,
|
||||
recipientId: user._id
|
||||
});
|
||||
|
||||
if (message == null) {
|
||||
return rej('message not found');
|
||||
}
|
||||
|
||||
read(user._id, message.userId, message);
|
||||
|
||||
res();
|
||||
});
|
Loading…
Reference in a new issue