-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IOS-719 MiddlewareEventConverter | Move event handler methods
IOS-719 MiddlewareEventConverter | Move event handler methods
- Loading branch information
Showing
6 changed files
with
130 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
Modules/Services/Sources/Models/Block/BlockContainer/InfoContainer+Events.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Foundation | ||
import ProtobufMessages | ||
|
||
public extension InfoContainerProtocol { | ||
|
||
func add(data: Anytype_Event.Block.Add) { | ||
data.blocks | ||
.compactMap(BlockInformationConverter.convert(block:)) | ||
.forEach { block in | ||
add(block) | ||
} | ||
} | ||
|
||
func setFields(data: Anytype_Event.Block.Set.Fields) { | ||
update(blockId: data.id) { info in | ||
return info.updated(fields: data.fields.fields) | ||
} | ||
} | ||
|
||
func delete(data: Anytype_Event.Block.Delete) { | ||
data.blockIds.forEach { blockId in | ||
remove(id: blockId) | ||
} | ||
} | ||
|
||
func setBackgroundColor(data: Anytype_Event.Block.Set.BackgroundColor) { | ||
update(blockId: data.id, update: { info in | ||
return info.updated( | ||
backgroundColor: MiddlewareColor(rawValue: data.backgroundColor) ?? .default | ||
) | ||
}) | ||
} | ||
|
||
func setAlign(data: Anytype_Event.Block.Set.Align) { | ||
update(blockId: data.id) { info in | ||
info.updated(horizontalAlignment: data.align.asBlockModel) | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
Modules/Services/Sources/Models/Details/Storage/ObjectDetailsStorage+Events.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import Foundation | ||
import AnytypeCore | ||
import ProtobufMessages | ||
import SwiftProtobuf | ||
|
||
public extension ObjectDetailsStorage { | ||
|
||
func set(data: Anytype_Event.Object.Details.Set) -> ObjectDetails? { | ||
guard data.hasDetails else { | ||
anytypeAssertionFailure("No details in Object.Details.Set") | ||
return nil | ||
} | ||
let id = data.id | ||
guard id.isValidId else { | ||
anytypeAssertionFailure("Id is empty in details", info: ["id": id]) | ||
return nil | ||
} | ||
|
||
let currentDetails = get(id: id) ?? ObjectDetails(id: id) | ||
let updatedDetails = currentDetails.updated(by: data.details.fields) | ||
|
||
add(details: updatedDetails) | ||
|
||
return updatedDetails | ||
} | ||
|
||
func unset(data: Anytype_Event.Object.Details.Unset) -> ObjectDetails? { | ||
let id = data.id | ||
guard id.isValidId else { | ||
anytypeAssertionFailure("Id is empty in details", info: ["id": id]) | ||
return nil | ||
} | ||
|
||
guard let currentDetails = get(id: id) else { | ||
return nil | ||
} | ||
|
||
let updatedDetails = currentDetails.removed(keys: data.keys) | ||
add(details: updatedDetails) | ||
|
||
return updatedDetails | ||
} | ||
|
||
func amend(data: Anytype_Event.Object.Details.Amend) -> ObjectDetails? { | ||
let id = data.id | ||
guard id.isValidId else { return nil } | ||
|
||
return amend(details: ObjectDetails(id: data.id, values: data.details.asDetailsDictionary)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
Modules/Services/Sources/Models/ObjectRestrictions/ObjectRestrictionsContainer+Events.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Foundation | ||
import ProtobufMessages | ||
|
||
public extension ObjectRestrictionsContainer { | ||
|
||
func set(data: Anytype_Event.Object.Restrictions.Set) { | ||
restrinctions = MiddlewareObjectRestrictionsConverter.convertObjectRestrictions(middlewareRestrictions: data.restrictions) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Modules/Services/Sources/Models/Relations/Storage/RelationLinksStorageProtocol+Events.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Foundation | ||
import ProtobufMessages | ||
|
||
public extension RelationLinksStorageProtocol { | ||
|
||
func ammend(data: Anytype_Event.Object.Relations.Amend) { | ||
amend(relationLinks: data.relationLinks.map { RelationLink(middlewareRelationLink: $0) }) | ||
} | ||
|
||
func remove(data: Anytype_Event.Object.Relations.Remove) { | ||
remove(relationKeys: data.relationKeys) | ||
} | ||
} |