-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement room join UI #870
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cfbd067
Refactor left panel to use menu
MidhunSureshR 413ba32
add "join-room" segment
MidhunSureshR c27dd97
Add vm/view
MidhunSureshR 8492062
Add join vm to session vm
MidhunSureshR f1b86e3
Add method to show join room view
MidhunSureshR 2d4b6b0
Exctract into function
MidhunSureshR d6ba218
Return view from SessionView
MidhunSureshR 3426240
Style JoinRoom View
MidhunSureshR 44eddd0
Call method from menu
MidhunSureshR 8809162
Rename variable
MidhunSureshR 1898c48
Specify return type
MidhunSureshR 67dfbc5
Add return type
MidhunSureshR 2e94700
Update src/platform/web/ui/session/JoinRoomView.ts
bwindels File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once this gets converted to TS this line will cause it to complain
cc @MidhunSureshR @bwindels
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because I forgot to add
join-room
here.