Skip to content

Commit

Permalink
IOS-3153 Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mgolovko committed Jul 16, 2024
1 parent e40145c commit 3c43e1d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
17 changes: 9 additions & 8 deletions Anytype/Sources/Models/Documents/Document/BaseDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,11 @@ final class BaseDocument: BaseDocumentProtocol {
}
}

private func reorderChilder() {
private func makeChildren() -> [BlockInformation] {
guard let model = infoContainer.get(id: objectId) else {
return
return children
}
let flatten = model.flatChildrenTree(container: infoContainer)
children = flatten
return model.flatChildrenTree(container: infoContainer)
}

private func triggerSync(updates: [DocumentUpdate]) {
Expand All @@ -184,8 +183,6 @@ final class BaseDocument: BaseDocumentProtocol {
return [.general]
case .block(let blockId):
return [.block(blockId: blockId)]
case .children(let blockId):
return [.block(blockId: blockId), .children]
case .details(let id):
return [.details(id: id)]
case .unhandled(let blockId):
Expand All @@ -201,8 +198,12 @@ final class BaseDocument: BaseDocumentProtocol {
let relationUpdates = triggerUpdateRelations(updates: updates, permissionsChanged: permissioUpdates.isNotEmpty)
docUpdates.append(contentsOf: relationUpdates)

if updates.contains(where: { $0 == .general || $0.isChildren }) {
reorderChilder()
if updates.contains(where: { $0 == .general || $0.isBlock }) {
let newChildren = makeChildren()
if newChildren != children {
children = newChildren
docUpdates.append(.children)
}
}

if updates.contains(.close) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class MiddlewareEventConverter {
case let .blockSetChildrenIds(data):
infoContainer
.setChildren(ids: data.childrenIds, parentId: data.id)
return .children(blockId: data.id)
return .block(blockId: data.id)
case let .blockSetText(newData):
return blockSetTextUpdate(newData)
case let .blockSetBackgroundColor(data):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import AnytypeCore
enum DocumentUpdate: Hashable {
case general
case block(blockId: String)
case children(blockId: String)
case details(id: String)
case unhandled(blockId: String)
case relationLinks
Expand All @@ -13,9 +12,9 @@ enum DocumentUpdate: Hashable {
}

extension DocumentUpdate {
var isChildren: Bool {
var isBlock: Bool {
switch self {
case .children(blockId: _):
case .block(blockId: _):
return true
default:
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ import Services
import Combine

extension BaseDocumentProtocol {

var widgetsPublisher: AnyPublisher<[BlockInformation], Never> {
childrenPublisher.map {
$0.filter(\.isWidget)
}
.receiveOnMain()
.eraseToAnyPublisher()
}


func targetObjectIdByLinkFor(widgetBlockId: String) -> String? {
guard let block = infoContainer.get(id: widgetBlockId),
let contentId = block.childrenIds.first,
Expand Down

0 comments on commit 3c43e1d

Please sign in to comment.