({ chatRoom, messageReplyTo, removeMessageReplyTo })
| 36 | } from "../../utils/crypto"; |
| 37 | |
| 38 | const MessageInput = ({ chatRoom, messageReplyTo, removeMessageReplyTo }) => { |
| 39 | const [message, setMessage] = useState(""); |
| 40 | const [isEmojiPickerOpen, setIsEmojiPickerOpen] = useState(false); |
| 41 | const [image, setImage] = useState<string | null>(null); |
| 42 | const [progress, setProgress] = useState(0); |
| 43 | const [recording, setRecording] = useState<Audio.Recording | null>(null); |
| 44 | const [soundURI, setSoundURI] = useState<string | null>(null); |
| 45 | |
| 46 | const navigation = useNavigation(); |
| 47 | |
| 48 | useEffect(() => { |
| 49 | (async () => { |
| 50 | if (Platform.OS !== "web") { |
| 51 | const libraryResponse = |
| 52 | await ImagePicker.requestMediaLibraryPermissionsAsync(); |
| 53 | const photoResponse = await ImagePicker.requestCameraPermissionsAsync(); |
| 54 | await Audio.requestPermissionsAsync(); |
| 55 | |
| 56 | if ( |
| 57 | libraryResponse.status !== "granted" || |
| 58 | photoResponse.status !== "granted" |
| 59 | ) { |
| 60 | alert("Sorry, we need camera roll permissions to make this work!"); |
| 61 | } |
| 62 | } |
| 63 | })(); |
| 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, |
nothing calls this directly
no outgoing calls
no test coverage detected