Reputation: 69
I am working on a system to allow users to hide a message from their conversation. Currently the system is designed so that a message is stored as a relationship between users directed as (sender)-[]->(recipient).
The issue I have is that I want either user to be able to hide the message on their side only. I am trying to develop the code so that the same function is called regardless of whether the user hiding it was the sender or recipient but am having trouble using conditional logic in the set statement.
My current attempt is show below.
Any advice would be appreciated
Thanks
MATCH (userLoggedIn :User {EmailAddress:'email'})
MATCH (userLoggedIn)-[r:USER_SENTMESSAGE]-(otherUser)
WHERE r.Id = '123456'
SET
case when (userLoggedIn)-[r]->(otherUser)
then r.HideFromSender = true
else r.HideFromReceiver = true
end
Upvotes: 2
Views: 64
Reputation: 29172
You need combine startNode
(for get direction) and conditional statement
(for set property):
MATCH (userLoggedIn:User {EmailAddress:'email'})
-[r:USER_SENTMESSAGE {Id: '123456'}]-
(otherUser)
WITH userLoggedIn, r, otherUser
FOREACH (ift in CASE WHEN userLoggedIn = startNode(r) THEN [1] ELSE [] END |
SET r.HideFromSender = true
)
FOREACH (ift in CASE WHEN otherUser = startNode(r) THEN [1] ELSE [] END |
SET r.HideFromReceiver = true
)
Upd.: In fact, logically you can make it easier:
MATCH (userLoggedIn:User {EmailAddress:'email'})
-[r:USER_SENTMESSAGE {Id: '123456'}]-
(otherUser)
WITH userLoggedIn, r,
CASE WHEN userLoggedIn = startNode(r) THEN true ELSE false END as ift
SET r.HideFromSender = ift,
r.HideFromReceiver = NOT ift
Upvotes: 3