@@ -43,23 +43,12 @@ export class AppComponent implements AfterViewInit, OnDestroy {
4343 private customTemplateService : CustomTemplatesService ,
4444 themeService : ThemeService
4545 ) {
46- const isDynamicUser = environment . userId === '<dynamic user>' ;
47- const userId = isDynamicUser ? uuidv4 ( ) : environment . userId ;
46+ const urlParams = new URLSearchParams ( window . location . search ) ;
47+ const userId = urlParams . get ( 'user' ) ?? '' ;
4848 void this . chatService . init (
4949 environment . apiKey ,
50- isDynamicUser ? { id : userId , name : names . random ( ) } : userId ,
51- environment . tokenUrl
52- ? async ( ) => {
53- const url = environment . tokenUrl . replace (
54- environment . userId ,
55- userId
56- ) ;
57- const response = await fetch ( url ) ;
58- const body = ( await response . json ( ) ) as { token : string } ;
59-
60- return body . token ;
61- }
62- : environment . userToken ,
50+ userId ,
51+ this . getTokenGenerator ( userId ) ,
6352 {
6453 timeout : 10000 ,
6554 logger : (
@@ -88,11 +77,11 @@ export class AppComponent implements AfterViewInit, OnDestroy {
8877 }
8978 ) ;
9079 void this . channelService . init (
91- environment . channelsFilter || {
80+ {
9281 type : 'messaging' ,
9382 members : { $in : [ environment . userId ] } ,
9483 } ,
95- undefined ,
84+ { has_unread : - 1 } ,
9685 { limit : 10 }
9786 ) ;
9887 this . subscriptions . push (
@@ -141,6 +130,19 @@ export class AppComponent implements AfterViewInit, OnDestroy {
141130 . subscribe ( ( isThreadOpen ) => ( this . isThreadOpen = isThreadOpen ) ) ;
142131 this . theme$ = themeService . theme$ ;
143132 }
133+
134+ getTokenGenerator ( userId : string ) {
135+ const oneDay = 24 * 60 * 60 ;
136+ return async ( ) => {
137+ const response = await fetch (
138+ `${ environment . tokenUrl } &user_id=${ userId } &exp=${ oneDay } `
139+ ) ;
140+ const body = await response . json ( ) ;
141+
142+ return body . token as string ;
143+ } ;
144+ }
145+
144146 ngOnDestroy ( ) : void {
145147 this . subscriptions . forEach ( ( s ) => s . unsubscribe ( ) ) ;
146148 }
0 commit comments