@@ -51,40 +51,24 @@ export default defineComponent({
5151 setup() {
5252 const router = useRouter ();
5353 const route: any = useRoute ();
54- let currentGroup = ref ();
55- let currentUser = ref ();
56- let users = ref ();
54+ let currentGroup = ref <CometChat .Group >();
5755
58- var GUID = " supergroup" ;
59- CometChat .getGroup (GUID ).then (
60- (group ) => {
61- currentGroup .value = group ;
62- },
63- (error ) => {
64- console .log (" Group details fetching failed with exception:" , error );
65- }
66- );
67-
68- var limit = 30 ;
69- var usersRequest = new CometChat .UsersRequestBuilder ()
70- .setLimit (limit )
71- .build ();
72-
73- usersRequest .fetchNext ().then (
74- (userList ) => {
75- users .value = userList ;
76- currentUser .value = userList [0 ];
77- },
78- (error ) => {
79- console .log (" User list fetching failed with error:" , error );
80- }
81- );
8256 onBeforeMount (async () => {
83- currentUser .value = await CometChat .getUser (" superhero2" );
84- currentGroup .value = await CometChat .getGroup (" supergroup" );
57+ try {
58+ const groupsRequest = new CometChat .GroupsRequestBuilder ()
59+ .setLimit (1 )
60+ .joinedOnly (true )
61+ .build ();
62+ const fetchedGroups = await groupsRequest .fetchNext ();
63+ if (fetchedGroups && fetchedGroups .length > 0 ) {
64+ currentGroup .value = fetchedGroups [0 ];
65+ }
66+ } catch (error ) {
67+ console .error (" Error fetching groups:" , error );
68+ }
8569 });
8670
87- return { router , route , currentGroup , users , currentUser };
71+ return { router , route , currentGroup };
8872 },
8973});
9074 </script >
0 commit comments