[server] Simplify relationship creation in thread-permission-updaters.js
Summary:
When a user joins a thread, we need to make sure that they have KNOW_OF relationships with all of the members. The existing code for handling this is very hacky. The complexity occurs because we try to avoid recreating relationships that they already exist.
Currently, relationship rows can be passed to commitMembershipChangeset from several places:
- The three Changeset-creating functions in thread-permission-updaters.js a. changeRole, recalculateThreadPermissions, and updateDescendantPermissions all add relationship rows between new members and existing members b. changeRole additionally adds relationship rows among the new members. The other two skip this because the new members can only come from the parent thread, and if they already shared a thread they should've already had a relationship row
- getParentThreadRelationshipRowsForNewUsers a. This function is called in createThread and updateThread when those functions have to merge membership creations from recalculateThreadPermissions (members of new parent) and changeRole (member additions)
- getRelationshipRowsForUsers a. This function is called in createThread when the viewer creates a thread with users they don't currently have a relationship with
The goal here is to get rid of 1b, 2, and 3 and instead have commitMembershipChangeset determine from the combined set of membership creations what relationships need to be created. In order to do that, we need to propagate information about what rows already exist.
In this diff I introduce RelationshipChangeset to handle containing this information (what rows already exist) as well as the information we currently propagate in relationshipRows (what rows need to exist). This information is determined within the changeset-creating function, so it needs to be packaged up and merged before being processed by commitMembershipChangeset.
Test Plan:
I tested all the way that commitMembershipChangeset can get triggered:
- joinThread
- removeMembers
- updateThread
- createThread
- updateRole
- leaveThread
Reviewers: palys-swm
Reviewed By: palys-swm
Subscribers: KatPo, Adrian, atul
Differential Revision: https://phabricator.ashoat.com/D1021