Skip to content

Commit 9f4157e

Browse files
added home server url to data fields
1 parent 1976ab4 commit 9f4157e

File tree

3 files changed

+57
-40
lines changed

3 files changed

+57
-40
lines changed

client/packages/lowcoder/src/comps/comps/chatroom/chatControllerComp.tsx

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ const EventOptions = [closeEvent] as const;
5454
const DEFAULT_SIZE = 378;
5555
const DEFAULT_PADDING = 16;
5656

57-
export const matrixClient: MatrixClient = sdk.createClient({
58-
baseUrl: "https://matrix.safiricabs.com",
59-
});
57+
export let matrixClient: any = null;
6058

6159
const DrawerWrapper = styled.div`
6260
// 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 = {
109107
showMask: withDefault(BoolControl, true),
110108
credentials: withDefault(StringControl, trans("chat.credentials")),
111109
roomAlias: withDefault(StringControl, ""),
110+
matrixServerUrl: withDefault(StringControl, ""),
112111
roomData: jsonObjectExposingStateControl(""),
113112
messages: stateComp<JSONValue>([]),
114113
participants: stateComp<JSONValue>([]),
@@ -140,8 +139,6 @@ let MTComp = (function () {
140139
[dispatch, isTopBom]
141140
);
142141

143-
144-
145142
useEffect(() => {
146143
if (props.matrixAuthData.value.access_token == null) return;
147144
resourcesInit();
@@ -150,8 +147,8 @@ let MTComp = (function () {
150147
useEffect(() => {
151148
if (props.roomData.value.roomId) {
152149
matrixClient
153-
.joinRoom(`${props.roomData.value.roomId}`)
154-
.then(async (room) => {
150+
?.joinRoom(`${props.roomData.value.roomId}`)
151+
.then(async (room: { getMembers: () => any }) => {
155152
let members = room.getMembers();
156153
let participants: any = [];
157154
members.forEach((element: sdk.RoomMember) => {
@@ -169,7 +166,13 @@ let MTComp = (function () {
169166
);
170167

171168
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+
}) {
173176
let messagesdata: any = [];
174177
var events = room.getLiveTimeline().getEvents();
175178
for (var i = 0; i < events.length; i++) {
@@ -207,12 +210,12 @@ let MTComp = (function () {
207210

208211
dispatchMessages(messagesdata);
209212
},
210-
function (err) {
213+
function (err: any) {
211214
console.log("/more Error: %s", err);
212215
}
213216
);
214217
})
215-
.catch((e) => console.log(e));
218+
.catch((e: any) => console.log(e));
216219
let messagesdata: any = [];
217220
matrixClient.on(
218221
"Room.timeline" as sdk.EmittedEvents,
@@ -239,7 +242,6 @@ let MTComp = (function () {
239242
}
240243
}, [props.roomData.value]);
241244

242-
243245
let resourcesInit = () => {
244246
// show the room list after syncing.
245247
matrixClient.on(
@@ -277,7 +279,6 @@ let MTComp = (function () {
277279
);
278280
};
279281

280-
281282
return (
282283
<BackgroundColorContext.Provider value={props.style.background}>
283284
<DrawerWrapper>
@@ -340,7 +341,7 @@ let MTComp = (function () {
340341
</DrawerWrapper>
341342
</BackgroundColorContext.Provider>
342343
);
343-
}
344+
}
344345
)
345346
.setPropertyViewFn((children) => (
346347
<>
@@ -369,6 +370,9 @@ let MTComp = (function () {
369370
{children.showMask.propertyView({
370371
label: trans("prop.showMask"),
371372
})}
373+
{children.matrixServerUrl.propertyView({
374+
label: trans("prop.matrixServerUrl"),
375+
})}
372376
</Section>
373377
<Section name={sectionNames.chats}>
374378
{children.roomAlias.propertyView({
@@ -410,15 +414,14 @@ MTComp = withMethodExposing(MTComp, [
410414
params: [],
411415
},
412416
execute: async (comp, values) => {
413-
console.log(values);
417+
console.log(values);
414418
if (values && values.length > 0) {
415419
const firstValue = values[0];
416420
if (
417421
typeof firstValue === "object" &&
418422
firstValue !== null &&
419423
"name" in firstValue
420-
) {
421-
console.log(firstValue);
424+
) {
422425
const name: any = firstValue.name;
423426
const topic: any = firstValue.topic;
424427
// Create a room
@@ -428,11 +431,10 @@ MTComp = withMethodExposing(MTComp, [
428431
name: name,
429432
topic: topic,
430433
})
431-
.then((response) => {
434+
.then((response: { room_id: any }) => {
432435
const roomId = response.room_id;
433-
console.log(`Created room: ${roomId}`);
434436
})
435-
.catch((error) => {
437+
.catch((error: { message: any }) => {
436438
console.error(`Failed to create room: ${error.message}`);
437439
});
438440
} else {
@@ -466,7 +468,7 @@ MTComp = withMethodExposing(MTComp, [
466468
.then(() => {
467469
console.log(`Left room: ${name}`);
468470
})
469-
.catch((error) => {
471+
.catch((error: { message: any }) => {
470472
console.error(`Failed to leave room: ${error.message}`);
471473
});
472474
} else {
@@ -515,27 +517,39 @@ MTComp = withMethodExposing(MTComp, [
515517
params: [],
516518
},
517519
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,
531524
});
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+
);
533546

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+
}
539553
},
540554
},
541555
{
@@ -557,4 +571,5 @@ export const ChatControllerComp = withExposingConfigs(MTComp, [
557571
new NameConfig("messages", ""),
558572
new NameConfig("participants", ""),
559573
new NameConfig("roomLists", ""),
574+
new NameConfig("matrixServerUrl", ""),
560575
]);

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export const en = {
198198
maskClosable: "Click Outside to Close",
199199
showMask: "Show Mask",
200200
textOverflow: "Text Overflow",
201+
matrixServerUrl: "Matrix Server Url",
201202
},
202203
autoHeightProp: {
203204
auto: "Auto",

client/packages/lowcoder/src/i18n/locales/translation_files/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@
180180
"showBody": "Show Body",
181181
"showFooter": "Show Footer",
182182
"maskClosable": "Click Outside to Close",
183-
"showMask": "Show Mask"
183+
"showMask": "Show Mask",
184+
"matrixServerUrl": "Matrix Server Url"
184185
},
185186
"autoHeightProp": {
186187
"auto": "Auto",

0 commit comments

Comments
 (0)