-
Notifications
You must be signed in to change notification settings - Fork 14
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
refactor: process conversation access update event - WPB-10164 #2028
base: develop
Are you sure you want to change the base?
Changes from all commits
487a01f
f220075
92d9ad1
8f5048f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import CoreData | ||
import WireAPI | ||
|
||
/// Process conversation access update events. | ||
|
@@ -26,15 +27,48 @@ protocol ConversationAccessUpdateEventProcessorProtocol { | |
/// | ||
/// - Parameter event: A conversation access update event. | ||
|
||
func processEvent(_ event: ConversationAccessUpdateEvent) async throws | ||
func processEvent(_ event: ConversationAccessUpdateEvent) async | ||
|
||
} | ||
|
||
struct ConversationAccessUpdateEventProcessor: ConversationAccessUpdateEventProcessorProtocol { | ||
|
||
func processEvent(_: ConversationAccessUpdateEvent) async throws { | ||
// TODO: [WPB-10164] | ||
assertionFailure("not implemented yet") | ||
let context: NSManagedObjectContext | ||
let repository: any ConversationRepositoryProtocol | ||
|
||
func processEvent(_ event: ConversationAccessUpdateEvent) async { | ||
let conversationID = event.conversationID | ||
|
||
let localConversation = await repository.fetchOrCreateConversation( | ||
with: conversationID.uuid, | ||
domain: conversationID.domain | ||
) | ||
|
||
let accessRoles = if let legacyAccessRole = event.legacyAccessRole { | ||
getAccessRoles(from: legacyAccessRole) | ||
} else { | ||
event.accessRoles | ||
} | ||
|
||
await context.perform { | ||
localConversation.accessModeStrings = event.accessModes.map(\.rawValue) | ||
localConversation.accessRoleStringsV2 = accessRoles.map(\.rawValue) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. context.save() ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think saves should happen on a higher level. For instance:
We need to take care that any committed work isn't repeated in case of any interruption to the event processing.
Comment on lines
+53
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be part of the repository? |
||
} | ||
} | ||
|
||
private func getAccessRoles( | ||
from legacyRole: ConversationAccessRoleLegacy | ||
) -> Set<ConversationAccessRole> { | ||
switch legacyRole { | ||
case .team: | ||
[.teamMember] | ||
case .activated: | ||
[.teamMember, .nonTeamMember, .guest] | ||
case .nonActivated: | ||
[.teamMember, .nonTeamMember, .guest, .service] | ||
case .private: | ||
[] | ||
} | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... do we even need to handle the legacy roles anymore? The newer roles are always present.