Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
SYN-149: Send join event immediately after the room create event
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Haines committed Nov 18, 2014
1 parent a5b88c4 commit ae9c2ab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
2 changes: 0 additions & 2 deletions synapse/handlers/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
from synapse.api.events.room import RoomAliasesEvent

import logging
import sqlite3


logger = logging.getLogger(__name__)

Expand Down
50 changes: 26 additions & 24 deletions synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,23 @@ def create_room(self, user_id, room_id, config):
user, room_id, is_public=is_public
)

room_member_handler = self.hs.get_handlers().room_member_handler

@defer.inlineCallbacks
def handle_event(event):
snapshot = yield self.store.snapshot_room(event)

logger.debug("Event: %s", event)

yield self._on_new_room_event(
event, snapshot, extra_users=[user], suppress_auth=True
)
if event.type == RoomMemberEvent.TYPE:
yield room_member_handler.change_membership(
event,
do_auth=False
)
else:
yield self._on_new_room_event(
event, snapshot, extra_users=[user], suppress_auth=True
)

for event in creation_events:
yield handle_event(event)
Expand All @@ -155,16 +163,6 @@ def handle_event(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}
for invitee in invite_list:
invite_event = self.event_factory.create_event(
Expand All @@ -174,16 +172,7 @@ def handle_event(event):
user_id=user_id,
content=content
)

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
)
yield handle_event(invite_event)

result = {"room_id": room_id}

Expand All @@ -194,9 +183,11 @@ def handle_event(event):
defer.returnValue(result)

def _create_events_for_new_room(self, creator, room_id, is_public=False):
creator_id = creator.to_string()

event_keys = {
"room_id": room_id,
"user_id": creator.to_string(),
"user_id": creator_id,
}

def create(etype, **content):
Expand All @@ -211,6 +202,16 @@ def create(etype, **content):
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(
etype=RoomPowerLevelsEvent.TYPE,
content={
Expand Down Expand Up @@ -239,6 +240,7 @@ def create(etype, **content):

return [
creation_event,
join_event,
power_levels_event,
join_rules_event,
]
Expand Down
5 changes: 5 additions & 0 deletions synapse/storage/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
# limitations under the License.

from ._base import SQLBaseStore

from synapse.api.errors import SynapseError

from twisted.internet import defer

from collections import namedtuple

import sqlite3


RoomAliasMapping = namedtuple(
"RoomAliasMapping",
Expand Down

0 comments on commit ae9c2ab

Please sign in to comment.