mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
feat(vessels): key vessels by their source's stable id, and share a selected vessel
AIS Vessels are keyed by the id their live source gives, with the MMSI as an attribute: an MMSI can be shared, spoofed or reused, so two vessels with one MMSI are now two vessels. Looking a vessel up or selecting it by MMSI still finds it. A share link made while a vessel is selected opens that vessel. A UUID vessel id travels as 16 bytes in a new thing field (13). A shared thing that is not reporting now says so in a sentence per kind, with its id (ICAO, NORAD, MMSI or vessel UUID) on a second line.
This commit is contained in:
1 parent
57ff81f723
commit
cbbf55cacd
74 files changed
+2481
-586
No files matched your search
+88
-24
@@ -70,34 +70,88 @@ export function shareTrackingRestoreNotice(result) {
|
||||
: t('Shared {subject} is unavailable', { subject });
|
||||
}
|
||||
|
||||
// The not-reporting notice, one ready-made sentence per shared entity kind
|
||||
// (SHARE_VIEW_ENTITY_KINDS) for the same reason as SHARE_RESTORE_NOTICES.
|
||||
const SHARED_FIX_NOTICES = Object.freeze({
|
||||
aircraft: Object.freeze({
|
||||
lastSeen: msg(
|
||||
"The shared flight isn't reporting now — showing where it was last seen",
|
||||
),
|
||||
at: msg(
|
||||
"The shared flight isn't reporting now — showing where it was at {time}",
|
||||
),
|
||||
}),
|
||||
military_aircraft: Object.freeze({
|
||||
lastSeen: msg(
|
||||
"The shared military flight isn't reporting now — showing where it was last seen",
|
||||
),
|
||||
at: msg(
|
||||
"The shared military flight isn't reporting now — showing where it was at {time}",
|
||||
),
|
||||
}),
|
||||
vessel: Object.freeze({
|
||||
lastSeen: msg(
|
||||
"The shared vessel isn't reporting now — showing where it was last seen",
|
||||
),
|
||||
at: msg(
|
||||
"The shared vessel isn't reporting now — showing where it was at {time}",
|
||||
),
|
||||
}),
|
||||
satellite: Object.freeze({
|
||||
lastSeen: msg(
|
||||
"The shared satellite isn't reporting now — showing where it was last seen",
|
||||
),
|
||||
at: msg(
|
||||
"The shared satellite isn't reporting now — showing where it was at {time}",
|
||||
),
|
||||
}),
|
||||
});
|
||||
|
||||
// The second line names the entity by the id the link carries.
|
||||
function sharedFixDetail(entity) {
|
||||
const id = String(entity.id);
|
||||
switch (entity.kind) {
|
||||
case 'aircraft':
|
||||
case 'military_aircraft':
|
||||
// ICAO addresses read as they are written on the aircraft: upper case.
|
||||
return t('ICAO: {id}', { id: id.toUpperCase() });
|
||||
case 'satellite':
|
||||
return t('NORAD: {id}', { id });
|
||||
case 'vessel':
|
||||
return /^\d+$/.test(id)
|
||||
? t('MMSI: {id}', { id })
|
||||
: t('Vessel UUID: {id}', { id: id.toLowerCase() });
|
||||
default:
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The notice for a shared entity that is not reporting: the view shows where
|
||||
* it was when the link was made.
|
||||
* it was when the link was made. The sentence is the notice; the entity's id
|
||||
* goes on a second line under it.
|
||||
* @param {{kind: string, id: string}} entity
|
||||
* @param {number|null} observedAtMs
|
||||
* @param {number} [nowMs]
|
||||
* @returns {string}
|
||||
* @returns {{message: string, detail: string}}
|
||||
*/
|
||||
export function sharedFixNotice(entity, observedAtMs, nowMs = Date.now()) {
|
||||
// ICAO addresses read as they are written on the aircraft: upper case.
|
||||
const id =
|
||||
ENTITY_BY_KIND.get(entity.kind)?.idForm === 'hex24'
|
||||
? String(entity.id).toUpperCase()
|
||||
: String(entity.id);
|
||||
const detail = sharedFixDetail(entity);
|
||||
const notices = SHARED_FIX_NOTICES[entity.kind];
|
||||
if (!notices)
|
||||
return {
|
||||
message: t('Shared {subject} is unavailable', { subject: t('entity') }),
|
||||
detail,
|
||||
};
|
||||
if (!Number.isFinite(observedAtMs))
|
||||
return t("{id} isn't reporting now — showing where it was last seen", {
|
||||
id,
|
||||
});
|
||||
return { message: t(notices.lastSeen), detail };
|
||||
const time = formatDate(
|
||||
observedAtMs,
|
||||
nowMs - observedAtMs < DAY_MS
|
||||
? { hour: '2-digit', minute: '2-digit' }
|
||||
: { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' },
|
||||
);
|
||||
return t("{id} isn't reporting now — showing where it was at {time}", {
|
||||
id,
|
||||
time,
|
||||
});
|
||||
return { message: t(notices.at, { time }), detail };
|
||||
}
|
||||
|
||||
/** Own initial share restoration, durable layer state and restoration notices. */
|
||||
@@ -181,7 +235,7 @@ export class ShareRestoration {
|
||||
this.syncShareState();
|
||||
if (this.shareLinkManager?.rejectedShareCode)
|
||||
this._presentAfterStartupCover(
|
||||
t("This share link can't be opened"),
|
||||
{ message: t("This share link can't be opened") },
|
||||
++this._shareTrackingNoticeGeneration,
|
||||
);
|
||||
}
|
||||
@@ -411,7 +465,7 @@ export class ShareRestoration {
|
||||
this._presentAfterStartupCover(
|
||||
view.lastKnown
|
||||
? sharedFixNotice(view.entity, view.lastKnown.observedAtMs)
|
||||
: t('Shared vessel is unavailable'),
|
||||
: { message: t('Shared vessel is unavailable') },
|
||||
++this._shareTrackingNoticeGeneration,
|
||||
);
|
||||
return false;
|
||||
@@ -505,26 +559,36 @@ export class ShareRestoration {
|
||||
// A share link that knows where the entity was says so; the view is
|
||||
// already there.
|
||||
const fix = this._sharedThingFor(result)?.lastKnown;
|
||||
const message = fix
|
||||
const notice = fix
|
||||
? sharedFixNotice(
|
||||
this._initialShareState.shareView.entity,
|
||||
fix.observedAtMs,
|
||||
)
|
||||
: shareTrackingRestoreNotice(result);
|
||||
: { message: shareTrackingRestoreNotice(result) };
|
||||
if (this._resolveInitialShareRestore) {
|
||||
void this.initialRestorePromise.then(() =>
|
||||
this._presentAfterStartupCover(message, noticeGeneration),
|
||||
this._presentAfterStartupCover(notice, noticeGeneration),
|
||||
);
|
||||
return;
|
||||
}
|
||||
this._presentAfterStartupCover(message, noticeGeneration);
|
||||
this._presentAfterStartupCover(notice, noticeGeneration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a status notice once the start-up cover is gone, unless a newer
|
||||
* notice (generation) has taken its place.
|
||||
* notice (generation) has taken its place. A notice with a detail line is
|
||||
* a last-known one: the sentence over the entity's id.
|
||||
* @param {{message: string, detail?: string}} notice
|
||||
* @param {number} noticeGeneration
|
||||
*/
|
||||
_presentAfterStartupCover(message, noticeGeneration) {
|
||||
_presentAfterStartupCover(notice, noticeGeneration) {
|
||||
const show = () =>
|
||||
notice.detail
|
||||
? this.showStatus(notice.message, {
|
||||
state: 'last-known',
|
||||
detail: notice.detail,
|
||||
})
|
||||
: this.showStatus(notice.message);
|
||||
const showAfterStartupCover = () => {
|
||||
this._lifetime.frame(() => {
|
||||
if (
|
||||
@@ -540,7 +604,7 @@ export class ShareRestoration {
|
||||
!startupCover ||
|
||||
getComputedStyle(startupCover).visibility === 'hidden'
|
||||
) {
|
||||
this.showStatus(message);
|
||||
show();
|
||||
return;
|
||||
}
|
||||
let fallbackTimer = null;
|
||||
@@ -555,7 +619,7 @@ export class ShareRestoration {
|
||||
this._disposed,
|
||||
)
|
||||
)
|
||||
this.showStatus(message);
|
||||
show();
|
||||
};
|
||||
removeStartupListener = this._lifetime.listen(
|
||||
startupCover,
|
||||
|
||||
Reference in new issue
Block a user