-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #870 from vector-im/implement-room-join-ui
Implement room join UI
- Loading branch information
Showing
10 changed files
with
250 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import {ViewModel, Options as BaseOptions} from "../ViewModel"; | ||
import {SegmentType} from "../navigation/index"; | ||
import type {Session} from "../../matrix/Session.js"; | ||
import {joinRoom} from "../../matrix/room/joinRoom"; | ||
|
||
type Options = BaseOptions & { | ||
session: Session; | ||
}; | ||
|
||
export class JoinRoomViewModel extends ViewModel<SegmentType, Options> { | ||
private _session: Session; | ||
private _joinInProgress: boolean = false; | ||
private _error: Error | undefined; | ||
|
||
constructor(options: Readonly<Options>) { | ||
super(options); | ||
this._session = options.session; | ||
} | ||
|
||
async join(roomId: string): Promise<void> { | ||
this._error = undefined; | ||
this._joinInProgress = true; | ||
this.emitChange("joinInProgress"); | ||
try { | ||
const id = await joinRoom(roomId, this._session); | ||
this.navigation.push("room", id); | ||
} | ||
catch (e) { | ||
this._error = e; | ||
this._joinInProgress = false; | ||
this.emitChange("error"); | ||
} | ||
} | ||
|
||
get joinInProgress(): boolean { | ||
return this._joinInProgress; | ||
} | ||
|
||
get status(): string | undefined { | ||
if (this._error) { | ||
return this._error.message; | ||
} | ||
else if(this._joinInProgress){ | ||
return "Joining room"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
import type {Session} from "../Session.js"; | ||
import {RoomStatus} from "./common"; | ||
|
||
/** | ||
* Join a room and wait for it to arrive in the next sync | ||
* @param roomId The id of the room to join | ||
* @param session A session instance | ||
*/ | ||
export async function joinRoom(roomId: string, session: Session): Promise<string> { | ||
try { | ||
const internalRoomId = await session.joinRoom(roomId); | ||
const roomStatusObservable = await session.observeRoomStatus(internalRoomId); | ||
await roomStatusObservable.waitFor((status: RoomStatus) => status === RoomStatus.Joined); | ||
return internalRoomId; | ||
} | ||
catch (e) { | ||
if ((e.statusCode ?? e.status) === 400) { | ||
throw new Error(`'${roomId}' is not a legal room ID or alias`); | ||
} else if ((e.statusCode ?? e.status) === 404 || (e.statusCode ?? e.status) === 502 || e.message == "Internal Server eor") { | ||
throw new Error(`Room '${roomId}' could not be found`); | ||
} else if ((e.statusCode ?? e.status) === 403) { | ||
throw new Error(`You are not invited to join '${roomId}'`); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import {TemplateView} from "../general/TemplateView"; | ||
import type {JoinRoomViewModel} from "../../../../domain/session/JoinRoomViewModel"; | ||
import {spinner} from "../common.js"; | ||
|
||
export class JoinRoomView extends TemplateView<JoinRoomViewModel> { | ||
render(t, vm) { | ||
const input = t.input({ | ||
type: "text", | ||
name: "id", | ||
id: "id", | ||
placeholder: vm.i18n`Enter a room id or alias`, | ||
disabled: vm => vm.joinInProgress, | ||
}); | ||
return t.main({className: "middle"}, | ||
t.div({className: "JoinRoomView centered-column"}, [ | ||
t.h2("Join room"), | ||
t.form({className: "JoinRoomView_detailsForm form", onSubmit: evt => this.onSubmit(evt, input.value)}, [ | ||
t.div({className: "vertical-layout"}, [ | ||
t.div({className: "stretch form-row text"}, [ | ||
t.label({for: "id"}, vm.i18n`Room id`), | ||
input, | ||
]), | ||
]), | ||
t.div({className: "button-row"}, [ | ||
t.button({ | ||
className: "button-action primary", | ||
type: "submit", | ||
disabled: vm => vm.joinInProgress | ||
}, vm.i18n`Join`), | ||
]), | ||
t.map(vm => vm.status, (status, t) => { | ||
return t.div({ className: "JoinRoomView_status" }, [ | ||
spinner(t, { hidden: vm => !vm.joinInProgress }), | ||
t.span(status), | ||
]); | ||
}) | ||
]) | ||
]) | ||
); | ||
} | ||
|
||
onSubmit(evt, id) { | ||
evt.preventDefault(); | ||
this.value.join(id); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.