Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicate 1-1 conversations - WPB-10260 #2006

Open
wants to merge 1 commit into
base: chore/cleanup-phone-number-WPB-11437
Choose a base branch
from

Conversation

netbe
Copy link
Collaborator

@netbe netbe commented Oct 7, 2024

Issue

Note: this PR is based on #2017, so preferably start with #2017 first.

Due to some race condition, an user could end up with duplicate proteus team 1-1 conversation. This PR aims to fix this, by showing only one same on all platforms 1-1 conversation.

  • Fix one to one migration that was introduced in adding the last rule to choose the 1-1 conversation (sorted qualified id)
  • Add coredata migration post action to latest db migration to reset the 1-1 conversation if it was wrongly set before AND merge all messages into the conversation to prepare for MLS migration.
  • Remove PatchApplicator (unused)

Testing

  • Use production account where duplicate 1-1 conversation exist
  • run the migration
  • See messages have been merged into one conversation

Checklist

  • Title contains a reference JIRA issue number like [WPB-XXX].
  • Description is filled and free of optional paragraphs.
  • Adds/updates automated tests.

@echoes-hq echoes-hq bot added the echoes: bugs Technical or functional defects in the product label Oct 7, 2024
@netbe netbe force-pushed the fix/duplicate-1-1-conversations-WPB-10260 branch from 0bee456 to fd72b45 Compare October 10, 2024 15:16
@netbe netbe changed the base branch from develop to chore/cleanup-phone-number-WPB-11437 October 10, 2024 15:21
@netbe netbe marked this pull request as ready for review October 10, 2024 15:24
Copy link
Contributor

Test Results

3 689 tests   3 689 ✅  9m 4s ⏱️
  402 suites      0 💤
    4 files        0 ❌

Results for commit fd72b45.

@@ -97,6 +97,10 @@ final class OneOnOneConversationMigrationAction: CoreDataMigrationAction {
sameParticipant
])

// 4. sort by their fully qualified conversation ID in ascending oder, and use the first one.
// primary_key is basically the qualified id
request.sortDescriptors = [NSSortDescriptor(key: "primaryKey", ascending: true)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the reason why, given two team one on ones, client A might show one and client B might show the other?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what do you mean? can you give an example?

Comment on lines +58 to +62
if fakeOnOnOnePerUser[otherUser] == nil {
fakeOnOnOnePerUser[otherUser] = [conversation]
} else {
fakeOnOnOnePerUser[otherUser]?.append(conversation)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can achieve this with:

fakeOneOnOnePerUser[otherUser, default: [])?.append(conversation)

return
}

let fakeOneOnOnePerUser = conversationsPerUser(from: fake1On1Conversations)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Elsewhere in our code we often name dictionaries as "valueByKey", so in this case conversationsByUser.

}
}

private func fakeOneOnOneConversations(context: NSManagedObjectContext) throws -> [ZMConversation] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to define once and reuse it?

@@ -305,6 +305,29 @@ public extension ZMConversation {

return try context.fetch(request)
}

static func fetchAllFakeOneOnOneGroupConversations(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe rename the file since fake one on ones only concern proteus.

Copy link
Contributor

@samwyndham samwyndham left a comment

Choose a reason for hiding this comment

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

Looks good!


private func moveMessages(from otherConversation: ZMConversation,
to theOneOnOneConversation: ZMConversation) {
otherConversation.allMessages.forEach { message in
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: I don't think the specifics of the content in the method are tested... eg. visible vs hidden, draft properties. Consider testing this if it is not too much trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
echoes: bugs Technical or functional defects in the product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants