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

Migrate direct message and tag state on room upgrade #4412

Merged
merged 23 commits into from
Jan 28, 2019

Conversation

anoadragon453
Copy link
Member

@anoadragon453 anoadragon453 commented Jan 17, 2019

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file
  • Pull request includes a sign off

Sytest PR: matrix-org/sytest#547

@anoadragon453
Copy link
Member Author

anoadragon453 commented Jan 17, 2019

According to the spec, is_direct should also be set in the createRoom event as well. That's still TODO.

Done.

@codecov-io
Copy link

codecov-io commented Jan 17, 2019

Codecov Report

Merging #4412 into develop will increase coverage by 0.02%.
The diff coverage is 92.85%.

@@             Coverage Diff             @@
##           develop    #4412      +/-   ##
===========================================
+ Coverage    74.73%   74.75%   +0.02%     
===========================================
  Files          336      336              
  Lines        34122    34138      +16     
  Branches      5547     5552       +5     
===========================================
+ Hits         25500    25521      +21     
+ Misses        7048     7041       -7     
- Partials      1574     1576       +2

@anoadragon453 anoadragon453 changed the title Migrate direct message state on room upgrade [WIP] Migrate direct message and tag state on room upgrade Jan 18, 2019
@anoadragon453 anoadragon453 changed the title [WIP] Migrate direct message and tag state on room upgrade Migrate direct message and tag state on room upgrade Jan 22, 2019
@anoadragon453
Copy link
Member Author

So this seems to be failing due to a timeout on sending a make_leave request over federation.

Ctrl-F for 2019-01-22 13:27:05,040 in https://10830-22844864-gh.circle-artifacts.com/0/logs/server-0/homeserver.log to see the error. Possibly explains why the CI would fail while locally the tests run fine?

This PR does add logic to when someone joins a room. Not sure if that has to do with make_leave however.

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally looks good, but a few suggestions for cleanups here.

synapse/handlers/room_member.py Show resolved Hide resolved
return
create_event = yield self.store.get_event(create_id)

if "predecessor" in create_event["content"]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presumably we can use the method from the search PR for this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we can but it's inside SearchHandler:

def get_old_rooms_from_upgraded_room(self, room_id):
"""Retrieves room IDs of old rooms in the history of an upgraded room.
We do so by checking the m.room.create event of the room for a
`predecessor` key. If it exists, we add the room ID to our return
list and then check that room for a m.room.create event and so on
until we can no longer find any more previous rooms.
The full list of all found rooms in then returned.
Args:
room_id (str): id of the room to search through.
Returns:
Deferred[iterable[unicode]]: predecessor room ids
"""

Shall I move it to the store instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking specifically of get_room_predecessor, which is in the Store I think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so it is. Will add, thanks.

user_account_data = yield self.store.get_account_data_for_user(
user_id,
)
room_tags = yield self.store.get_tags_for_room(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels weird when this is up here and not used until later on

break

# Copy room tags if applicable
if room_tags:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think this condition is redundant? get_tags_for_room always returns a dict, even if it's empty.

old_room_id = create_event["content"]["predecessor"]["room_id"]

# Retrieve room account data for predecessor room
user_account_data = yield self.store.get_account_data_for_user(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given you just want the first item in the tuple you can write:

user_account_data, _ = yield ...

which then saves the slightly cryptic [0] indexes later

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh, nice one. I love destructuring.

)

# Copy direct message state if applicable
if user_account_data and "m.direct" in user_account_data[0]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest you do direct_rooms = user_account_data.get("m.direct", {}) and you can drop these conditions.

HOWEVER it may be worth sanity-checking that nobody has decided to make m.direct a list or something else other than a dict, so if isinstance(direct_rooms, dict).

# Copy room tags if applicable
if room_tags:
# Copy each room tag to the new room
for tag in room_tags.keys():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for tag, tag_content in room_tags.items():

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, I think I got lost in thinking how the tag data was structured to realize how clunky that code was.

Thanks for pointing it out.

@anoadragon453 anoadragon453 requested review from a team and removed request for a team January 25, 2019 14:39
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm otherwise

user_id (str)

Returns:
Deferred|None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ITYM Deferred[None] ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it was just copied from another method. We seem to have several different ways of writing the same thing spread across different methods?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deferred|None means: "either a Deferred (of unspecified value type), or None", which is different to what your method does

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I see, thank you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants