server.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import TUICore, { TUIConstants } from '@tencentcloud/tui-core';
  2. import { TUITranslateService } from '@tencentcloud/chat-uikit-engine';
  3. import { isPC } from '../../../utils/env';
  4. import createGroup from '../../../assets/icon/start-group.svg';
  5. import C2C from '../../../assets/icon/icon-c2c.svg';
  6. import { CONV_CREATE_TYPE } from '../../../constant';
  7. export interface IMenuItem {
  8. icon?: string;
  9. text: string;
  10. data: {
  11. name: string;
  12. children?: any[];
  13. };
  14. listener?: {
  15. onClicked: (...args: any[]) => void;
  16. };
  17. }
  18. export default class ConversationHeaderServer {
  19. static instance: ConversationHeaderServer;
  20. static getInstance(): ConversationHeaderServer {
  21. if (!ConversationHeaderServer.instance) {
  22. ConversationHeaderServer.instance = new ConversationHeaderServer();
  23. }
  24. return ConversationHeaderServer.instance;
  25. }
  26. public getMenu(): any[] {
  27. const list = this.generateMenuList();
  28. if (!isPC && list.length > 0) {
  29. return [{
  30. text: TUITranslateService.t('TUIConversation.发起会话'),
  31. data: {
  32. name: 'all',
  33. children: list,
  34. },
  35. }];
  36. }
  37. return list;
  38. }
  39. private generateMenuList(): any[] {
  40. const list = [
  41. {
  42. icon: C2C,
  43. text: TUITranslateService.t('TUIConversation.发起单聊'),
  44. data: {
  45. name: CONV_CREATE_TYPE.TYPEC2C,
  46. },
  47. listener: {
  48. onClicked: this.createConversation.bind(this),
  49. },
  50. },
  51. {
  52. icon: createGroup,
  53. text: TUITranslateService.t('TUIConversation.发起群聊'),
  54. data: {
  55. name: CONV_CREATE_TYPE.TYPEGROUP,
  56. },
  57. listener: {
  58. onClicked: this.createConversation.bind(this),
  59. },
  60. },
  61. ];
  62. return list;
  63. }
  64. private createConversation(item: IMenuItem) {
  65. // Create a conversation and notify conversationServer via TUICore.callService
  66. TUICore.callService({
  67. serviceName: TUIConstants.TUIConversation.SERVICE.NAME,
  68. method: TUIConstants.TUIConversation.SERVICE.METHOD.CREATE_CONVERSATION,
  69. params: item,
  70. });
  71. }
  72. }