No Description

MsgBase.ts 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { uuid } from '../utils/uuid';
  2. export type MsgType = 'text' | 'media' | 'cmd' | 'attachment';
  3. export type RoomType = 'single' | 'room';
  4. export type GroupOption = {
  5. subject: string; // 群名称
  6. description: string; // 群简介
  7. members: string[]; // 成员列表
  8. optionsPublic: boolean; // 允许任何人加入
  9. optionsModerate: boolean; // 加入需审批
  10. optionsMembersOnly: boolean; // 不允许任何人主动加入
  11. optionsAllowInvites: boolean; // 允许群人员邀请
  12. };
  13. export class MsgBase {
  14. // 消息编号
  15. id: string = uuid();
  16. // 消息发送方,如果是从多个人发出,则用 , 逗号分隔
  17. from: string;
  18. // 消息接收方/目标方,如果是发送给多个人,则用 , 逗号分隔
  19. to: string;
  20. // 消息类型
  21. type: MsgType;
  22. // 聊天室类型
  23. roomType: RoomType;
  24. // 扩展消息
  25. ext: Record<string, string>;
  26. /** 校验当前消息是否有效 */
  27. isValid() {
  28. if (!this.from || !this.to) {
  29. return false;
  30. }
  31. return true;
  32. }
  33. static createMsg(baseMsg: Partial<MsgBase>): MsgBase {
  34. const msg = new MsgBase();
  35. Object.assign(msg, baseMsg);
  36. return msg;
  37. }
  38. }