Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
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
TeDomum
Matrix
Commits
871c4abf
Commit
871c4abf
authored
6 years ago
by
Richard van der Hoff
Browse files
Options
Downloads
Patches
Plain Diff
Factor _generate_room_id out of create_room
we're going to need this for room upgrades.
parent
cb53ce9d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/handlers/room.py
+23
-22
23 additions, 22 deletions
synapse/handlers/room.py
with
23 additions
and
22 deletions
synapse/handlers/room.py
+
23
−
22
View file @
871c4abf
...
...
@@ -165,28 +165,7 @@ class RoomCreationHandler(BaseHandler):
visibility
=
config
.
get
(
"
visibility
"
,
None
)
is_public
=
visibility
==
"
public
"
# autogen room IDs and try to create it. We may clash, so just
# try a few times till one goes through, giving up eventually.
attempts
=
0
room_id
=
None
while
attempts
<
5
:
try
:
random_string
=
stringutils
.
random_string
(
18
)
gen_room_id
=
RoomID
(
random_string
,
self
.
hs
.
hostname
,
)
yield
self
.
store
.
store_room
(
room_id
=
gen_room_id
.
to_string
(),
room_creator_user_id
=
user_id
,
is_public
=
is_public
)
room_id
=
gen_room_id
.
to_string
()
break
except
StoreError
:
attempts
+=
1
if
not
room_id
:
raise
StoreError
(
500
,
"
Couldn
'
t generate a room ID.
"
)
room_id
=
yield
self
.
_generate_room_id
(
creator_id
=
user_id
,
is_public
=
is_public
)
if
room_alias
:
directory_handler
=
self
.
hs
.
get_handlers
().
directory_handler
...
...
@@ -427,6 +406,28 @@ class RoomCreationHandler(BaseHandler):
content
=
content
,
)
@defer.inlineCallbacks
def
_generate_room_id
(
self
,
creator_id
,
is_public
):
# autogen room IDs and try to create it. We may clash, so just
# try a few times till one goes through, giving up eventually.
attempts
=
0
while
attempts
<
5
:
try
:
random_string
=
stringutils
.
random_string
(
18
)
gen_room_id
=
RoomID
(
random_string
,
self
.
hs
.
hostname
,
).
to_string
()
yield
self
.
store
.
store_room
(
room_id
=
gen_room_id
,
room_creator_user_id
=
creator_id
,
is_public
=
is_public
,
)
defer
.
returnValue
(
gen_room_id
)
except
StoreError
:
attempts
+=
1
raise
StoreError
(
500
,
"
Couldn
'
t generate a room ID.
"
)
class
RoomContextHandler
(
object
):
def
__init__
(
self
,
hs
):
...
...
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