Hi all, Thomas here, playing around with daml an its introduction tutorial.
It’s working great so far…
Congratulation @thomaslanglois
Look forward to seeing you progress, good luck!
Great job Thomas! Keep us posted with your learning journey!
Congrats @thomaslanglois Keep on learning Daml and let us know how it goes
Cheers all, thanks for the encouragements.
Second screenshot…so far so good although I find it strange that for A to send a message to B it only takes B to follow A whereas it takes B to be followed back by A before he can sends A a message.
I know it seems to be working as per the requirements described in the use case but I would make this requirement reciprocal i.e. A and B can only exchange messages until both follow each other.
Now how would one do this? I guess the Message contract is fine as is but maybe the SendMessage choice should be more strict and validate the reciprocity by adding an assertMsg statement.
@thomaslanglois
Indeed. You can restrict the ability to send a message only when both the sender and the recipient follow each other by adding an assertion to the SendMessage choice. The slight complication is that you don’t have all the data required to check if the sender follows the recipient ready available. You have the sender party, which is an argument of the SendMessage choice. But you don’t have the User contract associated with this party, which contains the list of parties the sender follows. To obtain the User contract, you need to fetch it from the ledger. Here’s the modified code for the SendMessage choice
nonconsuming choice SendMessage: ContractId Message with
sender: Party
content: Text
controller sender
do
assertMsg "The recipient must follow the sender" (elem sender following)
(senderUserCid, senderUser) <- fetchByKey @User sender
assertMsg "The sender must follow the recipient" (elem this.username senderUser.following)
create Message with sender, receiver = username, content
Thank you, much appreciated, I shall try this shortly
Works like a charm. Thanks Alex.
@Halloran
Congratulations! And welcome to the community of Damlers.
Housekeeping note. When making a new post or asking a new question on the forum - always start a new thread. If you need to refer to an existing thread in your post - include a link to the thread you need to reference.
Have fun learning Daml.
Congratulation @Halloran
Look forward to seeing you progress, good luck!