@@ -3,28 +3,22 @@ import CoreData
3
3
import Domain
4
4
5
5
extension CDMessageDAO : MessageStore {
6
- func addMessages( messages: [ Message ] ) -> AnyPublisher < Void , Error > {
6
+ func addMessages( messages: [ ( Message , Message . Direction ) ] ) -> AnyPublisher < Void , Error > {
7
7
messages
8
8
. publisher
9
- . flatMap { self . addMessage ( msg: $0) }
9
+ . flatMap { self . addMessage ( msg: $0. 0 , direction : $0 . 1 ) }
10
10
. eraseToAnyPublisher ( )
11
11
}
12
12
13
- func addMessage( msg: Message ) -> AnyPublisher < Void , Error > {
14
- guard
15
- let fromDID = msg. from,
16
- let toDID = msg. to
17
- else {
18
- return Fail ( error: PlutoError . messageMissingFromOrToDIDError) . eraseToAnyPublisher ( )
19
- }
13
+ func addMessage( msg: Message , direction: Message . Direction ) -> AnyPublisher < Void , Error > {
20
14
return pairDAO
21
15
. fetchController (
22
16
predicate: NSPredicate (
23
17
format: " (holderDID.did == %@) OR (holderDID.did == %@) OR (did == %@) OR (did == %@) " ,
24
- fromDID . string,
25
- toDID . string,
26
- fromDID . string,
27
- toDID . string
18
+ msg . from ? . string ?? " " ,
19
+ msg . to ? . string ?? " " ,
20
+ msg . from ? . string ?? " " ,
21
+ msg . to ? . string ?? " "
28
22
) ,
29
23
context: writeContext
30
24
)
@@ -35,7 +29,7 @@ extension CDMessageDAO: MessageStore {
35
29
msg. id,
36
30
context: writeContext
37
31
) { cdobj, _ in
38
- try cdobj. fromDomain ( msg: msg, pair: pair)
32
+ try cdobj. fromDomain ( msg: msg, direction : direction , pair: pair)
39
33
}
40
34
}
41
35
. map { _ in }
@@ -52,13 +46,14 @@ extension CDMessageDAO: MessageStore {
52
46
}
53
47
54
48
private extension CDMessage {
55
- func fromDomain( msg: Message , pair: CDDIDPair ? ) throws {
49
+ func fromDomain( msg: Message , direction : Message . Direction , pair: CDDIDPair ? ) throws {
56
50
self . messageId = msg. id
57
51
self . from = msg. from? . string
58
52
self . to = msg. to? . string
59
53
self . type = msg. piuri
60
54
self . dataJson = try JSONEncoder ( ) . encode ( CodableMessage ( message: msg) )
61
55
self . createdTime = msg. createdTime
62
56
self . pair = pair
57
+ self . direction = direction. rawValue
63
58
}
64
59
}
0 commit comments