Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Chatterbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
element-hq
Chatterbox
Commits
5fdef677
Commit
5fdef677
authored
3 years ago
by
Midhun Suresh
Browse files
Options
Downloads
Patches
Plain Diff
Implement room join after registration
parent
8e187b5b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Hydrogen.ts
+28
-4
28 additions, 4 deletions
src/Hydrogen.ts
src/main.ts
+4
-3
4 additions, 3 deletions
src/main.ts
with
32 additions
and
7 deletions
src/Hydrogen.ts
+
28
−
4
View file @
5fdef677
...
...
@@ -46,12 +46,11 @@ export class Hydrogen {
}
}
async
mountRoom
(
roomId
:
string
)
{
const
session
=
this
.
_client
.
session
;
const
room
=
session
.
rooms
.
get
(
roomId
);
async
showRoom
(
roomId
:
string
)
{
const
room
=
this
.
_session
.
rooms
.
get
(
roomId
)
??
await
this
.
_joinRoom
(
roomId
);
const
vm
=
new
RoomViewModel
({
room
,
ownUserId
:
session
.
userId
,
ownUserId
:
this
.
_
session
.
userId
,
platform
:
this
.
_platform
,
urlCreator
:
this
.
_urlRouter
,
navigation
:
this
.
_navigation
,
...
...
@@ -60,4 +59,29 @@ export class Hydrogen {
const
view
=
new
TimelineView
(
vm
.
timelineViewModel
);
this
.
_container
.
appendChild
(
view
.
mount
());
}
private
async
_joinRoom
(
roomId
:
string
):
Promise
<
any
>
{
await
this
.
_session
.
joinRoom
(
roomId
);
// even though we've joined the room, we need to wait till the next sync for the actual room
await
this
.
_waitForRoomFromSync
(
roomId
);
return
this
.
_session
.
rooms
.
get
(
roomId
);
}
private
_waitForRoomFromSync
(
roomId
:
string
):
Promise
<
void
>
{
let
resolve
:
()
=>
void
;
const
promise
:
Promise
<
void
>
=
new
Promise
(
r
=>
{
resolve
=
r
;
})
const
subscription
=
{
onAdd
:
(
_
:
string
,
value
:
{
id
:
string
})
=>
{
if
(
value
.
id
===
roomId
)
{
this
.
_session
.
rooms
.
unsubscribe
(
subscription
);
resolve
();
}
},
};
this
.
_session
.
rooms
.
subscribe
(
subscription
);
return
promise
;
}
private
get
_session
()
{
return
this
.
_client
.
session
;
}
}
This diff is collapsed.
Click to expand it.
src/main.ts
+
4
−
3
View file @
5fdef677
...
...
@@ -18,7 +18,7 @@ async function fetchConfig(): Promise<IChatterboxConfig> {
async
function
main
()
{
const
root
=
document
.
querySelector
(
"
#chatterbox
"
)
as
HTMLDivElement
;
const
{
homeserver
}
=
await
fetchConfig
();
const
{
homeserver
,
auto_join_room
}
=
await
fetchConfig
();
const
hydrogen
=
new
Hydrogen
(
homeserver
,
root
);
const
username
=
generateRandomString
(
7
);
const
password
=
generateRandomString
(
10
);
...
...
@@ -28,8 +28,9 @@ async function main() {
console
.
log
(
"
Attempting to login with same credentials
"
);
await
hydrogen
.
login
(
username
,
password
);
console
.
log
(
"
Login successful
"
);
console
.
log
(
"
Attempting to mount Timeline
"
);
await
hydrogen
.
showRoom
(
auto_join_room
);
console
.
log
(
"
Mounted Timeline
"
);
}
function
generateRandomString
(
length
:
number
):
string
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment