Use the "collect_presencelike_data" distributor signal instead of re-implementing its behaviour
parent
50718825bd
commit
583add34fe
|
@ -581,8 +581,8 @@ class RoomMemberHandler(BaseHandler):
|
||||||
room_id = event.room_id
|
room_id = event.room_id
|
||||||
|
|
||||||
# If event doesn't include a display name, add one.
|
# If event doesn't include a display name, add one.
|
||||||
yield self._fill_out_join_content(
|
yield self.distributor.fire(
|
||||||
joinee, event.content
|
"collect_presencelike_data", joinee, event.content
|
||||||
)
|
)
|
||||||
|
|
||||||
# XXX: We don't do an auth check if we are doing an invite
|
# XXX: We don't do an auth check if we are doing an invite
|
||||||
|
@ -637,34 +637,6 @@ class RoomMemberHandler(BaseHandler):
|
||||||
"user_joined_room", user=user, room_id=room_id
|
"user_joined_room", user=user, room_id=room_id
|
||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
|
||||||
def _fill_out_join_content(self, user_id, content):
|
|
||||||
# If event doesn't include a display name, add one.
|
|
||||||
# TODO(paul): This really ought to use the distributor's
|
|
||||||
# collect_presencelike_data signal instead.
|
|
||||||
profile_handler = self.hs.get_handlers().profile_handler
|
|
||||||
if "displayname" not in content:
|
|
||||||
try:
|
|
||||||
display_name = yield profile_handler.get_displayname(
|
|
||||||
user_id
|
|
||||||
)
|
|
||||||
|
|
||||||
if display_name:
|
|
||||||
content["displayname"] = display_name
|
|
||||||
except:
|
|
||||||
logger.exception("Failed to set display_name")
|
|
||||||
|
|
||||||
if "avatar_url" not in content:
|
|
||||||
try:
|
|
||||||
avatar_url = yield profile_handler.get_avatar_url(
|
|
||||||
user_id
|
|
||||||
)
|
|
||||||
|
|
||||||
if avatar_url:
|
|
||||||
content["avatar_url"] = avatar_url
|
|
||||||
except:
|
|
||||||
logger.exception("Failed to set avatar_url")
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _should_invite_join(self, room_id, prev_state, do_auth):
|
def _should_invite_join(self, room_id, prev_state, do_auth):
|
||||||
logger.debug("_should_invite_join: room_id: %s", room_id)
|
logger.debug("_should_invite_join: room_id: %s", room_id)
|
||||||
|
|
|
@ -69,6 +69,8 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
|
||||||
self.distributor = hs.get_distributor()
|
self.distributor = hs.get_distributor()
|
||||||
self.hs = hs
|
self.hs = hs
|
||||||
|
|
||||||
|
self.distributor.declare("collect_presencelike_data")
|
||||||
|
|
||||||
self.handlers.room_member_handler = RoomMemberHandler(self.hs)
|
self.handlers.room_member_handler = RoomMemberHandler(self.hs)
|
||||||
self.handlers.profile_handler = ProfileHandler(self.hs)
|
self.handlers.profile_handler = ProfileHandler(self.hs)
|
||||||
self.room_member_handler = self.handlers.room_member_handler
|
self.room_member_handler = self.handlers.room_member_handler
|
||||||
|
|
Loading…
Reference in New Issue