Open the gallery on a shared place photo link
The /e/:event_id route redirected to the place with a `photo` query param, but that only scrolled the inline carousel. It now opens the gallery modal, focused on the linked photo. The photo list loads asynchronously (cache first, then relays) and more photos can arrive while the gallery is open, so the auto-open waits for the linked photo, opens exactly once, and keeps focus on the same event id. A manual open or close consumes the pending link so a late-arriving photo cannot reopen or hijack the gallery the user is looking at. When the linked photo is hidden as untrusted, following the link reveals all untrusted photos by that author for the current place. The reveal is place-scoped and cleared when the place changes, so it never leaks into other places, and other authors' hidden photos stay hidden.
This commit is contained in:
6 files changed
+598
-46
No files matched your search
@@ -136,6 +136,10 @@ export default class PhotoGallery extends Component {
|
||||
@service blossom;
|
||||
@service settings;
|
||||
|
||||
// The focused photo. `parsePlacePhotos` rebuilds the photo objects on every
|
||||
// update, so identity is unstable — comparisons below go through `eventId`
|
||||
// instead. The referenced Nostr event is immutable, so a held object stays
|
||||
// valid even when a newer object for the same event replaces it.
|
||||
@tracked currentPhoto = this.args.selectedPhoto || this.args.photos?.[0];
|
||||
@tracked zapModalOpen = false;
|
||||
|
||||
@@ -216,7 +220,7 @@ export default class PhotoGallery extends Component {
|
||||
|
||||
@action
|
||||
handleVisiblePhotoChange(photo) {
|
||||
if (this.currentPhoto !== photo) {
|
||||
if (this.currentPhoto?.eventId !== photo.eventId) {
|
||||
this.currentPhoto = photo;
|
||||
}
|
||||
}
|
||||
@@ -230,7 +234,9 @@ export default class PhotoGallery extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentIndex = this.args.photos.indexOf(this.currentPhoto);
|
||||
const currentIndex = this.args.photos.findIndex(
|
||||
(p) => p.eventId === this.currentPhoto?.eventId
|
||||
);
|
||||
if (currentIndex === -1) return;
|
||||
|
||||
if (e.key === 'ArrowLeft' && currentIndex > 0) {
|
||||
@@ -326,15 +332,19 @@ export default class PhotoGallery extends Component {
|
||||
}
|
||||
|
||||
deletePhotoTask = task(async () => {
|
||||
const deletedEventId = this.currentPhoto.eventId;
|
||||
const deletedIndex = this.args.photos?.indexOf(this.currentPhoto) ?? -1;
|
||||
// Hold the photo for the duration of the task: `args.photos` may drop the
|
||||
// event once the kind 5 is added to the store below.
|
||||
const photo = this.currentPhoto;
|
||||
const deletedEventId = photo.eventId;
|
||||
const deletedIndex =
|
||||
this.args.photos?.findIndex((p) => p.eventId === deletedEventId) ?? -1;
|
||||
|
||||
try {
|
||||
// Publish Nostr kind: 5 deletion event first so we don't end up with dead blossom links on a failure
|
||||
const tags = [['e', deletedEventId]];
|
||||
|
||||
if (this.currentPhoto.placeIdentifier) {
|
||||
tags.push(['i', this.currentPhoto.placeIdentifier]);
|
||||
if (photo.placeIdentifier) {
|
||||
tags.push(['i', photo.placeIdentifier]);
|
||||
}
|
||||
|
||||
const event = await withMarcoClientTag(
|
||||
@@ -361,9 +371,9 @@ export default class PhotoGallery extends Component {
|
||||
// to extracting them from the URLs for legacy events without `x`.
|
||||
const hashRegex = /[0-9a-f]{64}/i;
|
||||
const hashes =
|
||||
this.currentPhoto.hashes?.length > 0
|
||||
? this.currentPhoto.hashes
|
||||
: [this.currentPhoto.url, this.currentPhoto.thumbUrl]
|
||||
photo.hashes?.length > 0
|
||||
? photo.hashes
|
||||
: [photo.url, photo.thumbUrl]
|
||||
.map((url) => url?.match(hashRegex)?.[0])
|
||||
.filter(Boolean);
|
||||
|
||||
@@ -377,8 +387,9 @@ export default class PhotoGallery extends Component {
|
||||
|
||||
this.toast.show('Photo deleted successfully');
|
||||
|
||||
// Navigate to the next remaining photo, or close the gallery if none left.
|
||||
// this.args.photos may be stale until Glimmer re-renders, so filter locally.
|
||||
// Navigate to the next remaining photo, or close the gallery if none
|
||||
// left. `this.args.photos` may be stale until Glimmer re-renders, so
|
||||
// filter locally.
|
||||
const remaining = (this.args.photos || []).filter(
|
||||
(p) => p.eventId !== deletedEventId
|
||||
);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { service } from '@ember/service';
|
||||
import { on } from '@ember/modifier';
|
||||
import { scheduleTask } from 'ember-lifeline';
|
||||
import { modifier } from 'ember-modifier';
|
||||
import { htmlSafe } from '@ember/template';
|
||||
import { humanizeOsmTag } from '../utils/format-text';
|
||||
import { getLocalizedName, getPlaceType } from '../utils/osm';
|
||||
@@ -46,6 +48,36 @@ export default class PlaceDetails extends Component {
|
||||
@tracked isPhotoUploadModalOpen = false;
|
||||
@tracked isNostrConnectModalOpen = false;
|
||||
@tracked newlyUploadedPhotoId = null;
|
||||
// Event id of the deep-linked photo we already auto-opened the gallery for,
|
||||
// so late-arriving photos or extra renders never reopen it. A plain field
|
||||
// (not rendered) so the render-time modifier can read and write it freely.
|
||||
autoOpenedPhotoEventId = null;
|
||||
|
||||
// Opens the gallery for a deep-linked photo (from `/e/:event_id`). Photos
|
||||
// load asynchronously (cache first, then relays) and more can arrive at any
|
||||
// time, so wait until the linked photo is present — revealing its author's
|
||||
// untrusted photos first if it is hidden — then open exactly once.
|
||||
//
|
||||
// State changes are deferred to the `actions` queue: the modifier runs during
|
||||
// the render, and both opening the gallery and revealing photos mutate
|
||||
// tracked state that is already being consumed by this render.
|
||||
syncDeepLinkedPhoto = modifier((element, [focusEventId, photos]) => {
|
||||
if (!focusEventId || this.autoOpenedPhotoEventId === focusEventId) return;
|
||||
|
||||
const photo = photos?.find((p) => p.eventId === focusEventId);
|
||||
if (photo) {
|
||||
this.autoOpenedPhotoEventId = focusEventId;
|
||||
scheduleTask(this, 'actions', () => this.openGallery(photo));
|
||||
return;
|
||||
}
|
||||
|
||||
// Not visible yet: if it is in the timeline but hidden as untrusted,
|
||||
// reveal its author's untrusted photos for this place. The resulting
|
||||
// `placePhotos` update re-runs this modifier, which then opens the gallery.
|
||||
scheduleTask(this, 'actions', () =>
|
||||
this.nostrData.revealPlacePhotoAuthor?.(focusEventId)
|
||||
);
|
||||
});
|
||||
|
||||
@action
|
||||
handleUploadStateChange(isActive) {
|
||||
@@ -152,8 +184,14 @@ export default class PlaceDetails extends Component {
|
||||
// route's `photo` query param (see the `/e/:event_id` route), or a photo just
|
||||
// uploaded on this page.
|
||||
get focusPhotoEventId() {
|
||||
const photo = this.router.currentRoute?.queryParams?.photo;
|
||||
return photo || this.newlyUploadedPhotoId || null;
|
||||
return this.deepLinkedPhotoEventId || this.newlyUploadedPhotoId || null;
|
||||
}
|
||||
|
||||
// The event id of a photo deep-linked via the route's `photo` query param.
|
||||
// Unlike `focusPhotoEventId`, this excludes freshly-uploaded photos, which
|
||||
// only scroll the inline carousel and must not auto-open the gallery.
|
||||
get deepLinkedPhotoEventId() {
|
||||
return this.router.currentRoute?.queryParams?.photo || null;
|
||||
}
|
||||
|
||||
get hasMultipleUntrusted() {
|
||||
@@ -531,20 +569,34 @@ export default class PlaceDetails extends Component {
|
||||
return !!this.place.description;
|
||||
}
|
||||
|
||||
// A manual open or close means the user has taken over the gallery, so the
|
||||
// pending deep link is considered handled and must not hijack it later (e.g.
|
||||
// when the linked photo arrives after the user opened or closed the gallery).
|
||||
consumeDeepLink() {
|
||||
if (this.deepLinkedPhotoEventId && !this.autoOpenedPhotoEventId) {
|
||||
this.autoOpenedPhotoEventId = this.deepLinkedPhotoEventId;
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
openGallery(photo) {
|
||||
this.consumeDeepLink();
|
||||
this.selectedGalleryPhoto = photo;
|
||||
this.isGalleryOpen = true;
|
||||
}
|
||||
|
||||
@action
|
||||
closeGallery() {
|
||||
this.consumeDeepLink();
|
||||
this.isGalleryOpen = false;
|
||||
this.selectedGalleryPhoto = null;
|
||||
}
|
||||
|
||||
<template>
|
||||
<div class="place-details">
|
||||
<div
|
||||
class="place-details"
|
||||
{{this.syncDeepLinkedPhoto this.deepLinkedPhotoEventId this.photos}}
|
||||
>
|
||||
{{#if this.isEditing}}
|
||||
<PlaceEditForm
|
||||
@place={{this.place}}
|
||||
|
||||
@@ -123,6 +123,11 @@ export default class NostrDataService extends Service {
|
||||
@tracked showUntrustedContent = false;
|
||||
// Count of currently-hidden (untrusted) place photos for the selected place.
|
||||
@tracked untrustedContentCount = 0;
|
||||
// Untrusted authors whose content is revealed for the currently selected
|
||||
// place because the user followed a deep link to one of their photos. Kept
|
||||
// place-scoped (cleared in `loadPhotosForPlace`) so a reveal never leaks into
|
||||
// other places. Reassigned — never mutated — to stay reactive.
|
||||
@tracked revealedUntrustedAuthors = new Set();
|
||||
_allPlacePhotos = [];
|
||||
|
||||
_profileSub = null;
|
||||
@@ -589,6 +594,7 @@ export default class NostrDataService extends Service {
|
||||
this._clearZapRefreshTimer();
|
||||
|
||||
this.placePhotos = [];
|
||||
this.revealedUntrustedAuthors = new Set();
|
||||
this.zapReceipts = {};
|
||||
this._lastPhotoIds = new Set();
|
||||
this._clearProfileSubs();
|
||||
@@ -646,14 +652,24 @@ export default class NostrDataService extends Service {
|
||||
);
|
||||
}
|
||||
|
||||
// Recompute `placePhotos` from `_allPlacePhotos` applying the trust filter
|
||||
// and the session-only reveal toggle. Called whenever the timeline emits or
|
||||
// the user flips `showUntrustedContent`.
|
||||
// Recompute `placePhotos` from `_allPlacePhotos` applying the trust filter,
|
||||
// the session-only reveal toggle and the per-place author reveals. Called
|
||||
// whenever the timeline emits, the user flips `showUntrustedContent` or a
|
||||
// deep link reveals an author.
|
||||
_updatePlacePhotos() {
|
||||
const events = this._allPlacePhotos;
|
||||
const { trusted, untrusted } = this.partitionByTrust(events);
|
||||
this.untrustedContentCount = untrusted.length;
|
||||
this.placePhotos = this.showUntrustedContent ? events : trusted;
|
||||
const trustedIds = new Set(trusted.map((e) => e.id));
|
||||
const hidden = untrusted.filter(
|
||||
(e) => !this.revealedUntrustedAuthors.has(e.pubkey)
|
||||
);
|
||||
this.untrustedContentCount = hidden.length;
|
||||
this.placePhotos = this.showUntrustedContent
|
||||
? events
|
||||
: events.filter(
|
||||
(e) =>
|
||||
trustedIds.has(e.id) || this.revealedUntrustedAuthors.has(e.pubkey)
|
||||
);
|
||||
}
|
||||
|
||||
@action
|
||||
@@ -662,6 +678,34 @@ export default class NostrDataService extends Service {
|
||||
this._updatePlacePhotos();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reveals all untrusted photos by the author of `eventId` for the current
|
||||
* place, so following a deep link to one untrusted photo also shows the rest
|
||||
* of that author's contribution. Other authors' hidden content stays hidden.
|
||||
*
|
||||
* Returns `true` when the event is present in the place timeline (hidden or
|
||||
* not) and `false` while it has not loaded yet, so callers can retry.
|
||||
*
|
||||
* @param {string} eventId
|
||||
* @returns {boolean}
|
||||
*/
|
||||
revealPlacePhotoAuthor(eventId) {
|
||||
if (!eventId) return false;
|
||||
|
||||
const event = this._allPlacePhotos.find((e) => e.id === eventId);
|
||||
if (!event) return false;
|
||||
|
||||
if (!this.revealedUntrustedAuthors.has(event.pubkey)) {
|
||||
this.revealedUntrustedAuthors = new Set([
|
||||
...this.revealedUntrustedAuthors,
|
||||
event.pubkey,
|
||||
]);
|
||||
this._updatePlacePhotos();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async loadMyContributions(pubkey) {
|
||||
if (!pubkey) return;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'marco/tests/helpers';
|
||||
import { render, click, triggerKeyEvent } from '@ember/test-helpers';
|
||||
import { render, click, triggerKeyEvent, settled } from '@ember/test-helpers';
|
||||
import Service from '@ember/service';
|
||||
import { decodePointer } from 'applesauce-core/helpers/pointers';
|
||||
import PhotoGallery from 'marco/components/photo-gallery';
|
||||
@@ -379,6 +379,83 @@ module('Integration | Component | photo-gallery', function (hooks) {
|
||||
assert.ok(closed, 'gallery was closed when last photo was deleted');
|
||||
});
|
||||
|
||||
test('it completes the Blossom cleanup when the real close unmounts the gallery', async function (assert) {
|
||||
this.nostrAuth.pubkey = USER_A;
|
||||
this.settings.update('experimentalEnablePhotoDeletion', true);
|
||||
Object.defineProperty(this.nostrAuth, 'signer', {
|
||||
configurable: true,
|
||||
get: () => ({
|
||||
signEvent: async (e) => ({
|
||||
...e,
|
||||
id: 'a3b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1',
|
||||
sig: 'b3b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1',
|
||||
pubkey: USER_A,
|
||||
}),
|
||||
getPublicKey: async () => USER_A,
|
||||
}),
|
||||
});
|
||||
|
||||
const mainHash =
|
||||
'd3b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1';
|
||||
const thumbHash =
|
||||
'e3b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1';
|
||||
|
||||
this.set('photos', [
|
||||
{
|
||||
...this.photos[0],
|
||||
url: 'https://example.com/photo.jpg',
|
||||
thumbUrl: 'https://example.com/thumb.jpg',
|
||||
hash: mainHash,
|
||||
hashes: [mainHash, thumbHash],
|
||||
},
|
||||
]);
|
||||
this.selectedPhoto = this.photos[0];
|
||||
|
||||
// Real close: unmounts the gallery, so a task that closed the component
|
||||
// before finishing its Blossom cleanup would be cancelled.
|
||||
this.open = true;
|
||||
this.close = () => this.set('open', false);
|
||||
|
||||
sinon.stub(window, 'confirm').returns(true);
|
||||
const blossomStub = sinon.stub(this.blossom, 'delete').resolves();
|
||||
sinon
|
||||
.stub(this.nostrRelay, 'publish')
|
||||
.resolves([{ ok: true, from: 'wss://relay.test' }]);
|
||||
sinon.stub(this.nostrData.store, 'add');
|
||||
const toastSpy = sinon.spy(this.toast, 'show');
|
||||
|
||||
await render(
|
||||
<template>
|
||||
<div id="test-container">
|
||||
<div id="modal-portal"></div>
|
||||
{{#if this.open}}
|
||||
<PhotoGallery
|
||||
@photos={{this.photos}}
|
||||
@selectedPhoto={{this.selectedPhoto}}
|
||||
@onClose={{this.close}}
|
||||
/>
|
||||
{{/if}}
|
||||
</div>
|
||||
</template>
|
||||
);
|
||||
|
||||
await click('.dropdown-trigger-btn');
|
||||
await click('.dropdown-item.text-danger');
|
||||
|
||||
assert.strictEqual(
|
||||
blossomStub.callCount,
|
||||
2,
|
||||
'both blobs were deleted before the gallery unmounted'
|
||||
);
|
||||
assert.ok(
|
||||
toastSpy.calledWith('Photo deleted successfully'),
|
||||
'the success toast fired'
|
||||
);
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.doesNotExist('the gallery closed after the deletion');
|
||||
});
|
||||
|
||||
test('it copies event id to clipboard', async function (assert) {
|
||||
const eventId = '1'.repeat(64);
|
||||
this.nostrAuth.pubkey = USER_A;
|
||||
@@ -626,6 +703,47 @@ module('Integration | Component | photo-gallery', function (hooks) {
|
||||
.hasAttribute('data-current-event-id', 'event2');
|
||||
});
|
||||
|
||||
test('keeps the focused photo when new photos are added', async function (assert) {
|
||||
this.photos = [
|
||||
{ eventId: 'event1', url: 'photo1.jpg' },
|
||||
{ eventId: 'event2', url: 'photo2.jpg' },
|
||||
];
|
||||
this.selectedPhoto = this.photos[1];
|
||||
|
||||
await render(
|
||||
<template>
|
||||
<div id="test-container">
|
||||
<div id="modal-portal"></div>
|
||||
<PhotoGallery
|
||||
@photos={{this.photos}}
|
||||
@selectedPhoto={{this.selectedPhoto}}
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
);
|
||||
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.hasAttribute('data-current-event-id', 'event2');
|
||||
|
||||
// Another photo streams in first, as fresh objects (parsePlacePhotos
|
||||
// rebuilds every photo on each update).
|
||||
this.set('photos', [
|
||||
{ eventId: 'event0', url: 'photo0.jpg' },
|
||||
{ eventId: 'event1', url: 'photo1.jpg' },
|
||||
{ eventId: 'event2', url: 'photo2.jpg' },
|
||||
]);
|
||||
await settled();
|
||||
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.hasAttribute(
|
||||
'data-current-event-id',
|
||||
'event2',
|
||||
'focus does not jump to the newly added photo'
|
||||
);
|
||||
});
|
||||
|
||||
test('escape key closes gallery', async function (assert) {
|
||||
this.selectedPhoto = this.photos[0];
|
||||
let closed = false;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'marco/tests/helpers';
|
||||
import { render, click } from '@ember/test-helpers';
|
||||
import { render, click, settled } from '@ember/test-helpers';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import Service from '@ember/service';
|
||||
import PlaceDetails from 'marco/components/place-details';
|
||||
|
||||
@@ -807,42 +808,289 @@ module('Integration | Component | place-details', function (hooks) {
|
||||
assert.dom('.place-lists-manager .edit-item').doesNotExist();
|
||||
});
|
||||
|
||||
test('it focuses a deep-linked photo from the photo query param', async function (assert) {
|
||||
class NostrDataStub extends Service {
|
||||
placePhotos = [
|
||||
{
|
||||
id: 'event-2',
|
||||
pubkey: 'a'.repeat(64),
|
||||
kind: 360,
|
||||
created_at: 1,
|
||||
tags: [
|
||||
['i', 'osm:node:1'],
|
||||
['imeta', 'url https://example.com/a.jpg', 'dim 800x600'],
|
||||
],
|
||||
},
|
||||
];
|
||||
untrustedContentCount = 0;
|
||||
showUntrustedContent = false;
|
||||
toggleShowUntrustedContent() {}
|
||||
}
|
||||
function makePhoto(id, { pubkey = 'a'.repeat(64), created_at = 1 } = {}) {
|
||||
return {
|
||||
id,
|
||||
pubkey,
|
||||
kind: 360,
|
||||
created_at,
|
||||
tags: [
|
||||
['i', 'osm:node:1'],
|
||||
['imeta', `url https://example.com/${id}.jpg`, 'dim 800x600'],
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
class MockRouter extends Service {
|
||||
currentRoute = { queryParams: { photo: 'event-2' } };
|
||||
// Deep links render the gallery through `in-element`, so the test needs the
|
||||
// same `#modal-portal` the app provides.
|
||||
async function renderDetails(place) {
|
||||
await render(
|
||||
<template>
|
||||
<div id="modal-portal"></div>
|
||||
<PlaceDetails @place={{place}} />
|
||||
</template>
|
||||
);
|
||||
}
|
||||
|
||||
function registerDeepLink(owner, { photo = 'event-2', NostrDataStub }) {
|
||||
class DebLinkRouter extends Service {
|
||||
currentRoute = { queryParams: { photo } };
|
||||
transitionTo() {}
|
||||
urlFor() {
|
||||
return '/place/osm:node:1';
|
||||
}
|
||||
}
|
||||
|
||||
this.owner.register('service:nostr-data', NostrDataStub);
|
||||
this.owner.register('service:router', MockRouter);
|
||||
owner.register('service:nostr-data', NostrDataStub);
|
||||
owner.register('service:router', DebLinkRouter);
|
||||
}
|
||||
|
||||
test('it focuses and opens a deep-linked photo from the photo query param', async function (assert) {
|
||||
class NostrDataStub extends Service {
|
||||
@tracked placePhotos = [makePhoto('event-2')];
|
||||
untrustedContentCount = 0;
|
||||
showUntrustedContent = false;
|
||||
toggleShowUntrustedContent() {}
|
||||
}
|
||||
|
||||
registerDeepLink(this.owner, { NostrDataStub });
|
||||
|
||||
const place = { title: 'Test Place', osmId: '1', osmType: 'node' };
|
||||
|
||||
await render(<template><PlaceDetails @place={{place}} /></template>);
|
||||
await renderDetails(place);
|
||||
|
||||
assert
|
||||
.dom('.carousel-slide[data-event-id="event-2"]')
|
||||
.hasClass('active', 'the deep-linked photo is focused');
|
||||
.hasClass('active', 'the deep-linked photo is focused inline');
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.hasAttribute(
|
||||
'data-current-event-id',
|
||||
'event-2',
|
||||
'the gallery opens on the deep-linked photo'
|
||||
);
|
||||
});
|
||||
|
||||
test('it opens the gallery once the deep-linked photo arrives', async function (assert) {
|
||||
class NostrDataStub extends Service {
|
||||
@tracked placePhotos = [];
|
||||
untrustedContentCount = 0;
|
||||
showUntrustedContent = false;
|
||||
toggleShowUntrustedContent() {}
|
||||
revealPlacePhotoAuthor() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
registerDeepLink(this.owner, { NostrDataStub });
|
||||
|
||||
const nostrData = this.owner.lookup('service:nostr-data');
|
||||
const place = { title: 'Test Place', osmId: '1', osmType: 'node' };
|
||||
await renderDetails(place);
|
||||
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.doesNotExist('the gallery waits for the photo to load');
|
||||
|
||||
nostrData.placePhotos = [makePhoto('event-2')];
|
||||
await settled();
|
||||
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.hasAttribute(
|
||||
'data-current-event-id',
|
||||
'event-2',
|
||||
'the gallery opens once the photo arrives'
|
||||
);
|
||||
});
|
||||
|
||||
test('it reveals the linked author before opening the gallery', async function (assert) {
|
||||
const linked = makePhoto('event-2');
|
||||
|
||||
class NostrDataStub extends Service {
|
||||
@tracked placePhotos = [];
|
||||
untrustedContentCount = 1;
|
||||
showUntrustedContent = false;
|
||||
revealCalls = [];
|
||||
toggleShowUntrustedContent() {}
|
||||
revealPlacePhotoAuthor(eventId) {
|
||||
this.revealCalls.push(eventId);
|
||||
this.placePhotos = [linked];
|
||||
this.untrustedContentCount = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
registerDeepLink(this.owner, { NostrDataStub });
|
||||
|
||||
const nostrData = this.owner.lookup('service:nostr-data');
|
||||
const place = { title: 'Test Place', osmId: '1', osmType: 'node' };
|
||||
await renderDetails(place);
|
||||
|
||||
assert.deepEqual(
|
||||
nostrData.revealCalls,
|
||||
['event-2'],
|
||||
'the linked event was handed to the reveal'
|
||||
);
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.hasAttribute(
|
||||
'data-current-event-id',
|
||||
'event-2',
|
||||
'the gallery opens after revealing the author'
|
||||
);
|
||||
});
|
||||
|
||||
test('it keeps the deep-linked photo focused when photos are added later', async function (assert) {
|
||||
class NostrDataStub extends Service {
|
||||
@tracked placePhotos = [makePhoto('event-2', { created_at: 2 })];
|
||||
untrustedContentCount = 0;
|
||||
showUntrustedContent = false;
|
||||
toggleShowUntrustedContent() {}
|
||||
}
|
||||
|
||||
registerDeepLink(this.owner, { NostrDataStub });
|
||||
|
||||
const nostrData = this.owner.lookup('service:nostr-data');
|
||||
const place = { title: 'Test Place', osmId: '1', osmType: 'node' };
|
||||
await renderDetails(place);
|
||||
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.hasAttribute('data-current-event-id', 'event-2');
|
||||
|
||||
// Another author's photo streams in afterwards, with fresh objects.
|
||||
nostrData.placePhotos = [
|
||||
makePhoto('event-1', { pubkey: 'b'.repeat(64), created_at: 1 }),
|
||||
...nostrData.placePhotos,
|
||||
];
|
||||
await settled();
|
||||
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.hasAttribute(
|
||||
'data-current-event-id',
|
||||
'event-2',
|
||||
'the gallery stays focused on the deep-linked photo'
|
||||
);
|
||||
});
|
||||
|
||||
test('it does not reopen the gallery after the user closes it', async function (assert) {
|
||||
class NostrDataStub extends Service {
|
||||
@tracked placePhotos = [makePhoto('event-2')];
|
||||
untrustedContentCount = 0;
|
||||
showUntrustedContent = false;
|
||||
toggleShowUntrustedContent() {}
|
||||
}
|
||||
|
||||
registerDeepLink(this.owner, { NostrDataStub });
|
||||
|
||||
const nostrData = this.owner.lookup('service:nostr-data');
|
||||
const place = { title: 'Test Place', osmId: '1', osmType: 'node' };
|
||||
await renderDetails(place);
|
||||
|
||||
await click('.photo-gallery-content .close-btn');
|
||||
|
||||
assert.dom('.photo-gallery-content').doesNotExist('gallery closed');
|
||||
|
||||
nostrData.placePhotos = [
|
||||
...nostrData.placePhotos,
|
||||
makePhoto('event-1', { pubkey: 'b'.repeat(64), created_at: 3 }),
|
||||
];
|
||||
await settled();
|
||||
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.doesNotExist('the gallery does not reopen after being closed');
|
||||
});
|
||||
|
||||
test('it does not open the gallery without a deep link', async function (assert) {
|
||||
class NostrDataStub extends Service {
|
||||
@tracked placePhotos = [makePhoto('event-2')];
|
||||
untrustedContentCount = 0;
|
||||
showUntrustedContent = false;
|
||||
toggleShowUntrustedContent() {}
|
||||
}
|
||||
|
||||
registerDeepLink(this.owner, { photo: null, NostrDataStub });
|
||||
|
||||
const place = { title: 'Test Place', osmId: '1', osmType: 'node' };
|
||||
await renderDetails(place);
|
||||
|
||||
assert.dom('.carousel-slide').exists('the inline carousel renders');
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.doesNotExist('the gallery stays closed without a deep link');
|
||||
});
|
||||
|
||||
test('it does not reopen the gallery if the linked photo arrives after a manual close', async function (assert) {
|
||||
class NostrDataStub extends Service {
|
||||
@tracked placePhotos = [makePhoto('event-1')];
|
||||
untrustedContentCount = 0;
|
||||
showUntrustedContent = false;
|
||||
toggleShowUntrustedContent() {}
|
||||
revealPlacePhotoAuthor() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
registerDeepLink(this.owner, { NostrDataStub });
|
||||
|
||||
const nostrData = this.owner.lookup('service:nostr-data');
|
||||
const place = { title: 'Test Place', osmId: '1', osmType: 'node' };
|
||||
await renderDetails(place);
|
||||
|
||||
// The linked photo is not loaded yet. The user opens the gallery on
|
||||
// another photo, then closes it.
|
||||
await click('.carousel-slide[data-event-id="event-1"]');
|
||||
assert.dom('.photo-gallery-content').exists('the user opened the gallery');
|
||||
await click('.photo-gallery-content .close-btn');
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.doesNotExist('the user closed the gallery');
|
||||
|
||||
// The linked photo finally arrives; it must not reopen the gallery.
|
||||
nostrData.placePhotos = [...nostrData.placePhotos, makePhoto('event-2')];
|
||||
await settled();
|
||||
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.doesNotExist('the late linked photo does not reopen the gallery');
|
||||
});
|
||||
|
||||
test('it does not hijack a gallery the user opened on another photo', async function (assert) {
|
||||
class NostrDataStub extends Service {
|
||||
@tracked placePhotos = [makePhoto('event-1', { created_at: 2 })];
|
||||
untrustedContentCount = 0;
|
||||
showUntrustedContent = false;
|
||||
toggleShowUntrustedContent() {}
|
||||
revealPlacePhotoAuthor() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
registerDeepLink(this.owner, { NostrDataStub });
|
||||
|
||||
const nostrData = this.owner.lookup('service:nostr-data');
|
||||
const place = { title: 'Test Place', osmId: '1', osmType: 'node' };
|
||||
await renderDetails(place);
|
||||
|
||||
await click('.carousel-slide[data-event-id="event-1"]');
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.hasAttribute('data-current-event-id', 'event-1');
|
||||
|
||||
nostrData.placePhotos = [
|
||||
...nostrData.placePhotos,
|
||||
makePhoto('event-2', { created_at: 3 }),
|
||||
];
|
||||
await settled();
|
||||
|
||||
assert
|
||||
.dom('.photo-gallery-content')
|
||||
.hasAttribute(
|
||||
'data-current-event-id',
|
||||
'event-1',
|
||||
'the late linked photo does not steal focus'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1116,6 +1116,85 @@ module('Unit | Service | nostr-data | place photos', function (hooks) {
|
||||
assert.strictEqual(service.placePhotos.length, 1, 'back to trusted only');
|
||||
});
|
||||
|
||||
test('revealPlacePhotoAuthor reveals only that author and recounts', async function (assert) {
|
||||
const service = this.owner.lookup('service:nostr-data');
|
||||
const pkA = makePubkey(88);
|
||||
const pkB = makePubkey(89);
|
||||
const trustedId = makeEventId(910);
|
||||
const authorAId = makeEventId(911);
|
||||
const authorBId = makeEventId(912);
|
||||
|
||||
await service.loadPhotosForPlace({ osmId: '910', osmType: 'node' });
|
||||
|
||||
service._recordProvenance(trustedId, 'wss://nostr.kosmos.org');
|
||||
service.store.add(makePhotoEvent(pkA, 'osm:node:910', { id: trustedId }));
|
||||
service.store.add(makePhotoEvent(pkA, 'osm:node:910', { id: authorAId }));
|
||||
service.store.add(makePhotoEvent(pkB, 'osm:node:910', { id: authorBId }));
|
||||
|
||||
await wait(50);
|
||||
|
||||
assert.deepEqual(
|
||||
service.placePhotos.map((e) => e.id),
|
||||
[trustedId],
|
||||
'only trusted shown initially'
|
||||
);
|
||||
assert.strictEqual(
|
||||
service.untrustedContentCount,
|
||||
2,
|
||||
'two untrusted hidden'
|
||||
);
|
||||
|
||||
assert.true(
|
||||
service.revealPlacePhotoAuthor(authorAId),
|
||||
'returns true for a known event'
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
service.placePhotos.map((e) => e.id).sort(),
|
||||
[trustedId, authorAId].sort(),
|
||||
"author A's untrusted photo is revealed"
|
||||
);
|
||||
assert.false(
|
||||
service.placePhotos.some((e) => e.id === authorBId),
|
||||
"author B's untrusted photo stays hidden"
|
||||
);
|
||||
assert.strictEqual(service.untrustedContentCount, 1, 'count decremented');
|
||||
});
|
||||
|
||||
test('revealPlacePhotoAuthor returns false for an event that is not loaded', async function (assert) {
|
||||
const service = this.owner.lookup('service:nostr-data');
|
||||
|
||||
await service.loadPhotosForPlace({ osmId: '911', osmType: 'node' });
|
||||
|
||||
assert.false(
|
||||
service.revealPlacePhotoAuthor(makeEventId(999)),
|
||||
'returns false for an unknown event'
|
||||
);
|
||||
assert.strictEqual(service.untrustedContentCount, 0, 'nothing to reveal');
|
||||
});
|
||||
|
||||
test('revealPlacePhotoAuthor is cleared when the place changes', async function (assert) {
|
||||
const service = this.owner.lookup('service:nostr-data');
|
||||
const pk = makePubkey(90);
|
||||
const untrustedId = makeEventId(920);
|
||||
|
||||
await service.loadPhotosForPlace({ osmId: '920', osmType: 'node' });
|
||||
service.store.add(makePhotoEvent(pk, 'osm:node:920', { id: untrustedId }));
|
||||
|
||||
await wait(50);
|
||||
|
||||
service.revealPlacePhotoAuthor(untrustedId);
|
||||
assert.strictEqual(service.placePhotos.length, 1, 'author revealed');
|
||||
|
||||
await service.loadPhotosForPlace({ osmId: '921', osmType: 'node' });
|
||||
|
||||
assert.deepEqual(
|
||||
[...service.revealedUntrustedAuthors],
|
||||
[],
|
||||
'revealed authors cleared for the next place'
|
||||
);
|
||||
});
|
||||
|
||||
test('own photos are shown without provenance', async function (assert) {
|
||||
const service = this.owner.lookup('service:nostr-data');
|
||||
const myPubkey = makePubkey(95);
|
||||
|
||||
Reference in new issue
Block a user