@@ -54,9 +54,7 @@ const EventOptions = [closeEvent] as const;
54
54
const DEFAULT_SIZE = 378 ;
55
55
const DEFAULT_PADDING = 16 ;
56
56
57
- export const matrixClient : MatrixClient = sdk . createClient ( {
58
- baseUrl : "https://matrix.safiricabs.com" ,
59
- } ) ;
57
+ export let matrixClient : any = null ;
60
58
61
59
const DrawerWrapper = styled . div `
62
60
// Shield the mouse events of the lower layer, the mask can be closed in the edit mode to prevent the lower layer from sliding
@@ -109,6 +107,7 @@ export const meetingControllerChildren = {
109
107
showMask : withDefault ( BoolControl , true ) ,
110
108
credentials : withDefault ( StringControl , trans ( "chat.credentials" ) ) ,
111
109
roomAlias : withDefault ( StringControl , "" ) ,
110
+ matrixServerUrl : withDefault ( StringControl , "" ) ,
112
111
roomData : jsonObjectExposingStateControl ( "" ) ,
113
112
messages : stateComp < JSONValue > ( [ ] ) ,
114
113
participants : stateComp < JSONValue > ( [ ] ) ,
@@ -140,8 +139,6 @@ let MTComp = (function () {
140
139
[ dispatch , isTopBom ]
141
140
) ;
142
141
143
-
144
-
145
142
useEffect ( ( ) => {
146
143
if ( props . matrixAuthData . value . access_token == null ) return ;
147
144
resourcesInit ( ) ;
@@ -150,8 +147,8 @@ let MTComp = (function () {
150
147
useEffect ( ( ) => {
151
148
if ( props . roomData . value . roomId ) {
152
149
matrixClient
153
- . joinRoom ( `${ props . roomData . value . roomId } ` )
154
- . then ( async ( room ) => {
150
+ ? .joinRoom ( `${ props . roomData . value . roomId } ` )
151
+ . then ( async ( room : { getMembers : ( ) => any } ) => {
155
152
let members = room . getMembers ( ) ;
156
153
let participants : any = [ ] ;
157
154
members . forEach ( ( element : sdk . RoomMember ) => {
@@ -169,7 +166,13 @@ let MTComp = (function () {
169
166
) ;
170
167
171
168
matrixClient . scrollback ( room , 10 ) . then (
172
- function ( room ) {
169
+ function ( room : {
170
+ getLiveTimeline : ( ) => {
171
+ ( ) : any ;
172
+ new ( ) : any ;
173
+ getEvents : { ( ) : any ; new ( ) : any } ;
174
+ } ;
175
+ } ) {
173
176
let messagesdata : any = [ ] ;
174
177
var events = room . getLiveTimeline ( ) . getEvents ( ) ;
175
178
for ( var i = 0 ; i < events . length ; i ++ ) {
@@ -207,12 +210,12 @@ let MTComp = (function () {
207
210
208
211
dispatchMessages ( messagesdata ) ;
209
212
} ,
210
- function ( err ) {
213
+ function ( err : any ) {
211
214
console . log ( "/more Error: %s" , err ) ;
212
215
}
213
216
) ;
214
217
} )
215
- . catch ( ( e ) => console . log ( e ) ) ;
218
+ . catch ( ( e : any ) => console . log ( e ) ) ;
216
219
let messagesdata : any = [ ] ;
217
220
matrixClient . on (
218
221
"Room.timeline" as sdk . EmittedEvents ,
@@ -239,7 +242,6 @@ let MTComp = (function () {
239
242
}
240
243
} , [ props . roomData . value ] ) ;
241
244
242
-
243
245
let resourcesInit = ( ) => {
244
246
// show the room list after syncing.
245
247
matrixClient . on (
@@ -277,7 +279,6 @@ let MTComp = (function () {
277
279
) ;
278
280
} ;
279
281
280
-
281
282
return (
282
283
< BackgroundColorContext . Provider value = { props . style . background } >
283
284
< DrawerWrapper >
@@ -340,7 +341,7 @@ let MTComp = (function () {
340
341
</ DrawerWrapper >
341
342
</ BackgroundColorContext . Provider >
342
343
) ;
343
- }
344
+ }
344
345
)
345
346
. setPropertyViewFn ( ( children ) => (
346
347
< >
@@ -369,6 +370,9 @@ let MTComp = (function () {
369
370
{ children . showMask . propertyView ( {
370
371
label : trans ( "prop.showMask" ) ,
371
372
} ) }
373
+ { children . matrixServerUrl . propertyView ( {
374
+ label : trans ( "prop.matrixServerUrl" ) ,
375
+ } ) }
372
376
</ Section >
373
377
< Section name = { sectionNames . chats } >
374
378
{ children . roomAlias . propertyView ( {
@@ -410,15 +414,14 @@ MTComp = withMethodExposing(MTComp, [
410
414
params : [ ] ,
411
415
} ,
412
416
execute : async ( comp , values ) => {
413
- console . log ( values ) ;
417
+ console . log ( values ) ;
414
418
if ( values && values . length > 0 ) {
415
419
const firstValue = values [ 0 ] ;
416
420
if (
417
421
typeof firstValue === "object" &&
418
422
firstValue !== null &&
419
423
"name" in firstValue
420
- ) {
421
- console . log ( firstValue ) ;
424
+ ) {
422
425
const name : any = firstValue . name ;
423
426
const topic : any = firstValue . topic ;
424
427
// Create a room
@@ -428,11 +431,10 @@ MTComp = withMethodExposing(MTComp, [
428
431
name : name ,
429
432
topic : topic ,
430
433
} )
431
- . then ( ( response ) => {
434
+ . then ( ( response : { room_id : any } ) => {
432
435
const roomId = response . room_id ;
433
- console . log ( `Created room: ${ roomId } ` ) ;
434
436
} )
435
- . catch ( ( error ) => {
437
+ . catch ( ( error : { message : any } ) => {
436
438
console . error ( `Failed to create room: ${ error . message } ` ) ;
437
439
} ) ;
438
440
} else {
@@ -466,7 +468,7 @@ MTComp = withMethodExposing(MTComp, [
466
468
. then ( ( ) => {
467
469
console . log ( `Left room: ${ name } ` ) ;
468
470
} )
469
- . catch ( ( error ) => {
471
+ . catch ( ( error : { message : any } ) => {
470
472
console . error ( `Failed to leave room: ${ error . message } ` ) ;
471
473
} ) ;
472
474
} else {
@@ -515,27 +517,39 @@ MTComp = withMethodExposing(MTComp, [
515
517
params : [ ] ,
516
518
} ,
517
519
execute : async ( comp , values ) => {
518
- let response = await matrixClient . login ( "org.matrix.login.jwt" , {
519
- token : values [ 0 ] ,
520
- } ) ;
521
- await matrixClient . startClient ( ) ;
522
-
523
- let allRooms = await matrixClient . publicRooms ( ) ;
524
-
525
- let rooms : any = [ ] ;
526
- allRooms . chunk . forEach ( ( room ) => {
527
- rooms . push ( {
528
- name : room . name ,
529
- roomId : room . room_id ,
530
- membersCount : room . num_joined_members . toString ( ) ,
520
+ let url = `https://${ comp . children . matrixServerUrl . getView ( ) } ` ;
521
+ if ( comp . children . matrixServerUrl . getView ( ) ) {
522
+ matrixClient = sdk . createClient ( {
523
+ baseUrl : url ,
531
524
} ) ;
532
- } ) ;
525
+ let response = await matrixClient . login ( "org.matrix.login.jwt" , {
526
+ token : values [ 0 ] ,
527
+ } ) ;
528
+ await matrixClient . startClient ( ) ;
529
+
530
+ let allRooms = await matrixClient . publicRooms ( ) ;
531
+
532
+ let rooms : any = [ ] ;
533
+ allRooms . chunk . forEach (
534
+ ( room : {
535
+ name : any ;
536
+ room_id : any ;
537
+ num_joined_members : { toString : ( ) => any } ;
538
+ } ) => {
539
+ rooms . push ( {
540
+ name : room . name ,
541
+ roomId : room . room_id ,
542
+ membersCount : room . num_joined_members . toString ( ) ,
543
+ } ) ;
544
+ }
545
+ ) ;
533
546
534
- comp . children . matrixAuthData . change ( {
535
- access_token : response . access_token ,
536
- user_id : response . user_id ,
537
- rooms,
538
- } ) ;
547
+ comp . children . matrixAuthData . change ( {
548
+ access_token : response . access_token ,
549
+ user_id : response . user_id ,
550
+ rooms,
551
+ } ) ;
552
+ }
539
553
} ,
540
554
} ,
541
555
{
@@ -557,4 +571,5 @@ export const ChatControllerComp = withExposingConfigs(MTComp, [
557
571
new NameConfig ( "messages" , "" ) ,
558
572
new NameConfig ( "participants" , "" ) ,
559
573
new NameConfig ( "roomLists" , "" ) ,
574
+ new NameConfig ( "matrixServerUrl" , "" ) ,
560
575
] ) ;
0 commit comments