mirror of https://github.com/msgbyte/tailchat
				
				
				
			feat: 回复消息的发送消息时带上meta信息
							parent
							
								
									acceba8726
								
							
						
					
					
						commit
						40113194ea
					
				@ -0,0 +1,34 @@
 | 
			
		||||
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 };
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -1,4 +0,0 @@
 | 
			
		||||
import type { ChatMessage } from '../model/message';
 | 
			
		||||
 | 
			
		||||
const replyMsgFields = ['_id', 'content', 'author'] as const;
 | 
			
		||||
export type ReplyMsgType = Pick<ChatMessage, typeof replyMsgFields[number]>;
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue