@@ -5,7 +5,7 @@ import { MutationOps } from '../shared/types'
55import { collectLinkedNodeStatements , collectNodeStatements , findExistingNode , runUpdateTransport } from '../shared/rdfMutationHelpers'
66import { logAndThrowMutationError } from '../shared/mutationErrors'
77import { createIdNode } from '../shared/idNodeFactory'
8- import { contactInfoUpdatesFailedMessageText , updaterUnsupportedStoreErrorMessageText } from '../../texts'
8+ import { saveContactUpdatesFailedMessageText , updaterUnsupportedStoreErrorMessageText } from '../../texts'
99import { buildAddressStatements , buildEmailStatements , buildPhoneStatements } from './rdfBuilders'
1010
1111async function mutatePhoneEntries ( store : LiveStore , subject : NamedNode , phoneOps : MutationOps < ContactPointRow > ) {
@@ -15,8 +15,8 @@ async function mutatePhoneEntries(store: LiveStore, subject: NamedNode, phoneOps
1515 const insertions : any [ ] = [ ]
1616
1717 phoneOps . remove . forEach ( ( phone ) => {
18- if ( ! phone . entryNode ) return
19- const existingNode = findExistingNode ( existingPhoneNodes , phone . entryNode )
18+ if ( ! phone . sourceNode ) return
19+ const existingNode = findExistingNode ( existingPhoneNodes , phone . sourceNode )
2020 if ( existingNode ) {
2121 const linkedPhoneStatements = collectLinkedNodeStatements ( store , subject , ns . vcard ( 'hasTelephone' ) , doc )
2222 const matchingLinkStatement = linkedPhoneStatements . linkStatements . find ( ( statement ) => statement . object ?. value === existingNode . value )
@@ -28,8 +28,8 @@ async function mutatePhoneEntries(store: LiveStore, subject: NamedNode, phoneOps
2828 } )
2929
3030 phoneOps . update . forEach ( ( phone ) => {
31- if ( ! phone . entryNode ) return
32- const existingNode = findExistingNode ( existingPhoneNodes , phone . entryNode )
31+ if ( ! phone . sourceNode ) return
32+ const existingNode = findExistingNode ( existingPhoneNodes , phone . sourceNode )
3333 if ( ! existingNode ) {
3434 insertions . push ( ...buildPhoneStatements ( subject , doc , createIdNode ( doc ) , phone ) )
3535 return
@@ -40,7 +40,9 @@ async function mutatePhoneEntries(store: LiveStore, subject: NamedNode, phoneOps
4040 deletions . push ( matchingLinkStatement )
4141 }
4242 deletions . push ( ...collectNodeStatements ( store , existingNode , doc ) )
43- insertions . push ( ...buildPhoneStatements ( subject , doc , existingNode , phone ) )
43+ const isDirectPhoneValue = existingNode . termType === 'NamedNode' && / ^ t e l : / i. test ( existingNode . value )
44+ const targetNode = isDirectPhoneValue ? createIdNode ( doc ) : existingNode
45+ insertions . push ( ...buildPhoneStatements ( subject , doc , targetNode , phone ) )
4446 } )
4547
4648 phoneOps . create . forEach ( ( phone ) => {
@@ -49,7 +51,7 @@ async function mutatePhoneEntries(store: LiveStore, subject: NamedNode, phoneOps
4951
5052 await runUpdateTransport ( store , doc , deletions , insertions , {
5153 unsupportedMessage : updaterUnsupportedStoreErrorMessageText ,
52- failureMessage : contactInfoUpdatesFailedMessageText ,
54+ failureMessage : saveContactUpdatesFailedMessageText ,
5355 } )
5456}
5557
@@ -60,8 +62,8 @@ async function mutateEmailEntries(store: LiveStore, subject: NamedNode, emailOps
6062 const insertions : any [ ] = [ ]
6163
6264 emailOps . remove . forEach ( ( email ) => {
63- if ( ! email . entryNode ) return
64- const existingNode = findExistingNode ( existingEmailNodes , email . entryNode )
65+ if ( ! email . sourceNode ) return
66+ const existingNode = findExistingNode ( existingEmailNodes , email . sourceNode )
6567 if ( existingNode ) {
6668 const linkedEmailStatements = collectLinkedNodeStatements ( store , subject , ns . vcard ( 'hasEmail' ) , doc )
6769 const matchingLinkStatement = linkedEmailStatements . linkStatements . find ( ( statement ) => statement . object ?. value === existingNode . value )
@@ -73,8 +75,8 @@ async function mutateEmailEntries(store: LiveStore, subject: NamedNode, emailOps
7375 } )
7476
7577 emailOps . update . forEach ( ( email ) => {
76- if ( ! email . entryNode ) return
77- const existingNode = findExistingNode ( existingEmailNodes , email . entryNode )
78+ if ( ! email . sourceNode ) return
79+ const existingNode = findExistingNode ( existingEmailNodes , email . sourceNode )
7880 if ( ! existingNode ) {
7981 insertions . push ( ...buildEmailStatements ( subject , doc , createIdNode ( doc ) , email ) )
8082 return
@@ -89,7 +91,7 @@ async function mutateEmailEntries(store: LiveStore, subject: NamedNode, emailOps
8991
9092 await runUpdateTransport ( store , doc , deletions , insertions , {
9193 unsupportedMessage : updaterUnsupportedStoreErrorMessageText ,
92- failureMessage : contactInfoUpdatesFailedMessageText ,
94+ failureMessage : saveContactUpdatesFailedMessageText ,
9395 } )
9496}
9597
@@ -100,8 +102,8 @@ async function mutateAddressEntries(store: LiveStore, subject: NamedNode, addres
100102 const insertions : any [ ] = [ ]
101103
102104 addressOps . remove . forEach ( ( address ) => {
103- if ( ! address . entryNode ) return
104- const existingNode = findExistingNode ( existingAddressNodes , address . entryNode )
105+ if ( ! address . sourceNode ) return
106+ const existingNode = findExistingNode ( existingAddressNodes , address . sourceNode )
105107 if ( existingNode ) {
106108 const linkedAddressStatements = collectLinkedNodeStatements ( store , subject , ns . vcard ( 'hasAddress' ) , doc )
107109 const matchingLinkStatement = linkedAddressStatements . linkStatements . find ( ( statement ) => statement . object ?. value === existingNode . value )
@@ -113,8 +115,8 @@ async function mutateAddressEntries(store: LiveStore, subject: NamedNode, addres
113115 } )
114116
115117 addressOps . update . forEach ( ( address ) => {
116- if ( ! address . entryNode ) return
117- const existingNode = findExistingNode ( existingAddressNodes , address . entryNode )
118+ if ( ! address . sourceNode ) return
119+ const existingNode = findExistingNode ( existingAddressNodes , address . sourceNode )
118120 if ( ! existingNode ) {
119121 insertions . push ( ...buildAddressStatements ( subject , doc , createIdNode ( doc ) , address ) )
120122 return
@@ -129,7 +131,7 @@ async function mutateAddressEntries(store: LiveStore, subject: NamedNode, addres
129131
130132 await runUpdateTransport ( store , doc , deletions , insertions , {
131133 unsupportedMessage : updaterUnsupportedStoreErrorMessageText ,
132- failureMessage : contactInfoUpdatesFailedMessageText ,
134+ failureMessage : saveContactUpdatesFailedMessageText ,
133135 } )
134136}
135137
@@ -139,6 +141,6 @@ export async function processContactInfoMutations(store: LiveStore, subject: Nam
139141 await mutateEmailEntries ( store , subject , mutationPlan . emailOps )
140142 await mutateAddressEntries ( store , subject , mutationPlan . addressOps )
141143 } catch ( error ) {
142- logAndThrowMutationError ( error )
144+ logAndThrowMutationError ( error , saveContactUpdatesFailedMessageText )
143145 }
144146}
0 commit comments