Skip to content

Commit

Permalink
Merge branch 'develop' into feat/define-default-protocol-WPB-14667
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterinaWire authored Dec 4, 2024
2 parents 98f0a42 + a2bf418 commit f010cb5
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import Foundation

struct UpdateEventEnvelopeV0: Decodable, ToAPIModelConvertible {
// TODO: [WPB-9612] make internal
// This is public for testing purposes.
public struct UpdateEventEnvelopeV0: Decodable, ToAPIModelConvertible {

let id: UUID
let payload: [UpdateEventDecodingProxy]?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extension ZMOperationLoop: ZMPushChannelConsumer {
// fix it. Once we're sure it works, we should remove this.
do {
let decoder = JSONDecoder.defaultDecoder
_ = try decoder.decode(UpdateEventEnvelope.self, from: data)
_ = try decoder.decode(UpdateEventEnvelopeV0.self, from: data)
} catch {
WireLogger.updateEvent.error("failed to decode 'UpdateEventEnvelope': \(error)")
}
Expand Down
2 changes: 2 additions & 0 deletions wire-ios-sync-engine/Source/UserSession/SyncStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public class SyncStatus: NSObject, SyncStatusProtocol, SyncProgress {
ZMUser.selfUser(in: managedObjectContext).needsPropertiesUpdate = true
// Reset the status.
currentSyncPhase = SyncPhase.fetchingLastUpdateEventID
RequestAvailableNotification.notifyNewRequestsAvailable(nil)
log("slow sync")
syncStateDelegate?.didStartSlowSync()
}
Expand All @@ -130,6 +131,7 @@ public class SyncStatus: NSObject, SyncStatusProtocol, SyncProgress {
ZMUser.selfUser(in: managedObjectContext).needsPropertiesUpdate = true
// Set the status.
currentSyncPhase = SyncPhase.fetchingLastUpdateEventID.nextPhase
RequestAvailableNotification.notifyNewRequestsAvailable(nil)
log("resyncResources")
syncStateDelegate?.didStartSlowSync()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class DeveloperDebugActionsViewModelTests: XCTestCase {

// when
// then
XCTAssertEqual(viewModel.buttons.count, 6)
XCTAssertEqual(viewModel.buttons.count, 8)
}

// MARK: - Helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ final class DeveloperDebugActionsViewModel: ObservableObject {

private let selfClient: UserClient?

private let logger = WireLogger(tag: "developer")

// MARK: - Initialize

init(selfClient: UserClient?) {
Expand All @@ -40,10 +42,12 @@ final class DeveloperDebugActionsViewModel: ObservableObject {
buttons = [
.init(title: "Send debug logs", action: sendDebugLogs),
.init(title: "Perform quick sync", action: performQuickSync),
.init(title: "Resync resources", action: resyncResources),
.init(title: "Break next quick sync", action: breakNextQuickSync),
.init(title: "Update Conversation to mixed protocol", action: updateConversationProtocolToMixed),
.init(title: "Update Conversation to MLS protocol", action: updateConversationProtocolToMLS),
.init(title: "Update MLS migration status", action: updateMLSMigrationStatus)
.init(title: "Update MLS migration status", action: updateMLSMigrationStatus),
.init(title: "Delete domains in the database", action: deleteDomains)
]
}

Expand Down Expand Up @@ -88,6 +92,12 @@ final class DeveloperDebugActionsViewModel: ObservableObject {
}
}

// MARK: Resync resources

private func resyncResources() {
DebugActions.triggerResyncResources()
}

// MARK: Proteus to MLS migration

private func updateMLSMigrationStatus() {
Expand Down Expand Up @@ -159,4 +169,37 @@ final class DeveloperDebugActionsViewModel: ObservableObject {
}
}

// MARK: Delete domains

private func deleteDomains() {
guard let syncContext = userSession?.syncContext else {
logger.error("failed to delete domains: no sync context")
return
}

syncContext.perform { [logger] in
do {
logger.debug("deleted domains of users...")
let users = try syncContext.fetch(NSFetchRequest<ZMUser>(entityName: ZMUser.entityName()))

for user in users where !user.isSelfUser {
user.domain = nil
}

logger.debug("deleted domains of conversations...")
let conversations = try syncContext.fetch(NSFetchRequest<ZMConversation>(entityName: ZMConversation.entityName()))

for conversation in conversations where conversation.conversationType.isOne(of: .oneOnOne, .group) {
conversation.domain = nil
}

try syncContext.save()
logger.debug("successfully deleted domains")

} catch {
logger.error("failed to delete domains: \(error.localizedDescription)")
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ extension SettingsCellDescriptorFactory {
Button(
title: "Trigger resyncResources",
isDestructive: false,
selectAction: DebugActions.triggerResyncResources
selectAction: { _ in DebugActions.triggerResyncResources() }
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ enum DebugActions {
sendNext(count: 0)
}

static func triggerResyncResources(_ type: any SettingsCellDescriptorType) {
static func triggerResyncResources() {
ZMUserSession.shared()?.syncManagedObjectContext.performGroupedBlock {
ZMUserSession.shared()?.requestResyncResources()
}
Expand Down Expand Up @@ -242,8 +242,10 @@ enum DebugActions {
switch command {
case .repairInvalidAccessRoles:
DebugActions.updateInvalidAccessRoles()
}

case .resyncResources:
DebugActions.triggerResyncResources()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,26 @@ import Foundation

enum DebugCommand {

/// Update accessRoles for existing conversations where the team is nil and accessRoles == [.teamMember]
/// Update accessRoles for existing conversations where the
/// team is nil and accessRoles == [.teamMember]

case repairInvalidAccessRoles

/// Fetch team, users, connections, conversations, etc, from
/// the backend to update local database.

case resyncResources

init?(string: String) {
// We may want to have commands that accept arguments, which means
// we'd have to do the parsing of the command here.
switch string {
case "repairInvalidAccessRoles":
self = .repairInvalidAccessRoles

case "resync resources":
self = .resyncResources

default:
return nil
}
Expand Down

0 comments on commit f010cb5

Please sign in to comment.