mirror of https://github.com/msgbyte/tailchat
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
791 B
TypeScript
35 lines
791 B
TypeScript
4 years ago
|
import type {
|
||
|
ChatMessage,
|
||
|
SendMessagePayload,
|
||
|
SimpleMessagePayload,
|
||
|
} from '../model/message';
|
||
|
import _isNil from 'lodash/isNil';
|
||
|
import _set from 'lodash/set';
|
||
|
import _pick from 'lodash/pick';
|
||
|
|
||
|
const replyMsgFields = ['_id', 'content', 'author'] as const;
|
||
|
export type ReplyMsgType = Pick<ChatMessage, typeof replyMsgFields[number]>;
|
||
|
|
||
|
export class MessageHelper {
|
||
|
private payload: SendMessagePayload;
|
||
|
|
||
|
constructor(origin: SimpleMessagePayload) {
|
||
|
this.payload = { ...origin };
|
||
|
}
|
||
|
|
||
|
setReplyMsg(replyMsg: ReplyMsgType) {
|
||
|
if (_isNil(replyMsg)) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
_set(this.payload, ['meta', 'reply'], _pick(replyMsg, replyMsgFields));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 生成待发送的消息体
|
||
|
*/
|
||
|
generatePayload(): SendMessagePayload {
|
||
|
return { ...this.payload };
|
||
|
}
|
||
|
}
|