No Description

MsgBase.ts 809B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { uuid } from '../utils/uuid';
  2. export type MsgType = 'text' | 'audio' | 'video' | 'image' |'cmd' | 'attachment';
  3. export type ChatType = 'chat' | 'room' | 'group' | 'push';
  4. export class MsgBase {
  5. // 消息编号
  6. id: string = uuid();
  7. // 消息发送方,如果是从多个人发出,则用 , 逗号分隔
  8. from: string;
  9. // 消息接收方/目标方,如果是发送给多个人,则用 , 逗号分隔
  10. to: string;
  11. // 聊天室类型
  12. type: ChatType;
  13. // 扩展消息
  14. ext: Record<string, string>;
  15. /** 校验当前消息是否有效 */
  16. isValid() {
  17. if (!this.from || !this.to) {
  18. return false;
  19. }
  20. return true;
  21. }
  22. static createMsg(baseMsg: Partial<MsgBase>): MsgBase {
  23. const msg = new MsgBase();
  24. Object.assign(msg, baseMsg);
  25. return msg;
  26. }
  27. }