server.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import TUICore, { TUIConstants } from '@tencentcloud/tui-core';
  2. import {
  3. TUIUserService,
  4. TUIGroupService,
  5. TUIFriendService,
  6. TUIStore,
  7. StoreName,
  8. } from '@tencentcloud/chat-uikit-engine';
  9. import { isUniFrameWork } from '../../utils/env';
  10. import { TUIGlobal } from '@tencentcloud/universal-api';
  11. export default class TUISearchServer {
  12. constructor() {
  13. TUICore.registerService(TUIConstants.TUISearch.SERVICE.NAME, this);
  14. TUICore.registerExtension(TUIConstants.TUIChat.EXTENSION.INPUT_MORE.EXT_ID, this);
  15. }
  16. public onCall(method: string, params: { [propsName: string]: string }) {
  17. switch (method) {
  18. case TUIConstants.TUISearch.SERVICE.METHOD.SEARCH_GROUP:
  19. return this.searchGroup(params?.groupID);
  20. case TUIConstants.TUISearch.SERVICE.METHOD.SEARCH_USER:
  21. return this.searchUser(params?.userID);
  22. case TUIConstants.TUISearch.SERVICE.METHOD.SEARCH_FRIEND:
  23. return this.searchFriend(params?.userID);
  24. case TUIConstants.TUISearch.SERVICE.METHOD.SEARCH_GROUP_MEMBER:
  25. return this.searchGroupMember(params?.groupID, params?.userID);
  26. }
  27. }
  28. public onGetExtension(extensionID: string) {
  29. if (extensionID === TUIConstants.TUIChat.EXTENSION.INPUT_MORE.EXT_ID) {
  30. const list: any[] = [];
  31. const searchExtension = {
  32. weight: 3000,
  33. text: '搜索',
  34. icon: 'https://web.sdk.qcloud.com/component/TUIKit/assets/message-search.svg',
  35. data: {
  36. name: 'search',
  37. },
  38. listener: {
  39. onClicked: () => {
  40. TUIStore.update(StoreName.SEARCH, 'isShowInConversationSearch', true);
  41. isUniFrameWork && TUIGlobal?.navigateTo({
  42. url: '/TUIKit/components/TUISearch/index',
  43. });
  44. },
  45. },
  46. };
  47. list.push(searchExtension);
  48. return list;
  49. }
  50. }
  51. public async searchFriend(userID: string) {
  52. return TUIFriendService.getFriendProfile({ userIDList: [userID] });
  53. }
  54. public async searchUser(userID: string) {
  55. return TUIUserService.getUserProfile({ userIDList: [userID] });
  56. }
  57. public async searchGroup(groupID: string) {
  58. return TUIGroupService.searchGroupByID(groupID);
  59. }
  60. public async searchGroupMember(groupID: string, userID: string) {
  61. return TUIGroupService.getGroupMemberProfile({
  62. groupID,
  63. userIDList: [userID],
  64. });
  65. }
  66. }