Compare commits
1 Commits
master
...
dev/map_ti
| Author | SHA1 | Date | |
|---|---|---|---|
|
f0a19e30b8
|
@@ -5,11 +5,7 @@ import { tracked } from '@glimmer/tracking';
|
|||||||
import { service } from '@ember/service';
|
import { service } from '@ember/service';
|
||||||
import { fn } from '@ember/helper';
|
import { fn } from '@ember/helper';
|
||||||
import Icon from '#components/icon';
|
import Icon from '#components/icon';
|
||||||
import {
|
import { normalizeRelayUrl } from '../../../utils/nostr';
|
||||||
excludeRequiredRelays,
|
|
||||||
mergeRequiredRelays,
|
|
||||||
normalizeRelayUrl,
|
|
||||||
} from '../../../utils/nostr';
|
|
||||||
|
|
||||||
const stripProtocol = (url) => (url ? url.replace(/^wss?:\/\//, '') : '');
|
const stripProtocol = (url) => (url ? url.replace(/^wss?:\/\//, '') : '');
|
||||||
|
|
||||||
@@ -21,74 +17,6 @@ export default class AppMenuSettingsNostr extends Component {
|
|||||||
@tracked newReadRelay = '';
|
@tracked newReadRelay = '';
|
||||||
@tracked newWriteRelay = '';
|
@tracked newWriteRelay = '';
|
||||||
|
|
||||||
get customReadRelays() {
|
|
||||||
return excludeRequiredRelays(
|
|
||||||
this.settings.nostrReadRelays || [],
|
|
||||||
this.nostrData.requiredReadRelays
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
get customWriteRelays() {
|
|
||||||
return excludeRequiredRelays(
|
|
||||||
this.settings.nostrWriteRelays || [],
|
|
||||||
this.nostrData.requiredWriteRelays
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
get readRelayExclusions() {
|
|
||||||
return this.settings.nostrReadRelayExclusions || [];
|
|
||||||
}
|
|
||||||
|
|
||||||
get writeRelayExclusions() {
|
|
||||||
return this.settings.nostrWriteRelayExclusions || [];
|
|
||||||
}
|
|
||||||
|
|
||||||
get requiredReadRelaySet() {
|
|
||||||
return new Set(this.nostrData.requiredReadRelays.filter(Boolean));
|
|
||||||
}
|
|
||||||
|
|
||||||
get requiredWriteRelaySet() {
|
|
||||||
return new Set(this.nostrData.requiredWriteRelays.filter(Boolean));
|
|
||||||
}
|
|
||||||
|
|
||||||
get mailboxReadRelaySet() {
|
|
||||||
return new Set(this.nostrData.mailboxReadRelays);
|
|
||||||
}
|
|
||||||
|
|
||||||
get mailboxWriteRelaySet() {
|
|
||||||
return new Set(this.nostrData.mailboxWriteRelays);
|
|
||||||
}
|
|
||||||
|
|
||||||
get hasReadOverrides() {
|
|
||||||
return (
|
|
||||||
this.customReadRelays.length > 0 || this.readRelayExclusions.length > 0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
get hasWriteOverrides() {
|
|
||||||
return (
|
|
||||||
this.customWriteRelays.length > 0 || this.writeRelayExclusions.length > 0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
get readRelaysForDisplay() {
|
|
||||||
return this.nostrData.activeReadRelays.map((url) => {
|
|
||||||
return {
|
|
||||||
url,
|
|
||||||
isRequired: this.requiredReadRelaySet.has(url),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
get writeRelaysForDisplay() {
|
|
||||||
return this.nostrData.activeWriteRelays.map((url) => {
|
|
||||||
return {
|
|
||||||
url,
|
|
||||||
isRequired: this.requiredWriteRelaySet.has(url),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
updateNewReadRelay(event) {
|
updateNewReadRelay(event) {
|
||||||
this.newReadRelay = event.target.value;
|
this.newReadRelay = event.target.value;
|
||||||
@@ -104,51 +32,19 @@ export default class AppMenuSettingsNostr extends Component {
|
|||||||
const url = normalizeRelayUrl(this.newReadRelay);
|
const url = normalizeRelayUrl(this.newReadRelay);
|
||||||
if (!url) return;
|
if (!url) return;
|
||||||
|
|
||||||
const merged = mergeRequiredRelays(this.nostrData.requiredReadRelays, [
|
const current =
|
||||||
...this.customReadRelays,
|
this.settings.nostrReadRelays || this.nostrData.defaultReadRelays;
|
||||||
url,
|
const set = new Set([...current, url]);
|
||||||
]);
|
this.settings.update('nostrReadRelays', Array.from(set));
|
||||||
const custom = excludeRequiredRelays(
|
|
||||||
merged,
|
|
||||||
this.nostrData.requiredReadRelays
|
|
||||||
);
|
|
||||||
|
|
||||||
const readExclusions = this.readRelayExclusions.filter((relay) => {
|
|
||||||
return normalizeRelayUrl(relay) !== url;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.settings.update('nostrReadRelays', custom.length > 0 ? custom : null);
|
|
||||||
this.settings.update(
|
|
||||||
'nostrReadRelayExclusions',
|
|
||||||
readExclusions.length > 0 ? readExclusions : null
|
|
||||||
);
|
|
||||||
this.newReadRelay = '';
|
this.newReadRelay = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
removeReadRelay(url) {
|
removeReadRelay(url) {
|
||||||
if (this.requiredReadRelaySet.has(url)) {
|
const current =
|
||||||
return;
|
this.settings.nostrReadRelays || this.nostrData.defaultReadRelays;
|
||||||
}
|
const filtered = current.filter((r) => r !== url);
|
||||||
|
this.settings.update('nostrReadRelays', filtered);
|
||||||
const normalizedUrl = normalizeRelayUrl(url);
|
|
||||||
|
|
||||||
const remainingCustom = this.customReadRelays.filter((relay) => {
|
|
||||||
return normalizeRelayUrl(relay) !== normalizedUrl;
|
|
||||||
});
|
|
||||||
|
|
||||||
const nextExclusions = this.mailboxReadRelaySet.has(normalizedUrl)
|
|
||||||
? Array.from(new Set([...this.readRelayExclusions, normalizedUrl]))
|
|
||||||
: this.readRelayExclusions;
|
|
||||||
|
|
||||||
this.settings.update(
|
|
||||||
'nostrReadRelays',
|
|
||||||
remainingCustom.length > 0 ? remainingCustom : null
|
|
||||||
);
|
|
||||||
this.settings.update(
|
|
||||||
'nostrReadRelayExclusions',
|
|
||||||
nextExclusions.length > 0 ? nextExclusions : null
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
@@ -168,7 +64,6 @@ export default class AppMenuSettingsNostr extends Component {
|
|||||||
@action
|
@action
|
||||||
resetReadRelays() {
|
resetReadRelays() {
|
||||||
this.settings.update('nostrReadRelays', null);
|
this.settings.update('nostrReadRelays', null);
|
||||||
this.settings.update('nostrReadRelayExclusions', null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
@@ -176,57 +71,24 @@ export default class AppMenuSettingsNostr extends Component {
|
|||||||
const url = normalizeRelayUrl(this.newWriteRelay);
|
const url = normalizeRelayUrl(this.newWriteRelay);
|
||||||
if (!url) return;
|
if (!url) return;
|
||||||
|
|
||||||
const merged = mergeRequiredRelays(this.nostrData.requiredWriteRelays, [
|
const current =
|
||||||
...this.customWriteRelays,
|
this.settings.nostrWriteRelays || this.nostrData.defaultWriteRelays;
|
||||||
url,
|
const set = new Set([...current, url]);
|
||||||
]);
|
this.settings.update('nostrWriteRelays', Array.from(set));
|
||||||
const custom = excludeRequiredRelays(
|
|
||||||
merged,
|
|
||||||
this.nostrData.requiredWriteRelays
|
|
||||||
);
|
|
||||||
|
|
||||||
const writeExclusions = this.writeRelayExclusions.filter((relay) => {
|
|
||||||
return normalizeRelayUrl(relay) !== url;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.settings.update('nostrWriteRelays', custom.length > 0 ? custom : null);
|
|
||||||
this.settings.update(
|
|
||||||
'nostrWriteRelayExclusions',
|
|
||||||
writeExclusions.length > 0 ? writeExclusions : null
|
|
||||||
);
|
|
||||||
this.newWriteRelay = '';
|
this.newWriteRelay = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
removeWriteRelay(url) {
|
removeWriteRelay(url) {
|
||||||
if (this.requiredWriteRelaySet.has(url)) {
|
const current =
|
||||||
return;
|
this.settings.nostrWriteRelays || this.nostrData.defaultWriteRelays;
|
||||||
}
|
const filtered = current.filter((r) => r !== url);
|
||||||
|
this.settings.update('nostrWriteRelays', filtered);
|
||||||
const normalizedUrl = normalizeRelayUrl(url);
|
|
||||||
|
|
||||||
const remainingCustom = this.customWriteRelays.filter((relay) => {
|
|
||||||
return normalizeRelayUrl(relay) !== normalizedUrl;
|
|
||||||
});
|
|
||||||
|
|
||||||
const nextExclusions = this.mailboxWriteRelaySet.has(normalizedUrl)
|
|
||||||
? Array.from(new Set([...this.writeRelayExclusions, normalizedUrl]))
|
|
||||||
: this.writeRelayExclusions;
|
|
||||||
|
|
||||||
this.settings.update(
|
|
||||||
'nostrWriteRelays',
|
|
||||||
remainingCustom.length > 0 ? remainingCustom : null
|
|
||||||
);
|
|
||||||
this.settings.update(
|
|
||||||
'nostrWriteRelayExclusions',
|
|
||||||
nextExclusions.length > 0 ? nextExclusions : null
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
resetWriteRelays() {
|
resetWriteRelays() {
|
||||||
this.settings.update('nostrWriteRelays', null);
|
this.settings.update('nostrWriteRelays', null);
|
||||||
this.settings.update('nostrWriteRelayExclusions', null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
@@ -250,20 +112,18 @@ export default class AppMenuSettingsNostr extends Component {
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="new-read-relay">Read Relays</label>
|
<label for="new-read-relay">Read Relays</label>
|
||||||
<ul class="relay-list">
|
<ul class="relay-list">
|
||||||
{{#each this.readRelaysForDisplay as |relay|}}
|
{{#each this.nostrData.activeReadRelays as |relay|}}
|
||||||
<li>
|
<li>
|
||||||
<span>{{stripProtocol relay.url}}</span>
|
<span>{{stripProtocol relay}}</span>
|
||||||
{{#unless relay.isRequired}}
|
<button
|
||||||
<button
|
type="button"
|
||||||
type="button"
|
class="btn-remove-relay"
|
||||||
class="btn-remove-relay"
|
title="Remove relay"
|
||||||
title="Remove relay"
|
aria-label="Remove"
|
||||||
aria-label="Remove"
|
{{on "click" (fn this.removeReadRelay relay)}}
|
||||||
{{on "click" (fn this.removeReadRelay relay.url)}}
|
>
|
||||||
>
|
<Icon @name="x" @size={{14}} @color="currentColor" />
|
||||||
<Icon @name="x" @size={{14}} @color="currentColor" />
|
</button>
|
||||||
</button>
|
|
||||||
{{/unless}}
|
|
||||||
</li>
|
</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -283,7 +143,7 @@ export default class AppMenuSettingsNostr extends Component {
|
|||||||
{{on "click" this.addReadRelay}}
|
{{on "click" this.addReadRelay}}
|
||||||
>Add</button>
|
>Add</button>
|
||||||
</div>
|
</div>
|
||||||
{{#if this.hasReadOverrides}}
|
{{#if this.settings.nostrReadRelays}}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="btn-link reset-relays"
|
class="btn-link reset-relays"
|
||||||
@@ -297,20 +157,18 @@ export default class AppMenuSettingsNostr extends Component {
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="new-write-relay">Write Relays</label>
|
<label for="new-write-relay">Write Relays</label>
|
||||||
<ul class="relay-list">
|
<ul class="relay-list">
|
||||||
{{#each this.writeRelaysForDisplay as |relay|}}
|
{{#each this.nostrData.activeWriteRelays as |relay|}}
|
||||||
<li>
|
<li>
|
||||||
<span>{{stripProtocol relay.url}}</span>
|
<span>{{stripProtocol relay}}</span>
|
||||||
{{#unless relay.isRequired}}
|
<button
|
||||||
<button
|
type="button"
|
||||||
type="button"
|
class="btn-remove-relay"
|
||||||
class="btn-remove-relay"
|
title="Remove relay"
|
||||||
title="Remove relay"
|
aria-label="Remove"
|
||||||
aria-label="Remove"
|
{{on "click" (fn this.removeWriteRelay relay)}}
|
||||||
{{on "click" (fn this.removeWriteRelay relay.url)}}
|
>
|
||||||
>
|
<Icon @name="x" @size={{14}} @color="currentColor" />
|
||||||
<Icon @name="x" @size={{14}} @color="currentColor" />
|
</button>
|
||||||
</button>
|
|
||||||
{{/unless}}
|
|
||||||
</li>
|
</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -330,7 +188,7 @@ export default class AppMenuSettingsNostr extends Component {
|
|||||||
{{on "click" this.addWriteRelay}}
|
{{on "click" this.addWriteRelay}}
|
||||||
>Add</button>
|
>Add</button>
|
||||||
</div>
|
</div>
|
||||||
{{#if this.hasWriteOverrides}}
|
{{#if this.settings.nostrWriteRelays}}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="btn-link reset-relays"
|
class="btn-link reset-relays"
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { Style, Circle, Fill, Stroke, Icon } from 'ol/style.js';
|
|||||||
import { apply } from 'ol-mapbox-style';
|
import { apply } from 'ol-mapbox-style';
|
||||||
import { getIcon } from '../utils/icons';
|
import { getIcon } from '../utils/icons';
|
||||||
import { getIconNameForTags } from '../utils/osm-icons';
|
import { getIconNameForTags } from '../utils/osm-icons';
|
||||||
|
import config from 'marco/config/environment';
|
||||||
|
|
||||||
export default class MapComponent extends Component {
|
export default class MapComponent extends Component {
|
||||||
@service osm;
|
@service osm;
|
||||||
@@ -286,9 +287,26 @@ export default class MapComponent extends Component {
|
|||||||
this.mapUi.updateCenter(initialCenter[1], initialCenter[0]);
|
this.mapUi.updateCenter(initialCenter[1], initialCenter[0]);
|
||||||
this.mapUi.updateZoom(view.getZoom());
|
this.mapUi.updateZoom(view.getZoom());
|
||||||
|
|
||||||
apply(this.mapInstance, 'https://tiles.openfreemap.org/styles/liberty', {
|
if (config.environment === 'test') {
|
||||||
webfonts: 'data:text/css,',
|
apply(this.mapInstance, {
|
||||||
});
|
version: 8,
|
||||||
|
name: 'Test Style',
|
||||||
|
sources: {},
|
||||||
|
layers: [
|
||||||
|
{
|
||||||
|
id: 'background',
|
||||||
|
type: 'background',
|
||||||
|
paint: {
|
||||||
|
'background-color': '#f8f4f0',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
apply(this.mapInstance, 'https://tiles.openfreemap.org/styles/liberty', {
|
||||||
|
webfonts: 'data:text/css,',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.searchOverlayElement = document.createElement('div');
|
this.searchOverlayElement = document.createElement('div');
|
||||||
this.searchOverlayElement.className = 'search-pulse';
|
this.searchOverlayElement.className = 'search-pulse';
|
||||||
|
|||||||
@@ -6,12 +6,7 @@ import { MailboxesModel } from 'applesauce-core/models/mailboxes';
|
|||||||
import { npubEncode } from 'applesauce-core/helpers/pointers';
|
import { npubEncode } from 'applesauce-core/helpers/pointers';
|
||||||
import { persistEventsToCache } from 'applesauce-core/helpers/event-cache';
|
import { persistEventsToCache } from 'applesauce-core/helpers/event-cache';
|
||||||
import { NostrIDB, openDB } from 'nostr-idb';
|
import { NostrIDB, openDB } from 'nostr-idb';
|
||||||
import {
|
import { normalizeRelayUrl } from '../utils/nostr';
|
||||||
excludeRequiredRelays,
|
|
||||||
mergeRequiredRelays,
|
|
||||||
normalizeRelayUrl,
|
|
||||||
uniqNormalizedRelays,
|
|
||||||
} from '../utils/nostr';
|
|
||||||
import { getGeohashPrefixesInBbox } from '../utils/geohash-coverage';
|
import { getGeohashPrefixesInBbox } from '../utils/geohash-coverage';
|
||||||
|
|
||||||
const DIRECTORY_RELAYS = [
|
const DIRECTORY_RELAYS = [
|
||||||
@@ -88,62 +83,43 @@ export default class NostrDataService extends Service {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get requiredReadRelays() {
|
get defaultReadRelays() {
|
||||||
return DEFAULT_READ_RELAYS;
|
const mailboxes = (this.mailboxes?.inboxes || [])
|
||||||
}
|
|
||||||
|
|
||||||
get requiredWriteRelays() {
|
|
||||||
return DEFAULT_WRITE_RELAYS;
|
|
||||||
}
|
|
||||||
|
|
||||||
get mailboxReadRelays() {
|
|
||||||
return (this.mailboxes?.inboxes || [])
|
|
||||||
.map(normalizeRelayUrl)
|
.map(normalizeRelayUrl)
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
const defaults = DEFAULT_READ_RELAYS.map(normalizeRelayUrl).filter(Boolean);
|
||||||
|
return Array.from(new Set([...defaults, ...mailboxes]));
|
||||||
}
|
}
|
||||||
|
|
||||||
get mailboxWriteRelays() {
|
get defaultWriteRelays() {
|
||||||
return (this.mailboxes?.outboxes || [])
|
const mailboxes = (this.mailboxes?.outboxes || [])
|
||||||
.map(normalizeRelayUrl)
|
.map(normalizeRelayUrl)
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
}
|
const defaults =
|
||||||
|
DEFAULT_WRITE_RELAYS.map(normalizeRelayUrl).filter(Boolean);
|
||||||
get configuredReadRelays() {
|
return Array.from(new Set([...defaults, ...mailboxes]));
|
||||||
const configured = uniqNormalizedRelays([
|
|
||||||
...this.mailboxReadRelays,
|
|
||||||
...(this.settings.nostrReadRelays || []),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return excludeRequiredRelays(
|
|
||||||
configured,
|
|
||||||
this.settings.nostrReadRelayExclusions || []
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
get configuredWriteRelays() {
|
|
||||||
const configured = uniqNormalizedRelays([
|
|
||||||
...this.mailboxWriteRelays,
|
|
||||||
...(this.settings.nostrWriteRelays || []),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return excludeRequiredRelays(
|
|
||||||
configured,
|
|
||||||
this.settings.nostrWriteRelayExclusions || []
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get activeReadRelays() {
|
get activeReadRelays() {
|
||||||
return mergeRequiredRelays(
|
if (this.settings.nostrReadRelays) {
|
||||||
this.requiredReadRelays,
|
return Array.from(
|
||||||
this.configuredReadRelays
|
new Set(
|
||||||
);
|
this.settings.nostrReadRelays.map(normalizeRelayUrl).filter(Boolean)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return this.defaultReadRelays;
|
||||||
}
|
}
|
||||||
|
|
||||||
get activeWriteRelays() {
|
get activeWriteRelays() {
|
||||||
return mergeRequiredRelays(
|
if (this.settings.nostrWriteRelays) {
|
||||||
this.requiredWriteRelays,
|
return Array.from(
|
||||||
this.configuredWriteRelays
|
new Set(
|
||||||
);
|
this.settings.nostrWriteRelays.map(normalizeRelayUrl).filter(Boolean)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return this.defaultWriteRelays;
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadPlacesInBounds(bbox) {
|
async loadPlacesInBounds(bbox) {
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ const DEFAULT_SETTINGS = {
|
|||||||
nostrPhotoFallbackUploads: false,
|
nostrPhotoFallbackUploads: false,
|
||||||
nostrReadRelays: null,
|
nostrReadRelays: null,
|
||||||
nostrWriteRelays: null,
|
nostrWriteRelays: null,
|
||||||
nostrReadRelayExclusions: null,
|
|
||||||
nostrWriteRelayExclusions: null,
|
|
||||||
experimentalEnablePhotoDeletion: false,
|
experimentalEnablePhotoDeletion: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -23,9 +21,6 @@ export default class SettingsService extends Service {
|
|||||||
DEFAULT_SETTINGS.nostrPhotoFallbackUploads;
|
DEFAULT_SETTINGS.nostrPhotoFallbackUploads;
|
||||||
@tracked nostrReadRelays = DEFAULT_SETTINGS.nostrReadRelays;
|
@tracked nostrReadRelays = DEFAULT_SETTINGS.nostrReadRelays;
|
||||||
@tracked nostrWriteRelays = DEFAULT_SETTINGS.nostrWriteRelays;
|
@tracked nostrWriteRelays = DEFAULT_SETTINGS.nostrWriteRelays;
|
||||||
@tracked nostrReadRelayExclusions = DEFAULT_SETTINGS.nostrReadRelayExclusions;
|
|
||||||
@tracked nostrWriteRelayExclusions =
|
|
||||||
DEFAULT_SETTINGS.nostrWriteRelayExclusions;
|
|
||||||
@tracked experimentalEnablePhotoDeletion =
|
@tracked experimentalEnablePhotoDeletion =
|
||||||
DEFAULT_SETTINGS.experimentalEnablePhotoDeletion;
|
DEFAULT_SETTINGS.experimentalEnablePhotoDeletion;
|
||||||
|
|
||||||
@@ -116,8 +111,6 @@ export default class SettingsService extends Service {
|
|||||||
this.nostrPhotoFallbackUploads = finalSettings.nostrPhotoFallbackUploads;
|
this.nostrPhotoFallbackUploads = finalSettings.nostrPhotoFallbackUploads;
|
||||||
this.nostrReadRelays = finalSettings.nostrReadRelays;
|
this.nostrReadRelays = finalSettings.nostrReadRelays;
|
||||||
this.nostrWriteRelays = finalSettings.nostrWriteRelays;
|
this.nostrWriteRelays = finalSettings.nostrWriteRelays;
|
||||||
this.nostrReadRelayExclusions = finalSettings.nostrReadRelayExclusions;
|
|
||||||
this.nostrWriteRelayExclusions = finalSettings.nostrWriteRelayExclusions;
|
|
||||||
this.experimentalEnablePhotoDeletion =
|
this.experimentalEnablePhotoDeletion =
|
||||||
finalSettings.experimentalEnablePhotoDeletion;
|
finalSettings.experimentalEnablePhotoDeletion;
|
||||||
|
|
||||||
@@ -134,8 +127,6 @@ export default class SettingsService extends Service {
|
|||||||
nostrPhotoFallbackUploads: this.nostrPhotoFallbackUploads,
|
nostrPhotoFallbackUploads: this.nostrPhotoFallbackUploads,
|
||||||
nostrReadRelays: this.nostrReadRelays,
|
nostrReadRelays: this.nostrReadRelays,
|
||||||
nostrWriteRelays: this.nostrWriteRelays,
|
nostrWriteRelays: this.nostrWriteRelays,
|
||||||
nostrReadRelayExclusions: this.nostrReadRelayExclusions,
|
|
||||||
nostrWriteRelayExclusions: this.nostrWriteRelayExclusions,
|
|
||||||
experimentalEnablePhotoDeletion: this.experimentalEnablePhotoDeletion,
|
experimentalEnablePhotoDeletion: this.experimentalEnablePhotoDeletion,
|
||||||
};
|
};
|
||||||
localStorage.setItem('marco:settings', JSON.stringify(settings));
|
localStorage.setItem('marco:settings', JSON.stringify(settings));
|
||||||
|
|||||||
@@ -14,30 +14,6 @@ export function normalizeRelayUrl(url) {
|
|||||||
return normalized;
|
return normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function uniqNormalizedRelays(relays = []) {
|
|
||||||
return Array.from(new Set(relays.map(normalizeRelayUrl).filter(Boolean)));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function mergeRequiredRelays(requiredRelays = [], customRelays = []) {
|
|
||||||
const requiredSet = new Set(requiredRelays.filter(Boolean));
|
|
||||||
const merged = [...requiredRelays.filter(Boolean)];
|
|
||||||
|
|
||||||
for (const relay of uniqNormalizedRelays(customRelays)) {
|
|
||||||
if (!requiredSet.has(relay)) {
|
|
||||||
merged.push(relay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return merged;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function excludeRequiredRelays(customRelays = [], requiredRelays = []) {
|
|
||||||
const requiredSet = new Set(requiredRelays.filter(Boolean));
|
|
||||||
return uniqNormalizedRelays(customRelays).filter((relay) => {
|
|
||||||
return !requiredSet.has(relay);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts and normalizes photo data from NIP-360 (Place Photos) events.
|
* Extracts and normalizes photo data from NIP-360 (Place Photos) events.
|
||||||
* Sorts chronologically and guarantees the first landscape photo (or first portrait) is at index 0.
|
* Sorts chronologically and guarantees the first landscape photo (or first portrait) is at index 0.
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { module, test } from 'qunit';
|
|||||||
import { visit, currentURL, waitFor, triggerEvent } from '@ember/test-helpers';
|
import { visit, currentURL, waitFor, triggerEvent } from '@ember/test-helpers';
|
||||||
import { setupApplicationTest } from 'marco/tests/helpers';
|
import { setupApplicationTest } from 'marco/tests/helpers';
|
||||||
import Service from '@ember/service';
|
import Service from '@ember/service';
|
||||||
import sinon from 'sinon';
|
|
||||||
|
|
||||||
module('Acceptance | map search reset', function (hooks) {
|
module('Acceptance | map search reset', function (hooks) {
|
||||||
setupApplicationTest(hooks);
|
setupApplicationTest(hooks);
|
||||||
@@ -17,58 +16,10 @@ module('Acceptance | map search reset', function (hooks) {
|
|||||||
'marco:map-view',
|
'marco:map-view',
|
||||||
JSON.stringify(highZoomState)
|
JSON.stringify(highZoomState)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Stub window.fetch using Sinon
|
|
||||||
// We want to intercept map style requests and let everything else through
|
|
||||||
this.fetchStub = sinon.stub(window, 'fetch');
|
|
||||||
|
|
||||||
this.fetchStub.callsFake(async (input, init) => {
|
|
||||||
let url = input;
|
|
||||||
if (typeof input === 'object' && input !== null && 'url' in input) {
|
|
||||||
url = input.url;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
typeof url === 'string' &&
|
|
||||||
url.includes('tiles.openfreemap.org/styles/liberty')
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
ok: true,
|
|
||||||
status: 200,
|
|
||||||
json: async () => ({
|
|
||||||
version: 8,
|
|
||||||
name: 'Liberty',
|
|
||||||
sources: {
|
|
||||||
openmaptiles: {
|
|
||||||
type: 'vector',
|
|
||||||
url: 'https://tiles.openfreemap.org/planet',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
layers: [
|
|
||||||
{
|
|
||||||
id: 'background',
|
|
||||||
type: 'background',
|
|
||||||
paint: {
|
|
||||||
'background-color': '#123456',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
glyphs:
|
|
||||||
'https://tiles.openfreemap.org/fonts/{fontstack}/{range}.pbf',
|
|
||||||
sprite: 'https://tiles.openfreemap.org/sprites/liberty',
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pass through to the original implementation
|
|
||||||
return this.fetchStub.wrappedMethod(input, init);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
hooks.afterEach(function () {
|
hooks.afterEach(function () {
|
||||||
window.localStorage.removeItem('marco:map-view');
|
window.localStorage.removeItem('marco:map-view');
|
||||||
// Restore the original fetch
|
|
||||||
this.fetchStub.restore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('clicking the map clears the category search parameter', async function (assert) {
|
test('clicking the map clears the category search parameter', async function (assert) {
|
||||||
|
|||||||
@@ -49,19 +49,11 @@ export class MockNostrDataService extends Service {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
get requiredReadRelays() {
|
get defaultReadRelays() {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
get requiredWriteRelays() {
|
get defaultWriteRelays() {
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
get mailboxReadRelays() {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
get mailboxWriteRelays() {
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,188 +0,0 @@
|
|||||||
import { module, test } from 'qunit';
|
|
||||||
import { setupRenderingTest } from 'marco/tests/helpers';
|
|
||||||
import { click, fillIn, render } from '@ember/test-helpers';
|
|
||||||
import Service, { service } from '@ember/service';
|
|
||||||
import AppMenuSettingsNostr from 'marco/components/app-menu/settings/nostr';
|
|
||||||
import {
|
|
||||||
excludeRequiredRelays,
|
|
||||||
mergeRequiredRelays,
|
|
||||||
uniqNormalizedRelays,
|
|
||||||
} from 'marco/utils/nostr';
|
|
||||||
|
|
||||||
class MockNostrDataService extends Service {
|
|
||||||
@service settings;
|
|
||||||
|
|
||||||
requiredReadRelays = ['wss://nostr.kosmos.org'];
|
|
||||||
requiredWriteRelays = [];
|
|
||||||
|
|
||||||
mailboxReadRelays = ['wss://mailbox.example.com'];
|
|
||||||
mailboxWriteRelays = ['wss://mailbox-write.example.com'];
|
|
||||||
|
|
||||||
get configuredReadRelays() {
|
|
||||||
const configured = uniqNormalizedRelays([
|
|
||||||
...this.mailboxReadRelays,
|
|
||||||
...(this.settings.nostrReadRelays || []),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return excludeRequiredRelays(
|
|
||||||
configured,
|
|
||||||
this.settings.nostrReadRelayExclusions || []
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
get configuredWriteRelays() {
|
|
||||||
const configured = uniqNormalizedRelays([
|
|
||||||
...this.mailboxWriteRelays,
|
|
||||||
...(this.settings.nostrWriteRelays || []),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return excludeRequiredRelays(
|
|
||||||
configured,
|
|
||||||
this.settings.nostrWriteRelayExclusions || []
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
get activeReadRelays() {
|
|
||||||
return mergeRequiredRelays(
|
|
||||||
this.requiredReadRelays,
|
|
||||||
this.configuredReadRelays
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
get activeWriteRelays() {
|
|
||||||
return mergeRequiredRelays(
|
|
||||||
this.requiredWriteRelays,
|
|
||||||
this.configuredWriteRelays
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async clearCache() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
function readRows(element) {
|
|
||||||
const list = element.querySelectorAll('.relay-list')[0];
|
|
||||||
return [...list.querySelectorAll('li')];
|
|
||||||
}
|
|
||||||
|
|
||||||
function writeRows(element) {
|
|
||||||
const list = element.querySelectorAll('.relay-list')[1];
|
|
||||||
return [...list.querySelectorAll('li')];
|
|
||||||
}
|
|
||||||
|
|
||||||
function rowByText(rows, text) {
|
|
||||||
return rows.find((row) => row.textContent.includes(text));
|
|
||||||
}
|
|
||||||
|
|
||||||
module('Integration | Component | app-menu/settings/nostr', function (hooks) {
|
|
||||||
setupRenderingTest(hooks);
|
|
||||||
|
|
||||||
hooks.beforeEach(function () {
|
|
||||||
localStorage.removeItem('marco:settings');
|
|
||||||
|
|
||||||
this.owner.register('service:nostrData', MockNostrDataService);
|
|
||||||
this.settings = this.owner.lookup('service:settings');
|
|
||||||
this.onChange = () => {};
|
|
||||||
});
|
|
||||||
|
|
||||||
hooks.afterEach(function () {
|
|
||||||
localStorage.removeItem('marco:settings');
|
|
||||||
});
|
|
||||||
|
|
||||||
async function renderAndOpenDetails(context) {
|
|
||||||
await render(
|
|
||||||
<template><AppMenuSettingsNostr @onChange={{this.onChange}} /></template>
|
|
||||||
);
|
|
||||||
await click('summary');
|
|
||||||
return context.element;
|
|
||||||
}
|
|
||||||
|
|
||||||
test('required read relay is first and non-removable', async function (assert) {
|
|
||||||
const element = await renderAndOpenDetails(this);
|
|
||||||
const rows = readRows(element);
|
|
||||||
|
|
||||||
assert.dom(rows[0]).includesText('nostr.kosmos.org');
|
|
||||||
|
|
||||||
const requiredRow = rowByText(rows, 'nostr.kosmos.org');
|
|
||||||
const mailboxRow = rowByText(rows, 'mailbox.example.com');
|
|
||||||
|
|
||||||
assert.dom(requiredRow.querySelector('.btn-remove-relay')).doesNotExist();
|
|
||||||
assert.dom(mailboxRow.querySelector('.btn-remove-relay')).exists();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('removing mailbox read relay stores exclusion override', async function (assert) {
|
|
||||||
const element = await renderAndOpenDetails(this);
|
|
||||||
const mailboxRow = rowByText(readRows(element), 'mailbox.example.com');
|
|
||||||
|
|
||||||
await click(mailboxRow.querySelector('.btn-remove-relay'));
|
|
||||||
|
|
||||||
assert.deepEqual(this.settings.nostrReadRelayExclusions, [
|
|
||||||
'wss://mailbox.example.com',
|
|
||||||
]);
|
|
||||||
assert.strictEqual(this.settings.nostrReadRelays, null);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('removing custom read relay updates custom list without exclusions', async function (assert) {
|
|
||||||
this.settings.update('nostrReadRelays', ['wss://custom.example.com']);
|
|
||||||
|
|
||||||
const element = await renderAndOpenDetails(this);
|
|
||||||
const customRow = rowByText(readRows(element), 'custom.example.com');
|
|
||||||
|
|
||||||
await click(customRow.querySelector('.btn-remove-relay'));
|
|
||||||
|
|
||||||
assert.strictEqual(this.settings.nostrReadRelays, null);
|
|
||||||
assert.strictEqual(this.settings.nostrReadRelayExclusions, null);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('adding read relay clears existing exclusion for same relay', async function (assert) {
|
|
||||||
this.settings.update('nostrReadRelayExclusions', [
|
|
||||||
'wss://mailbox.example.com',
|
|
||||||
]);
|
|
||||||
|
|
||||||
const element = await renderAndOpenDetails(this);
|
|
||||||
|
|
||||||
await fillIn('#new-read-relay', 'Mailbox.EXAMPLE.com/');
|
|
||||||
await click(element.querySelector('#new-read-relay').nextElementSibling);
|
|
||||||
|
|
||||||
assert.deepEqual(this.settings.nostrReadRelays, [
|
|
||||||
'wss://mailbox.example.com',
|
|
||||||
]);
|
|
||||||
assert.strictEqual(this.settings.nostrReadRelayExclusions, null);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('reset read relays clears additions and exclusions', async function (assert) {
|
|
||||||
this.settings.update('nostrReadRelays', ['wss://custom.example.com']);
|
|
||||||
this.settings.update('nostrReadRelayExclusions', [
|
|
||||||
'wss://mailbox.example.com',
|
|
||||||
]);
|
|
||||||
|
|
||||||
const element = await renderAndOpenDetails(this);
|
|
||||||
await click(element.querySelectorAll('.reset-relays')[0]);
|
|
||||||
|
|
||||||
assert.strictEqual(this.settings.nostrReadRelays, null);
|
|
||||||
assert.strictEqual(this.settings.nostrReadRelayExclusions, null);
|
|
||||||
|
|
||||||
const requiredRow = rowByText(readRows(element), 'nostr.kosmos.org');
|
|
||||||
assert.dom(requiredRow).exists();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('write relays are removable and mailbox delete stores exclusion', async function (assert) {
|
|
||||||
this.settings.update('nostrWriteRelays', [
|
|
||||||
'wss://custom-write.example.com',
|
|
||||||
]);
|
|
||||||
|
|
||||||
const element = await renderAndOpenDetails(this);
|
|
||||||
const rows = writeRows(element);
|
|
||||||
|
|
||||||
assert.true(
|
|
||||||
rows.every((row) => row.querySelector('.btn-remove-relay')),
|
|
||||||
'all write relays can be removed'
|
|
||||||
);
|
|
||||||
|
|
||||||
const mailboxRow = rowByText(rows, 'mailbox-write.example.com');
|
|
||||||
await click(mailboxRow.querySelector('.btn-remove-relay'));
|
|
||||||
|
|
||||||
assert.deepEqual(this.settings.nostrWriteRelayExclusions, [
|
|
||||||
'wss://mailbox-write.example.com',
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,11 +1,5 @@
|
|||||||
import { module, test } from 'qunit';
|
import { module, test } from 'qunit';
|
||||||
import {
|
import { normalizeRelayUrl, parsePlacePhotos } from 'marco/utils/nostr';
|
||||||
excludeRequiredRelays,
|
|
||||||
mergeRequiredRelays,
|
|
||||||
normalizeRelayUrl,
|
|
||||||
parsePlacePhotos,
|
|
||||||
uniqNormalizedRelays,
|
|
||||||
} from 'marco/utils/nostr';
|
|
||||||
|
|
||||||
module('Unit | Utility | nostr', function () {
|
module('Unit | Utility | nostr', function () {
|
||||||
test('normalizeRelayUrl normalizes protocol, case, and slashes', function (assert) {
|
test('normalizeRelayUrl normalizes protocol, case, and slashes', function (assert) {
|
||||||
@@ -147,59 +141,4 @@ module('Unit | Utility | nostr', function () {
|
|||||||
assert.strictEqual(photos[0].placeIdentifier, 'osm:node:123');
|
assert.strictEqual(photos[0].placeIdentifier, 'osm:node:123');
|
||||||
assert.strictEqual(photos[1].placeIdentifier, 'osm:node:456');
|
assert.strictEqual(photos[1].placeIdentifier, 'osm:node:456');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('uniqNormalizedRelays returns normalized unique relays', function (assert) {
|
|
||||||
const relays = uniqNormalizedRelays([
|
|
||||||
'Relay.example.com',
|
|
||||||
'wss://relay.example.com/',
|
|
||||||
'wss://other.example.com',
|
|
||||||
]);
|
|
||||||
|
|
||||||
assert.deepEqual(relays, [
|
|
||||||
'wss://relay.example.com',
|
|
||||||
'wss://other.example.com',
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('mergeRequiredRelays keeps required relays as-is and merges normalized custom relays', function (assert) {
|
|
||||||
const relays = mergeRequiredRelays(
|
|
||||||
['wss://required.example.com', 'required-2.example.com'],
|
|
||||||
['required-2.example.com/', 'wss://custom.example.com']
|
|
||||||
);
|
|
||||||
|
|
||||||
assert.deepEqual(relays, [
|
|
||||||
'wss://required.example.com',
|
|
||||||
'required-2.example.com',
|
|
||||||
'wss://required-2.example.com',
|
|
||||||
'wss://custom.example.com',
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('excludeRequiredRelays removes required relays from normalized custom list', function (assert) {
|
|
||||||
const relays = excludeRequiredRelays(
|
|
||||||
[
|
|
||||||
'wss://required.example.com',
|
|
||||||
'custom.example.com',
|
|
||||||
'ws://custom2.example.com',
|
|
||||||
],
|
|
||||||
['wss://required.example.com']
|
|
||||||
);
|
|
||||||
|
|
||||||
assert.deepEqual(relays, [
|
|
||||||
'wss://custom.example.com',
|
|
||||||
'ws://custom2.example.com',
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('excludeRequiredRelays trusts required list without normalizing it', function (assert) {
|
|
||||||
const relays = excludeRequiredRelays(
|
|
||||||
['Required.example.com', 'custom.example.com'],
|
|
||||||
['required.example.com']
|
|
||||||
);
|
|
||||||
|
|
||||||
assert.deepEqual(relays, [
|
|
||||||
'wss://required.example.com',
|
|
||||||
'wss://custom.example.com',
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user