MCPcopy Create free account
hub / github.com/VadimNotJustDev/SignalClone / sendMessageToUser

Function sendMessageToUser

components/MessageInput/MessageInput.tsx:66–103  ·  view source on GitHub ↗
(user, fromUserId)

Source from the content-addressed store, hash-verified

64 }, []);
65
66 const sendMessageToUser = async (user, fromUserId) => {
67 // send message
68 const ourSecretKey = await getMySecretKey();
69 if (!ourSecretKey) {
70 return;
71 }
72
73 if (!user.publicKey) {
74 Alert.alert(
75 "The user haven't set his keypair yet",
76 "Until the user generates the keypair, you cannot securely send him messages"
77 );
78 return;
79 }
80
81 console.log("private key", ourSecretKey);
82
83 const sharedKey = box.before(
84 stringToUint8Array(user.publicKey),
85 ourSecretKey
86 );
87 console.log("shared key", sharedKey);
88
89 const encryptedMessage = encrypt(sharedKey, { message });
90 console.log("encrypted message", encryptedMessage);
91
92 const newMessage = await DataStore.save(
93 new Message({
94 content: encryptedMessage, // <- this messages should be encrypted
95 userID: fromUserId,
96 forUserId: user.id,
97 chatroomID: chatRoom.id,
98 replyToMessageID: messageReplyTo?.id,
99 })
100 );
101
102 // updateLastMessage(newMessage);
103 };
104
105 const sendMessage = async () => {
106 // get all the users of this chatroom

Callers 1

sendMessageFunction · 0.85

Calls 3

getMySecretKeyFunction · 0.90
stringToUint8ArrayFunction · 0.90
encryptFunction · 0.90

Tested by

no test coverage detected