forked from MirrorHub/synapse
SYN-149: Send join event immediately after the room create event
This commit is contained in:
parent
a5b88c489e
commit
ae9c2ab165
3 changed files with 31 additions and 26 deletions
|
@ -21,8 +21,6 @@ from synapse.api.errors import SynapseError
|
||||||
from synapse.api.events.room import RoomAliasesEvent
|
from synapse.api.events.room import RoomAliasesEvent
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import sqlite3
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -120,12 +120,20 @@ class RoomCreationHandler(BaseHandler):
|
||||||
user, room_id, is_public=is_public
|
user, room_id, is_public=is_public
|
||||||
)
|
)
|
||||||
|
|
||||||
|
room_member_handler = self.hs.get_handlers().room_member_handler
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def handle_event(event):
|
def handle_event(event):
|
||||||
snapshot = yield self.store.snapshot_room(event)
|
snapshot = yield self.store.snapshot_room(event)
|
||||||
|
|
||||||
logger.debug("Event: %s", event)
|
logger.debug("Event: %s", event)
|
||||||
|
|
||||||
|
if event.type == RoomMemberEvent.TYPE:
|
||||||
|
yield room_member_handler.change_membership(
|
||||||
|
event,
|
||||||
|
do_auth=False
|
||||||
|
)
|
||||||
|
else:
|
||||||
yield self._on_new_room_event(
|
yield self._on_new_room_event(
|
||||||
event, snapshot, extra_users=[user], suppress_auth=True
|
event, snapshot, extra_users=[user], suppress_auth=True
|
||||||
)
|
)
|
||||||
|
@ -155,16 +163,6 @@ class RoomCreationHandler(BaseHandler):
|
||||||
|
|
||||||
yield handle_event(topic_event)
|
yield handle_event(topic_event)
|
||||||
|
|
||||||
content = {"membership": Membership.JOIN}
|
|
||||||
join_event = self.event_factory.create_event(
|
|
||||||
etype=RoomMemberEvent.TYPE,
|
|
||||||
state_key=user_id,
|
|
||||||
room_id=room_id,
|
|
||||||
user_id=user_id,
|
|
||||||
membership=Membership.JOIN,
|
|
||||||
content=content
|
|
||||||
)
|
|
||||||
|
|
||||||
content = {"membership": Membership.INVITE}
|
content = {"membership": Membership.INVITE}
|
||||||
for invitee in invite_list:
|
for invitee in invite_list:
|
||||||
invite_event = self.event_factory.create_event(
|
invite_event = self.event_factory.create_event(
|
||||||
|
@ -174,16 +172,7 @@ class RoomCreationHandler(BaseHandler):
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
content=content
|
content=content
|
||||||
)
|
)
|
||||||
|
yield handle_event(invite_event)
|
||||||
yield self.hs.get_handlers().room_member_handler.change_membership(
|
|
||||||
invite_event,
|
|
||||||
do_auth=False
|
|
||||||
)
|
|
||||||
|
|
||||||
yield self.hs.get_handlers().room_member_handler.change_membership(
|
|
||||||
join_event,
|
|
||||||
do_auth=False
|
|
||||||
)
|
|
||||||
|
|
||||||
result = {"room_id": room_id}
|
result = {"room_id": room_id}
|
||||||
|
|
||||||
|
@ -194,9 +183,11 @@ class RoomCreationHandler(BaseHandler):
|
||||||
defer.returnValue(result)
|
defer.returnValue(result)
|
||||||
|
|
||||||
def _create_events_for_new_room(self, creator, room_id, is_public=False):
|
def _create_events_for_new_room(self, creator, room_id, is_public=False):
|
||||||
|
creator_id = creator.to_string()
|
||||||
|
|
||||||
event_keys = {
|
event_keys = {
|
||||||
"room_id": room_id,
|
"room_id": room_id,
|
||||||
"user_id": creator.to_string(),
|
"user_id": creator_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
def create(etype, **content):
|
def create(etype, **content):
|
||||||
|
@ -211,6 +202,16 @@ class RoomCreationHandler(BaseHandler):
|
||||||
creator=creator.to_string(),
|
creator=creator.to_string(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
join_event = self.event_factory.create_event(
|
||||||
|
etype=RoomMemberEvent.TYPE,
|
||||||
|
state_key=creator_id,
|
||||||
|
content={
|
||||||
|
"membership": Membership.JOIN,
|
||||||
|
},
|
||||||
|
**event_keys
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
power_levels_event = self.event_factory.create_event(
|
power_levels_event = self.event_factory.create_event(
|
||||||
etype=RoomPowerLevelsEvent.TYPE,
|
etype=RoomPowerLevelsEvent.TYPE,
|
||||||
content={
|
content={
|
||||||
|
@ -239,6 +240,7 @@ class RoomCreationHandler(BaseHandler):
|
||||||
|
|
||||||
return [
|
return [
|
||||||
creation_event,
|
creation_event,
|
||||||
|
join_event,
|
||||||
power_levels_event,
|
power_levels_event,
|
||||||
join_rules_event,
|
join_rules_event,
|
||||||
]
|
]
|
||||||
|
|
|
@ -14,10 +14,15 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from ._base import SQLBaseStore
|
from ._base import SQLBaseStore
|
||||||
|
|
||||||
|
from synapse.api.errors import SynapseError
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
|
||||||
RoomAliasMapping = namedtuple(
|
RoomAliasMapping = namedtuple(
|
||||||
"RoomAliasMapping",
|
"RoomAliasMapping",
|
||||||
|
|
Loading…
Reference in a new issue