mirror of
https://github.com/styppo/hamstr.git
synced 2024-10-18 05:23:28 +00:00
Add option to restore default relays
This commit is contained in:
parent
1bea3ab24b
commit
c1a4ff6f58
@ -5,6 +5,7 @@
|
||||
<script>
|
||||
import {defineComponent} from 'vue'
|
||||
import {useNostrStore} from 'src/nostr/NostrStore'
|
||||
import {useSettingsStore} from 'stores/Settings'
|
||||
import MainLayout from 'layouts/MainLayout.vue'
|
||||
|
||||
export default defineComponent({
|
||||
@ -13,6 +14,7 @@ export default defineComponent({
|
||||
MainLayout
|
||||
},
|
||||
setup() {
|
||||
useSettingsStore().init()
|
||||
useNostrStore().init()
|
||||
}
|
||||
})
|
||||
|
@ -10,6 +10,15 @@
|
||||
<q-input v-model="newRelayUrl" label="Add a relay" dense />
|
||||
<q-btn type="submit" icon="add_circle_outline" size="sm" flat round class="btn-icon" />
|
||||
</q-form>
|
||||
<div class="buttons">
|
||||
<button
|
||||
class="btn btn-sm"
|
||||
:disabled="!changed"
|
||||
@click="settings.restoreDefaultRelays()"
|
||||
>
|
||||
Restore defaults
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -31,6 +40,11 @@ export default {
|
||||
newRelayUrl: '',
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
changed() {
|
||||
return !this.settings.hasDefaultRelays()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
addRelay() {
|
||||
let url
|
||||
@ -114,6 +128,17 @@ export default {
|
||||
.btn-icon {
|
||||
color: $color-primary;
|
||||
}
|
||||
.buttons {
|
||||
display: flex;
|
||||
padding: 1rem 0;
|
||||
button {
|
||||
letter-spacing: 1px;
|
||||
font-weight: 600;
|
||||
}
|
||||
button + button {
|
||||
margin-left: .5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<style lang="scss">
|
||||
|
@ -6,13 +6,13 @@ import FetchQueue from 'src/nostr/FetchQueue'
|
||||
import {NoteOrder, useNoteStore} from 'src/nostr/store/NoteStore'
|
||||
import {useProfileStore} from 'src/nostr/store/ProfileStore'
|
||||
import {useContactStore} from 'src/nostr/store/ContactStore'
|
||||
import {useSettingsStore, RELAYS} from 'stores/Settings'
|
||||
import {useSettingsStore} from 'stores/Settings'
|
||||
import {useStatStore} from 'src/nostr/store/StatStore'
|
||||
import {useAppStore} from 'stores/App'
|
||||
import {useMessageStore} from 'src/nostr/store/MessageStore'
|
||||
import {Observable} from 'src/nostr/utils'
|
||||
import {CloseAfter} from 'src/nostr/Relay'
|
||||
import DateUtils from 'src/utils/DateUtils'
|
||||
import {useAppStore} from 'stores/App'
|
||||
import {useMessageStore} from 'src/nostr/store/MessageStore'
|
||||
|
||||
class Stream extends Observable {
|
||||
constructor(sub) {
|
||||
@ -68,8 +68,7 @@ export const useNostrStore = defineStore('nostr', {
|
||||
actions: {
|
||||
init() {
|
||||
const settings = useSettingsStore()
|
||||
// FIXME Use relays from settings
|
||||
this.client = markRaw(new NostrClient(RELAYS))
|
||||
this.client = markRaw(new NostrClient(settings.relays))
|
||||
this.client.connect()
|
||||
|
||||
this.profileQueue = profileQueue(this.client)
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {defineStore} from 'pinia'
|
||||
import {Account} from 'src/nostr/Account'
|
||||
|
||||
export const RELAYS = [
|
||||
const RELAYS = [
|
||||
'wss://nostr-pub.wellorder.net',
|
||||
// 'wss://nostr-relay.wlvs.space',
|
||||
// 'wss://nostr.bitcoiner.social',
|
||||
@ -10,15 +10,14 @@ export const RELAYS = [
|
||||
// 'wss://nostr-pub.semisol.dev',
|
||||
'wss://relay.snort.social',
|
||||
]
|
||||
const RELAYS_VERSION = 1
|
||||
|
||||
export const useSettingsStore = defineStore('settings', {
|
||||
state: () => ({
|
||||
accounts: {},
|
||||
pubkey: null,
|
||||
relays: RELAYS,
|
||||
// TODO move somewhere else?
|
||||
notificationsLastRead: 0,
|
||||
messagesLastRead: 0,
|
||||
relays: [].concat(RELAYS),
|
||||
relaysVersion: 0,
|
||||
}),
|
||||
getters: {
|
||||
activeAccount(state) {
|
||||
@ -29,8 +28,17 @@ export const useSettingsStore = defineStore('settings', {
|
||||
hasAccount(state) {
|
||||
return pubkey => !!state.accounts[pubkey]
|
||||
},
|
||||
hasRelay(state) {
|
||||
return url => state.relays.indexOf(url) >= 0
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
init() {
|
||||
if (this.relaysVersion < RELAYS_VERSION) {
|
||||
this.relays = [].concat(RELAYS)
|
||||
this.relaysVersion = RELAYS_VERSION
|
||||
}
|
||||
},
|
||||
addAccount(opts) {
|
||||
const account = new Account(opts)
|
||||
this.accounts[account.pubkey] = account
|
||||
@ -63,8 +71,12 @@ export const useSettingsStore = defineStore('settings', {
|
||||
if (idx < 0) return
|
||||
this.relays.splice(idx, 1)
|
||||
},
|
||||
hasRelay(url) {
|
||||
return this.relays.indexOf(url) >= 0
|
||||
restoreDefaultRelays() {
|
||||
this.relays = [].concat(RELAYS)
|
||||
},
|
||||
hasDefaultRelays() {
|
||||
return this.relays.length === RELAYS.length
|
||||
&& this.relays.every((url, idx) => url === RELAYS[idx])
|
||||
},
|
||||
},
|
||||
persist: true,
|
||||
|
Loading…
Reference in New Issue
Block a user