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