From 845f9d6d19db50efbba2a79fbd584b7fbbb407fd Mon Sep 17 00:00:00 2001 From: liamcottle Date: Wed, 12 Feb 2025 00:44:53 +1300 Subject: [PATCH] add ability to send messages to contacts --- index.html | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index c440b16..2a6b407 100644 --- a/index.html +++ b/index.html @@ -110,10 +110,14 @@
{{ contact.advName }}
+
<{{ bytesToHex(contact.publicKey) }}>
Type: {{ contactTypeToString(contact.type) }} • Last Advert: {{ contact.lastAdvert }}
-
Forget
+
Send Message
+
+
+
Forget
@@ -265,6 +269,25 @@ async sendCommandSyncNextMessage() { await this.connection.sendCommandSyncNextMessage(); }, + async sendMessage(contact) { + + // ask user for message + const message = prompt("Enter message to send"); + if(!message){ + return; + } + + // compose message + const txtType = Constants.TxtTypes.Plain; + const attempt = 0; + const senderTimestamp = Math.floor(Date.now() / 1000); + const pubKeyPrefix = contact.publicKey; + const text = message; + + // send message + await this.connection.sendCommandSendTxtMsg(txtType, attempt, senderTimestamp, pubKeyPrefix, text); + + }, async removeContact(contact) { // ask user to confirm action @@ -279,6 +302,9 @@ await this.loadContacts(); }, + bytesToHex(uint8Array) { + return Array.from(uint8Array).map(byte => byte.toString(16).padStart(2, '0')).join(''); + }, }, }).mount('#app');