Add an /e/:event_id route that resolves a NIP-19 event reference (nevent with relay hints, note, naddr, raw hex id, an optional nostr: prefix, or a full permalink) to the event, reads its i tag and opens the place. When the event is a place photo, focus it in the place details carousel via a ?photo= query param. Also keep the selected place's photo subscription open instead of completing on the first relay's EOSE, so photos that live on a slower relay are no longer dropped (the submission relay holds only a subset).
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
import Route from '@ember/routing/route';
|
|
import { service } from '@ember/service';
|
|
|
|
import {
|
|
parseNostrEventReference,
|
|
placeIdentifierFromEvent,
|
|
} from '../utils/nostr';
|
|
|
|
// Opens a shared NIP-19 event reference at its place. This backs the NIP-89
|
|
// app handler's `web` URL template (https://marco.earth/e/<bech32>): given a
|
|
// place photo (kind 360) or, later, a place review (kind 30360), it reads the
|
|
// event's `i` tag and redirects into the place route.
|
|
export default class EventRoute extends Route {
|
|
@service nostrData;
|
|
@service router;
|
|
@service toast;
|
|
|
|
async model(params) {
|
|
const pointer = parseNostrEventReference(params.event_id);
|
|
if (!pointer) {
|
|
return { error: 'This link is not a valid Nostr event reference.' };
|
|
}
|
|
|
|
const event = await this.nostrData.loadEventByPointer(pointer);
|
|
if (!event) {
|
|
return { error: 'Could not find this event on any relay.' };
|
|
}
|
|
|
|
const placeId = placeIdentifierFromEvent(event);
|
|
if (!placeId) {
|
|
return { error: 'This event is not linked to a place.' };
|
|
}
|
|
|
|
return { placeId, eventId: event.id };
|
|
}
|
|
|
|
redirect(model) {
|
|
if (model.placeId) {
|
|
return this.router.replaceWith('place', model.placeId, {
|
|
queryParams: { photo: model.eventId },
|
|
});
|
|
}
|
|
|
|
this.toast.show(model.error || 'Could not open this event.');
|
|
return this.router.replaceWith('index');
|
|
}
|
|
}
|