@@ -43,23 +43,12 @@ export class AppComponent implements AfterViewInit, OnDestroy {
43
43
private customTemplateService : CustomTemplatesService ,
44
44
themeService : ThemeService
45
45
) {
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' ) ?? '' ;
48
48
void this . chatService . init (
49
49
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 ) ,
63
52
{
64
53
timeout : 10000 ,
65
54
logger : (
@@ -88,11 +77,11 @@ export class AppComponent implements AfterViewInit, OnDestroy {
88
77
}
89
78
) ;
90
79
void this . channelService . init (
91
- environment . channelsFilter || {
80
+ {
92
81
type : 'messaging' ,
93
82
members : { $in : [ environment . userId ] } ,
94
83
} ,
95
- undefined ,
84
+ { has_unread : - 1 } ,
96
85
{ limit : 10 }
97
86
) ;
98
87
this . subscriptions . push (
@@ -141,6 +130,19 @@ export class AppComponent implements AfterViewInit, OnDestroy {
141
130
. subscribe ( ( isThreadOpen ) => ( this . isThreadOpen = isThreadOpen ) ) ;
142
131
this . theme$ = themeService . theme$ ;
143
132
}
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
+
144
146
ngOnDestroy ( ) : void {
145
147
this . subscriptions . forEach ( ( s ) => s . unsubscribe ( ) ) ;
146
148
}
0 commit comments