fix slow chat and locked publishing in general.

This commit is contained in:
fiatjaf 2022-01-12 17:45:10 -03:00
parent 0d01d8400e
commit f42deeaef4
4 changed files with 36 additions and 14 deletions

View File

@ -15,7 +15,7 @@
"core-js": "^3.6.5",
"identicon.js": "^2.3.3",
"markdown-it": "^12.3.0",
"nostr-tools": "^0.17.0",
"nostr-tools": "^0.18.0",
"pouchdb-adapter-idb": "6",
"pouchdb-core": "6",
"pouchdb-mapreduce": "6",

View File

@ -21,14 +21,21 @@
<q-form @submit="submitMessage" @reset="text = ''">
<div class="flex w-full mt-4">
<q-input v-model="text" autofocus class="w-full" filled>
<q-input
v-model="text"
autofocus
class="w-full"
filled
:disable="!!sending"
>
<template #append>
<q-btn
unelevated
class="mx-4"
label="Send"
:label="sending ? 'Sending' : 'Send'"
type="submit"
color="secondary"
:disable="!!sending"
@click="submitMessage"
/>
</template>
@ -55,7 +62,9 @@ export default {
listener: null,
messages: [],
canLoadMore: false,
text: ''
text: '',
sending: null,
messagesSet: new Set()
}
},
@ -102,6 +111,7 @@ export default {
methods: {
async restart() {
this.messagesSet = new Set()
if (this.listener) this.listener.cancel()
this.$store.commit('haveReadMessage', this.$route.params.pubkey)
@ -114,6 +124,18 @@ export default {
}
this.listener = onNewMessage(this.$route.params.pubkey, async event => {
this.$store.commit('haveReadMessage', this.$route.params.pubkey)
if (this.messagesSet.has(event.id)) return
this.messagesSet.add(event.id)
if (
event.pubkey === this.$store.state.keys.pub &&
event.created_at === this.sending
) {
this.sending = null
this.text = ''
}
if (this.messages.length === 0) {
this.messages.push(event)
} else {
@ -132,8 +154,6 @@ export default {
if (isElementFullyScrolled(this.$refs.chatScroll)) {
await this.scrollToBottom()
}
this.$store.commit('haveReadMessage', this.$route.params.pubkey)
})
},
@ -157,12 +177,14 @@ export default {
},
async submitMessage() {
if (this.sending) return
this.sending = Math.round(Date.now() / 1000)
await this.$store.dispatch('sendChatMessage', {
now: this.sending,
pubkey: this.$route.params.pubkey,
text: this.text
})
this.text = ''
},
async loadMore() {

View File

@ -161,7 +161,7 @@ export async function setMetadata(store, metadata) {
store.dispatch('addEvent', {event})
}
export async function sendChatMessage(store, {pubkey, text, replyTo}) {
export async function sendChatMessage(store, {now, pubkey, text, replyTo}) {
if (text.length === 0) return
let [ciphertext, iv] = encrypt(store.state.keys.priv, pubkey, text)
@ -169,7 +169,7 @@ export async function sendChatMessage(store, {pubkey, text, replyTo}) {
// make event
let event = {
pubkey: store.state.keys.pub,
created_at: Math.floor(Date.now() / 1000),
created_at: now,
kind: 4,
tags: [['p', pubkey]],
content: ciphertext + '?iv=' + iv

View File

@ -4769,10 +4769,10 @@ normalize-url@^6.0.1:
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-6.1.0.tgz#40d0885b535deffe3f3147bec877d05fe4c5668a"
integrity sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==
nostr-tools@^0.17.0:
version "0.17.0"
resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-0.17.0.tgz#bcc041d810b710dd8431b3d27576948ccea4dac4"
integrity sha512-1Ld/DxBHC+ljVPlOyGh+LtDQfiFMJO76Nyfberuh8mCwvgut6sAW8iI2pHLJEzmQO5T2JgI3qThU4+9vKzXApg==
nostr-tools@^0.18.0:
version "0.18.0"
resolved "https://registry.yarnpkg.com/nostr-tools/-/nostr-tools-0.18.0.tgz#d5c76ecd2ea6728a772de5daa5ab5d8110f3425c"
integrity sha512-NOAC7JhNrAtFnEsr4vEG3PzSzhAcChzXr0SCcfrlFbXcwIFKHcrBGZ4K6qmhJPGpVvhuXwquixG3KlfMIoqc5g==
dependencies:
"@noble/hashes" "^0.5.7"
"@noble/secp256k1" "^1.3.0"