add ability to send messages to contacts

This commit is contained in:
liamcottle 2025-02-12 00:44:53 +13:00
parent 88c2be13d0
commit 845f9d6d19

View file

@ -110,10 +110,14 @@
<div v-for="contact of contacts" class="flex px-2 py-1">
<div class="my-auto mr-auto">
<div class="font-semibold">{{ contact.advName }}</div>
<div class="text-sm text-gray-500"><{{ bytesToHex(contact.publicKey) }}></div>
<div class="text-sm text-gray-500">Type: {{ contactTypeToString(contact.type) }} • Last Advert: {{ contact.lastAdvert }}</div>
</div>
<div class="my-auto mx-2">
<div @click="removeContact(contact)" class="hover:underline">Forget</div>
<div @click="sendMessage(contact)" class="hover:underline cursor-pointer">Send Message</div>
</div>
<div class="my-auto mx-2">
<div @click="removeContact(contact)" class="hover:underline cursor-pointer">Forget</div>
</div>
</div>
</div>
@ -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');
</script>