wemathallday 1.0.14 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.html +102 -11
- package/package.json +1 -1
- package/yap.html +494 -53
package/index.html
CHANGED
|
@@ -322,8 +322,15 @@
|
|
|
322
322
|
</div>
|
|
323
323
|
</div>
|
|
324
324
|
<div class="relative flex-1 bg-black">
|
|
325
|
-
<div id="player-loading" class="absolute inset-0 grid place-items-center"><span class="orb pulse-orb" style="width:22px;height:22px"></span></div>
|
|
325
|
+
<div id="player-loading" class="absolute inset-0 z-10 grid place-items-center"><span class="orb pulse-orb" style="width:22px;height:22px"></span></div>
|
|
326
326
|
<iframe id="player-frame" class="relative h-full w-full" allow="autoplay; fullscreen; gamepad; pointer-lock; camera; microphone; display-capture" allowfullscreen loading="eager"></iframe>
|
|
327
|
+
<div id="player-error" role="alert" style="display:none" class="absolute inset-0 z-20 place-items-center bg-black/85 p-6">
|
|
328
|
+
<div class="glass glass-sheet relative w-full max-w-[340px] rounded-[28px] p-6 text-center">
|
|
329
|
+
<p class="text-[17px] font-semibold">Couldn't load this app</p>
|
|
330
|
+
<p id="player-error-sub" class="mt-2 text-pretty text-[14px] leading-relaxed text-ink-300">The package couldn't be fetched. Check your connection and try again.</p>
|
|
331
|
+
<button id="player-retry" type="button" class="btn btn-primary mt-5 w-full">Retry</button>
|
|
332
|
+
</div>
|
|
333
|
+
</div>
|
|
327
334
|
</div>
|
|
328
335
|
</div>
|
|
329
336
|
</div>
|
|
@@ -561,6 +568,25 @@ const isConfigured = () =>
|
|
|
561
568
|
const SETTINGS_KEY = "mlv2_settings";
|
|
562
569
|
const isHttp = (v) => { try { const p = new URL(v).protocol; return p === "http:" || p === "https:"; } catch { return false; } };
|
|
563
570
|
const ico = (svg) => "data:image/svg+xml," + encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">${svg}</svg>`);
|
|
571
|
+
|
|
572
|
+
// Built-in CDN-distributed apps. These are fetched as HTML and written into the player iframe
|
|
573
|
+
// so frame-ancestors headers on the package host cannot block them.
|
|
574
|
+
const CDN_HTML_VERSION = "1.0.15";
|
|
575
|
+
const CDN_HTML_MIRRORS = [
|
|
576
|
+
`https://cdn.jsdelivr.net/npm/mlv2boii@${CDN_HTML_VERSION}/yap.html`,
|
|
577
|
+
`https://cdn.jsdelivr.net/npm/devpackagz@${CDN_HTML_VERSION}/yap.html`,
|
|
578
|
+
];
|
|
579
|
+
const YAP_ENTRY = {
|
|
580
|
+
id: "builtin-yap",
|
|
581
|
+
name: "Yap",
|
|
582
|
+
url: CDN_HTML_MIRRORS[0],
|
|
583
|
+
category: "Social",
|
|
584
|
+
enabled: true,
|
|
585
|
+
type: "cdn-html",
|
|
586
|
+
mirror: true,
|
|
587
|
+
sort_order: -1000,
|
|
588
|
+
icon_url: ico('<rect width="32" height="32" rx="7" fill="#071426"/><path d="M7 8.5C7 6.6 8.6 5 10.5 5h11c1.9 0 3.5 1.6 3.5 3.5v7c0 1.9-1.6 3.5-3.5 3.5h-6.3l-4.7 4v-4h-.1C8.5 19 7 17.4 7 15.5z" fill="#2F6BFF"/><circle cx="12" cy="12" r="1.4" fill="#fff"/><circle cx="16" cy="12" r="1.4" fill="#fff"/><circle cx="20" cy="12" r="1.4" fill="#fff"/>'),
|
|
589
|
+
};
|
|
564
590
|
const SIZES = {
|
|
565
591
|
compact: "grid-cols-4 sm:grid-cols-6 md:grid-cols-7 lg:grid-cols-8",
|
|
566
592
|
default: "grid-cols-3 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6",
|
|
@@ -614,7 +640,7 @@ function pop(targets, { y = 12, scale = 0.94, delay = 0, stiff = 320, damp = 24
|
|
|
614
640
|
}
|
|
615
641
|
|
|
616
642
|
/* ------------------------------- state ------------------------------- */
|
|
617
|
-
let allGames = [];
|
|
643
|
+
let allGames = [YAP_ENTRY];
|
|
618
644
|
let activeCategory = "All";
|
|
619
645
|
let searchTerm = "";
|
|
620
646
|
const BRAND = "#f01a36";
|
|
@@ -755,19 +781,24 @@ function renderGrid() {
|
|
|
755
781
|
}
|
|
756
782
|
|
|
757
783
|
/* ------------------------------ fetching ------------------------------ */
|
|
784
|
+
function withBuiltinEntries(rows) {
|
|
785
|
+
// The built-in CDN entry supersedes older database rows that framed Yap through codedex.
|
|
786
|
+
const isLegacyYap = (g) => g.name?.trim().toLowerCase() === "yap" || CDN_HTML_MIRRORS.includes(g.url);
|
|
787
|
+
return [YAP_ENTRY, ...rows.filter((g) => g.id !== YAP_ENTRY.id && !isLegacyYap(g))];
|
|
788
|
+
}
|
|
789
|
+
|
|
758
790
|
async function loadGames() {
|
|
759
791
|
if (!isConfigured()) {
|
|
760
792
|
el("setup-banner").classList.remove("hidden");
|
|
761
|
-
el("
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
el("empty-state").classList.add("flex");
|
|
793
|
+
el("count-num").textContent = allGames.length;
|
|
794
|
+
renderCategoryBar(barShown ? undefined : "intro");
|
|
795
|
+
barShown = true;
|
|
796
|
+
renderGrid();
|
|
766
797
|
return;
|
|
767
798
|
}
|
|
768
799
|
try {
|
|
769
800
|
const rows = await unwrap(sb.from(CONFIG.gamesTable).select("*").order("sort_order").limit(200));
|
|
770
|
-
allGames = rows.filter((g) => g.url && g.enabled !== false);
|
|
801
|
+
allGames = withBuiltinEntries(rows.filter((g) => g.url && g.enabled !== false));
|
|
771
802
|
const from = Number(el("count-num").textContent) || 0;
|
|
772
803
|
if (reduceMotion || from === allGames.length) el("count-num").textContent = allGames.length;
|
|
773
804
|
else animate(from, allGames.length, { duration: 1, delay: 0.3, ease: "easeOut", onUpdate: (v) => (el("count-num").textContent = Math.round(v)) });
|
|
@@ -776,7 +807,14 @@ async function loadGames() {
|
|
|
776
807
|
renderGrid();
|
|
777
808
|
} catch (err) {
|
|
778
809
|
console.error("Failed to load games:", err);
|
|
779
|
-
if (allGames.length) {
|
|
810
|
+
if (allGames.length) {
|
|
811
|
+
toast("Couldn't refresh the game list", "error");
|
|
812
|
+
el("count-num").textContent = allGames.length;
|
|
813
|
+
renderCategoryBar(barShown ? undefined : "intro");
|
|
814
|
+
barShown = true;
|
|
815
|
+
renderGrid();
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
780
818
|
el("retry").classList.remove("hidden");
|
|
781
819
|
el("skeleton-grid").classList.add("hidden");
|
|
782
820
|
el("empty-title").textContent = "Couldn't load games";
|
|
@@ -838,21 +876,71 @@ document.addEventListener("keydown", (e) => {
|
|
|
838
876
|
});
|
|
839
877
|
|
|
840
878
|
/* ------------------------------- player ------------------------------- */
|
|
879
|
+
const isCdnHtmlEntry = (game) => game?.type === "cdn-html" || game?.mirror === true;
|
|
880
|
+
let playerLoadToken = 0;
|
|
881
|
+
let currentPlayerGame = null;
|
|
882
|
+
|
|
883
|
+
function hidePlayerError() {
|
|
884
|
+
el("player-error").style.display = "none";
|
|
885
|
+
}
|
|
886
|
+
function showPlayerError(message) {
|
|
887
|
+
el("player-error-sub").textContent = message;
|
|
888
|
+
el("player-loading").style.display = "none";
|
|
889
|
+
el("player-error").style.display = "grid";
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
async function loadCdnHtmlPlayer(game, token) {
|
|
893
|
+
const frame = el("player-frame");
|
|
894
|
+
hidePlayerError();
|
|
895
|
+
el("player-loading").style.display = "grid";
|
|
896
|
+
const urls = [...new Set([game.url, ...CDN_HTML_MIRRORS])];
|
|
897
|
+
let lastError = null;
|
|
898
|
+
|
|
899
|
+
for (const url of urls) {
|
|
900
|
+
try {
|
|
901
|
+
const res = await fetch(url, { cache: "no-store" });
|
|
902
|
+
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`.trim());
|
|
903
|
+
const html = await res.text();
|
|
904
|
+
if (token !== playerLoadToken || currentPlayerGame !== game) return;
|
|
905
|
+
const doc = frame.contentDocument;
|
|
906
|
+
if (!doc) throw new Error("Player document unavailable");
|
|
907
|
+
doc.open();
|
|
908
|
+
doc.write(html);
|
|
909
|
+
doc.close();
|
|
910
|
+
el("player-loading").style.display = "none";
|
|
911
|
+
hidePlayerError();
|
|
912
|
+
return;
|
|
913
|
+
} catch (err) {
|
|
914
|
+
lastError = err;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
if (token !== playerLoadToken || currentPlayerGame !== game) return;
|
|
919
|
+
showPlayerError(`The app package couldn't be fetched from the CDN or its mirror${lastError?.message ? ` (${lastError.message})` : ""}. Check your connection and try again.`);
|
|
920
|
+
}
|
|
921
|
+
|
|
841
922
|
function openPlayer(game) {
|
|
842
923
|
if (!game) return;
|
|
924
|
+
const token = ++playerLoadToken;
|
|
925
|
+
currentPlayerGame = game;
|
|
843
926
|
beginDialog();
|
|
844
927
|
el("player-title").textContent = game.name;
|
|
845
928
|
el("player-frame").title = game.name;
|
|
846
929
|
el("player-icon").src = iconSrcFor(game) || monogramSrc(game.name);
|
|
847
930
|
el("player-newtab").href = game.url;
|
|
848
931
|
el("player-loading").style.display = "grid";
|
|
849
|
-
|
|
932
|
+
hidePlayerError();
|
|
933
|
+
if (isCdnHtmlEntry(game)) loadCdnHtmlPlayer(game, token);
|
|
934
|
+
else el("player-frame").src = game.url;
|
|
850
935
|
el("player-modal").classList.remove("hidden");
|
|
851
936
|
document.documentElement.style.overflow = "hidden";
|
|
852
937
|
pop("#player-panel", { y: 20, scale: 0.94, stiff: 260, damp: 26 });
|
|
853
938
|
focusSoon(el("player-close"));
|
|
854
939
|
}
|
|
855
940
|
function closePlayer() {
|
|
941
|
+
playerLoadToken++;
|
|
942
|
+
currentPlayerGame = null;
|
|
943
|
+
hidePlayerError();
|
|
856
944
|
fx("#player-panel", { opacity: [1, 0], scale: [1, 0.98] }, { duration: 0.18, ease: "easeIn" }).finished.then(() => {
|
|
857
945
|
el("player-modal").classList.add("hidden");
|
|
858
946
|
el("player-frame").src = "about:blank";
|
|
@@ -862,6 +950,9 @@ function closePlayer() {
|
|
|
862
950
|
}
|
|
863
951
|
el("player-close").addEventListener("click", closePlayer);
|
|
864
952
|
document.querySelector("[data-player-close]").addEventListener("click", closePlayer);
|
|
953
|
+
el("player-retry").addEventListener("click", () => {
|
|
954
|
+
if (currentPlayerGame && isCdnHtmlEntry(currentPlayerGame)) loadCdnHtmlPlayer(currentPlayerGame, ++playerLoadToken);
|
|
955
|
+
});
|
|
865
956
|
el("player-fs").addEventListener("click", () => { const f = el("player-frame"); (f.requestFullscreen || f.webkitRequestFullscreen)?.call(f); });
|
|
866
957
|
|
|
867
958
|
/* ------------------------------ admin: PIN ------------------------------ */
|
|
@@ -1925,7 +2016,7 @@ gridEl.addEventListener("pointerout", (e) => {
|
|
|
1925
2016
|
});
|
|
1926
2017
|
|
|
1927
2018
|
el("player-frame").addEventListener("load", () => {
|
|
1928
|
-
if (el("player-frame").getAttribute("src") !== "about:blank") el("player-loading").style.display = "none";
|
|
2019
|
+
if (!isCdnHtmlEntry(currentPlayerGame) && el("player-frame").getAttribute("src") !== "about:blank") el("player-loading").style.display = "none";
|
|
1929
2020
|
});
|
|
1930
2021
|
|
|
1931
2022
|
/* ------------------------------ hero motion ------------------------------ */
|
package/package.json
CHANGED
package/yap.html
CHANGED
|
@@ -539,6 +539,69 @@ body[data-view="chats"] .thread-pane::before {
|
|
|
539
539
|
.thread-state { align-self: flex-end; display: flex; align-items: center; gap: 4px; margin-top: 4px; font-size: 13px; color: var(--t3); animation: fade-in 300ms var(--ease); }
|
|
540
540
|
@keyframes fade-in { from { opacity: 0; transform: translateY(3px); } }
|
|
541
541
|
.thread-state .ico { width: 12px; height: 12px; }
|
|
542
|
+
.thread-state[data-read="true"] { color: var(--blue-hi); }
|
|
543
|
+
|
|
544
|
+
/* compact safe-markdown fragments inside chat bubbles */
|
|
545
|
+
.md-body { display: inline; }
|
|
546
|
+
.md-body strong { font-weight: 800; }
|
|
547
|
+
.md-body em { font-style: italic; }
|
|
548
|
+
.md-body s { opacity: .78; }
|
|
549
|
+
.md-body a { color: inherit; font-weight: 700; text-decoration: underline; text-decoration-color: rgb(255 255 255 / .48); text-underline-offset: 2px; }
|
|
550
|
+
.bubble:not(.me) .md-body a { color: var(--sky); text-decoration-color: rgb(60 200 255 / .42); }
|
|
551
|
+
.md-code {
|
|
552
|
+
display: inline-block; max-width: 100%; padding: 1px 6px 2px; border-radius: 8px;
|
|
553
|
+
background: rgb(0 0 0 / .42); box-shadow: inset 0 0 0 1px rgb(255 255 255 / .14);
|
|
554
|
+
-webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
|
|
555
|
+
color: #fff; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em;
|
|
556
|
+
}
|
|
557
|
+
.bubble:not(.me) .md-code { background: rgb(0 0 0 / .3); color: var(--t1); }
|
|
558
|
+
.md-spoiler {
|
|
559
|
+
display: inline-block; margin: 0; padding: 0 3px; border-radius: 6px; color: inherit; font: inherit; cursor: pointer;
|
|
560
|
+
background: rgb(255 255 255 / .08);
|
|
561
|
+
}
|
|
562
|
+
.md-spoiler > span { filter: blur(5px); opacity: .82; transition: filter 140ms var(--ease), opacity 140ms var(--ease); }
|
|
563
|
+
.md-spoiler[data-open="true"] > span { filter: none; opacity: 1; }
|
|
564
|
+
|
|
565
|
+
/* typing indicator: deliberately quieter than a real message bubble */
|
|
566
|
+
.typing-bubble {
|
|
567
|
+
align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; width: fit-content;
|
|
568
|
+
margin-top: 10px; padding: 9px 12px; border-radius: 18px 18px 18px 7px;
|
|
569
|
+
background: rgb(255 255 255 / .055); box-shadow: inset 0 1px 0 rgb(255 255 255 / .08);
|
|
570
|
+
}
|
|
571
|
+
.typing-bubble i { width: 5px; height: 5px; border-radius: 50%; background: var(--t3); animation: typing-dot 1.1s ease-in-out infinite; }
|
|
572
|
+
.typing-bubble i:nth-child(2) { animation-delay: .14s; }
|
|
573
|
+
.typing-bubble i:nth-child(3) { animation-delay: .28s; }
|
|
574
|
+
@keyframes typing-dot { 0%, 100% { transform: translateY(0); opacity: .45; } 45% { transform: translateY(-3px); opacity: 1; } }
|
|
575
|
+
.chatrow[data-typing="true"] .snippet::after {
|
|
576
|
+
content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 7px; border-radius: 50%;
|
|
577
|
+
background: var(--sky); box-shadow: 0 0 10px rgb(60 200 255 / .75); vertical-align: 1px;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/* Snapchat-style risk marker: flame plus a small hourglass, with one subdued pulse */
|
|
581
|
+
.streak[data-risk="true"] { color: var(--sky); }
|
|
582
|
+
.streak .risk-hg { width: 11px; height: 11px; margin-left: 1px; stroke-width: 2.2; }
|
|
583
|
+
.streak[data-risk="true"] .ico:first-child { animation: streak-risk-pulse 1.8s ease-in-out infinite; }
|
|
584
|
+
@keyframes streak-risk-pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.12); opacity: .72; } }
|
|
585
|
+
.streak-nudge {
|
|
586
|
+
position: relative; flex: none; margin: 12px 12px 0; padding: 12px 42px 12px 14px; overflow: hidden;
|
|
587
|
+
border-radius: 18px; color: var(--t1); background: var(--glass-bg);
|
|
588
|
+
-webkit-backdrop-filter: blur(22px) saturate(180%); backdrop-filter: blur(22px) saturate(180%);
|
|
589
|
+
box-shadow: var(--glass-shadow); font-size: 14px; line-height: 1.35;
|
|
590
|
+
}
|
|
591
|
+
.streak-nudge::before {
|
|
592
|
+
content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1px; pointer-events: none;
|
|
593
|
+
background: linear-gradient(135deg, rgb(60 200 255 / .38), rgb(255 255 255 / .05) 46%, rgb(47 107 255 / .3));
|
|
594
|
+
-webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude;
|
|
595
|
+
}
|
|
596
|
+
.streak-nudge strong { color: var(--sky); }
|
|
597
|
+
.streak-nudge .nudge-copy { display: flex; align-items: center; gap: 9px; }
|
|
598
|
+
.streak-nudge .nudge-copy > .ico { width: 18px; height: 18px; flex: none; color: var(--sky); fill: currentColor; stroke: none; animation: streak-risk-pulse 1.8s ease-in-out infinite; }
|
|
599
|
+
.streak-nudge .nudge-close { position: absolute; right: 7px; top: 7px; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; color: var(--t3); }
|
|
600
|
+
.streak-nudge .nudge-close:hover { color: var(--t1); background: rgb(255 255 255 / .08); }
|
|
601
|
+
.streak-nudge .nudge-close .ico { width: 14px; height: 14px; }
|
|
602
|
+
@media (prefers-reduced-motion: reduce) {
|
|
603
|
+
.typing-bubble i, .streak[data-risk="true"] .ico:first-child, .streak-nudge .nudge-copy > .ico { animation: none !important; }
|
|
604
|
+
}
|
|
542
605
|
|
|
543
606
|
.threadbar { flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
|
|
544
607
|
.threadbar .iconbtn { height: 44px; width: 44px; }
|
|
@@ -592,9 +655,11 @@ body[data-view="chats"] .thread-pane::before {
|
|
|
592
655
|
padding: 64px 24px 24px; background: linear-gradient(to top, rgb(0 0 0 / .72), transparent); pointer-events: none;
|
|
593
656
|
}
|
|
594
657
|
.cam-bar > * { pointer-events: auto; }
|
|
595
|
-
.cam-side { justify-self: start; }
|
|
658
|
+
.cam-side { justify-self: start; display: flex; align-items: center; gap: 8px; }
|
|
659
|
+
.cam-create { font-weight: 700; }
|
|
660
|
+
.cam-create .glyph { font-family: var(--font-display); font-size: 16px; font-weight: 800; line-height: 1; }
|
|
596
661
|
.cam-actions { display: none; }
|
|
597
|
-
.cam-stage[data-blocked="true"][data-review="false"] .cam-
|
|
662
|
+
.cam-stage[data-blocked="true"][data-review="false"] .shutter, .cam-stage[data-blocked="true"][data-review="false"] #cam-file { display: none; }
|
|
598
663
|
.cam-bar .btn.ghost { background: rgb(0 0 0 / .5); border-color: rgb(255 255 255 / .2); color: #fff; }
|
|
599
664
|
.cam-bar .btn.ghost:hover { background: rgb(0 0 0 / .7); }
|
|
600
665
|
.cam-stage .btn.primary:disabled { background: rgb(0 0 0 / .5); color: rgb(255 255 255 / .55); }
|
|
@@ -695,16 +760,26 @@ body[data-view="chats"] .thread-pane::before {
|
|
|
695
760
|
.ctxmenu-sep { height: 1px; margin: 6px 8px; background: var(--line); }
|
|
696
761
|
|
|
697
762
|
.cam-cap-row { margin-top: 12px; }
|
|
698
|
-
.filters-strip {
|
|
763
|
+
.filters-strip, .blank-strip {
|
|
699
764
|
display: none; gap: 8px; margin-top: 12px; padding: 2px 0; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity;
|
|
700
765
|
-webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
|
|
701
766
|
}
|
|
702
767
|
.cam-route:has(.cam-stage[data-live="true"]) .filters-strip { display: flex; }
|
|
703
|
-
.
|
|
768
|
+
.blank-strip:not(.hidden) { display: flex; }
|
|
769
|
+
.filters-strip::-webkit-scrollbar, .blank-strip::-webkit-scrollbar { display: none; }
|
|
704
770
|
.fchip { display: inline-flex; align-items: center; gap: 8px; flex: none; height: 38px; padding: 0 14px; border-radius: var(--r-pill); scroll-snap-align: start; font-size: 14px; font-weight: 500; color: var(--t2); transition: background-color 160ms var(--ease), color 160ms var(--ease), transform 160ms var(--spring); }
|
|
705
771
|
.fchip:hover { background: var(--s2); color: var(--t1); }
|
|
706
772
|
.fchip[data-on="true"] { background: var(--grad); color: #fff; box-shadow: inset 0 1px 0 rgb(255 255 255 / .45), inset 0 -1px 0 rgb(0 0 0 / .16); animation: pop-in 260ms var(--spring); }
|
|
707
773
|
.fswatch { width: 14px; height: 14px; flex: none; border-radius: 50%; background: var(--grad); border: 1px solid rgb(255 255 255 / .25); }
|
|
774
|
+
.blank-swatch {
|
|
775
|
+
display: inline-flex; align-items: center; gap: 8px; flex: none; height: 38px; padding: 0 13px 0 8px;
|
|
776
|
+
border-radius: var(--r-pill); scroll-snap-align: start; color: var(--t2); font-size: 13px; font-weight: 700;
|
|
777
|
+
transition: transform 120ms var(--spring), background-color 140ms, color 140ms, box-shadow 140ms;
|
|
778
|
+
}
|
|
779
|
+
.blank-swatch:hover { background: var(--s2); color: var(--t1); }
|
|
780
|
+
.blank-swatch:active { transform: scale(.94); }
|
|
781
|
+
.blank-swatch[data-on="true"] { background: rgb(47 107 255 / .28); color: #fff; box-shadow: inset 0 0 0 1px rgb(60 200 255 / .55); }
|
|
782
|
+
.blank-dot { width: 22px; height: 22px; flex: none; border-radius: 50%; background: var(--swatch); border: 1px solid rgb(255 255 255 / .42); box-shadow: inset 0 1px 0 rgb(255 255 255 / .18); }
|
|
708
783
|
|
|
709
784
|
/* --------------------------------------------------------------- profile */
|
|
710
785
|
.banner { position: relative; height: 220px; overflow: hidden; border-radius: var(--r-card); background: var(--s2); }
|
|
@@ -1092,6 +1167,7 @@ body[data-view="chats"] .thread-pane::before {
|
|
|
1092
1167
|
<symbol id="i-right" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="m9.5 5 7 7-7 7"/></symbol>
|
|
1093
1168
|
<symbol id="i-bolt" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linejoin="round"><path d="M13 3 5.5 13.5H11L10 21l7.5-10.5H12z"/></symbol>
|
|
1094
1169
|
<symbol id="i-flame" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2.5c3.2 3.4 6 6.2 6 10a6 6 0 0 1-12 0c0-2 .8-3.6 2-5 .2 1.4.9 2.4 2 2.8.7-2.6.9-5.4 2-7.8z"/></symbol>
|
|
1170
|
+
<symbol id="i-hourglass" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="M6.5 2.5h11M6.5 21.5h11M8 2.5v3.2c0 1.5.7 2.9 1.9 3.8l2.1 1.6 2.1-1.6c1.2-.9 1.9-2.3 1.9-3.8V2.5M8 21.5v-3.2c0-1.5.7-2.9 1.9-3.8l2.1-1.6 2.1 1.6c1.2.9 1.9 2.3 1.9 3.8v3.2"/></symbol>
|
|
1095
1171
|
<symbol id="i-eye" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="M2.8 12S6.3 5.8 12 5.8 21.2 12 21.2 12 17.7 18.2 12 18.2 2.8 12 2.8 12z"/><circle cx="12" cy="12" r="2.8"/></symbol>
|
|
1096
1172
|
<symbol id="i-eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"><path d="M9.9 6.1A9.6 9.6 0 0 1 12 5.8c5.7 0 9.2 6.2 9.2 6.2a15.6 15.6 0 0 1-2.6 3.3M6.4 7.6A15.7 15.7 0 0 0 2.8 12s3.5 6.2 9.2 6.2c1.4 0 2.7-.4 3.8-.9"/><path d="M9.9 9.9a2.8 2.8 0 0 0 4.2 3.7M3.5 3.5l17 17"/></symbol>
|
|
1097
1173
|
<symbol id="i-key" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round"><circle cx="8" cy="8" r="3.6"/><path d="m10.6 10.6 8 8m-3-3 2-2m-4-2 2-2"/></symbol>
|
|
@@ -1255,6 +1331,7 @@ body[data-view="chats"] .thread-pane::before {
|
|
|
1255
1331
|
<div class="cam-bar">
|
|
1256
1332
|
<div class="cam-side">
|
|
1257
1333
|
<button class="btn ghost sm" id="cam-file">Upload</button>
|
|
1334
|
+
<button class="btn ghost sm cam-create" id="cam-create" title="Blank canvas" aria-label="Create on a blank canvas" data-tip="Blank canvas"><span class="glyph" aria-hidden="true">T</span>Create</button>
|
|
1258
1335
|
</div>
|
|
1259
1336
|
<button class="shutter" id="shutter" aria-label="Take a photo" data-tip="space"></button>
|
|
1260
1337
|
<div class="cam-actions">
|
|
@@ -1269,6 +1346,7 @@ body[data-view="chats"] .thread-pane::before {
|
|
|
1269
1346
|
<input id="cam-fileinput" type="file" accept="image/*" class="hidden" />
|
|
1270
1347
|
<input id="cap-input" class="field cam-cap-row hidden" placeholder="add a caption" maxlength="120" aria-label="Caption" />
|
|
1271
1348
|
<div class="filters-strip" id="filter-row"></div>
|
|
1349
|
+
<div class="blank-strip hidden" id="blank-row" role="radiogroup" aria-label="Blank canvas background"></div>
|
|
1272
1350
|
</div>
|
|
1273
1351
|
</section>
|
|
1274
1352
|
|
|
@@ -1279,6 +1357,7 @@ body[data-view="chats"] .thread-pane::before {
|
|
|
1279
1357
|
<input id="people-search" class="field" placeholder="Find someone on yap" aria-label="Search people" />
|
|
1280
1358
|
</div>
|
|
1281
1359
|
<div id="people-results"></div>
|
|
1360
|
+
<div id="streak-nudge" class="streak-nudge hidden"></div>
|
|
1282
1361
|
<div class="chat-scroll" id="inbox-list"></div>
|
|
1283
1362
|
</div>
|
|
1284
1363
|
</section>
|
|
@@ -1493,6 +1572,25 @@ const SHOP = {"decorations":[{"id":"astronaut_helmet","name":"Astronaut Helmet",
|
|
|
1493
1572
|
const $ = (sel, root = document) => root.querySelector(sel);
|
|
1494
1573
|
const $$ = (sel, root = document) => Array.from(root.querySelectorAll(sel));
|
|
1495
1574
|
const esc = (v) => String(v ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]));
|
|
1575
|
+
|
|
1576
|
+
/* Chat markdown is deliberately tiny and safe: the user input is HTML-escaped
|
|
1577
|
+
before any marker is interpreted, so no raw HTML can ever enter the DOM. */
|
|
1578
|
+
function mdRender(text) {
|
|
1579
|
+
let s = esc(text ?? "");
|
|
1580
|
+
const stash = [];
|
|
1581
|
+
const keep = (html) => "\u0001" + (stash.push(html) - 1) + "\u0001";
|
|
1582
|
+
s = s.replace(/`([^`\n]+)`/g, (m, body) => keep(`<code class="md-code">${body}</code>`));
|
|
1583
|
+
s = s.replace(/\|\|([^|\n]+)\|\|/g, (m, body) => keep(`<button type="button" class="md-spoiler" data-open="false"><span>${body}</span></button>`));
|
|
1584
|
+
s = s.replace(/(^|[\s(])((?:https?:\/\/|www\.)[^\s]+)/g, (m, pre, url) => {
|
|
1585
|
+
const href = url.startsWith("www.") ? "https://" + url : url;
|
|
1586
|
+
return pre + keep(`<a href="${href}" target="_blank" rel="noopener">${url}</a>`);
|
|
1587
|
+
});
|
|
1588
|
+
s = s.replace(/\*\*([^*\n]+)\*\*/g, "<strong>$1</strong>");
|
|
1589
|
+
s = s.replace(/(^|[^*])\*([^*\n]+)\*/g, "$1<em>$2</em>");
|
|
1590
|
+
s = s.replace(/(^|[^_])_([^_\n]+)_/g, "$1<em>$2</em>");
|
|
1591
|
+
s = s.replace(/~~([^~\n]+)~~/g, "<s>$1</s>");
|
|
1592
|
+
return s.replace(/\u0001(\d+)\u0001/g, (m, i) => stash[Number(i)] || "");
|
|
1593
|
+
}
|
|
1496
1594
|
const TOKEN_KEY = "yap_token";
|
|
1497
1595
|
const sb = window.supabase.createClient(CONFIG.supabaseUrl, CONFIG.supabaseAnonKey);
|
|
1498
1596
|
const REDUCED = () => matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
@@ -1514,8 +1612,147 @@ const state = {
|
|
|
1514
1612
|
avatarFile: null, avatarPreview: null, bannerFile: null, bannerPreview: null, bannerImgCleared: false,
|
|
1515
1613
|
lightbox: { list: [], idx: 0 }, hasShotOnce: false,
|
|
1516
1614
|
camTexts: [], activeTextId: null,
|
|
1615
|
+
blankMode: false, blankColor: "#0A0F1E", dmTarget: null,
|
|
1517
1616
|
};
|
|
1518
1617
|
|
|
1618
|
+
/* ------------------------------------------------------------ realtime
|
|
1619
|
+
Backend tables are RLS-locked behind custom tokens, so postgres_changes and
|
|
1620
|
+
private channels are not available. A single public broadcast channel carries
|
|
1621
|
+
tiny pulse events; actual data is still loaded through the existing RPCs. */
|
|
1622
|
+
let pulseChannel = null;
|
|
1623
|
+
let pulseFeedDirty = false;
|
|
1624
|
+
let pulseStoryDirty = false;
|
|
1625
|
+
let pulseReadFrom = new Set();
|
|
1626
|
+
let pulseMsgFrom = new Set();
|
|
1627
|
+
let pulseFlushTimer = 0;
|
|
1628
|
+
let pulsePollTimer = 0;
|
|
1629
|
+
const typingState = { from: null, timer: 0, rowTimer: 0, lastSentAt: 0, live: false };
|
|
1630
|
+
|
|
1631
|
+
function startPulse() {
|
|
1632
|
+
startPulsePolling();
|
|
1633
|
+
if (pulseChannel || window.YAP_DISABLE_REALTIME) return;
|
|
1634
|
+
try {
|
|
1635
|
+
const ch = sb.channel("yap-pulse");
|
|
1636
|
+
ch.on("broadcast", { event: "pulse" }, (msg) => handlePulse(msg?.payload || {}));
|
|
1637
|
+
ch.subscribe(() => {});
|
|
1638
|
+
pulseChannel = ch;
|
|
1639
|
+
} catch { /* realtime is an enhancement; polling below remains as fallback */ }
|
|
1640
|
+
}
|
|
1641
|
+
function broadcastPulse(what, to = null, extra = {}) {
|
|
1642
|
+
const user = state.me?.username;
|
|
1643
|
+
if (!user) return;
|
|
1644
|
+
const payload = { what, user, ...extra };
|
|
1645
|
+
if (to) payload.to = to;
|
|
1646
|
+
try {
|
|
1647
|
+
startPulse();
|
|
1648
|
+
const sent = pulseChannel?.send?.({ type: "broadcast", event: "pulse", payload });
|
|
1649
|
+
if (sent?.catch) sent.catch(() => {});
|
|
1650
|
+
} catch { /* fire-and-forget by design */ }
|
|
1651
|
+
}
|
|
1652
|
+
function handlePulse(p = {}) {
|
|
1653
|
+
const me = state.me?.username;
|
|
1654
|
+
if (!p.what || !p.user || (me && p.user === me)) return;
|
|
1655
|
+
if (["typing", "read", "msg"].includes(p.what) && p.to && me && p.to !== me) return;
|
|
1656
|
+
if (p.what === "typing") { receiveTyping(p); return; }
|
|
1657
|
+
if (p.what === "read") {
|
|
1658
|
+
if (state.view === "thread" && state.peer === p.user) pulseReadFrom.add(p.user);
|
|
1659
|
+
} else if (p.what === "msg") {
|
|
1660
|
+
pulseMsgFrom.add(p.user);
|
|
1661
|
+
} else if (p.what === "post" || p.what === "reply") {
|
|
1662
|
+
pulseFeedDirty = true;
|
|
1663
|
+
} else if (p.what === "story") {
|
|
1664
|
+
pulseStoryDirty = true;
|
|
1665
|
+
} else return;
|
|
1666
|
+
schedulePulseFlush();
|
|
1667
|
+
}
|
|
1668
|
+
function schedulePulseFlush() {
|
|
1669
|
+
clearTimeout(pulseFlushTimer);
|
|
1670
|
+
pulseFlushTimer = setTimeout(flushPulse, 650);
|
|
1671
|
+
}
|
|
1672
|
+
async function flushPulse() {
|
|
1673
|
+
const feed = pulseFeedDirty, story = pulseStoryDirty;
|
|
1674
|
+
const msgs = [...pulseMsgFrom], reads = [...pulseReadFrom];
|
|
1675
|
+
pulseFeedDirty = pulseStoryDirty = false;
|
|
1676
|
+
pulseMsgFrom = new Set();
|
|
1677
|
+
pulseReadFrom = new Set();
|
|
1678
|
+
const jobs = [];
|
|
1679
|
+
const editingReply = state.view === "feed" && document.activeElement?.closest?.(".reply-form");
|
|
1680
|
+
if (feed && state.view === "feed" && !editingReply) jobs.push(loadFeed({ silent: true }));
|
|
1681
|
+
if (story && (state.view === "feed" || state.view === "profile")) jobs.push(loadStories());
|
|
1682
|
+
if (msgs.length) {
|
|
1683
|
+
if (state.view === "thread" && msgs.includes(state.peer)) {
|
|
1684
|
+
jobs.push((async () => { await refreshThreadSilent({ notifyRead: true }); await loadInbox(); })());
|
|
1685
|
+
} else {
|
|
1686
|
+
jobs.push(loadInbox());
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
if (reads.length && state.view === "thread" && reads.includes(state.peer)) jobs.push(refreshThreadSilent());
|
|
1690
|
+
await Promise.allSettled(jobs);
|
|
1691
|
+
}
|
|
1692
|
+
function startPulsePolling() {
|
|
1693
|
+
if (pulsePollTimer) return;
|
|
1694
|
+
pulsePollTimer = setInterval(() => { void silentPulseRefresh(); }, 45000);
|
|
1695
|
+
}
|
|
1696
|
+
async function silentPulseRefresh() {
|
|
1697
|
+
if (!state.token || document.hidden) return;
|
|
1698
|
+
try {
|
|
1699
|
+
if (state.view === "feed") await Promise.all([loadFeed({ silent: true }), loadStories(), loadInbox()]);
|
|
1700
|
+
else if (state.view === "chats") await loadInbox();
|
|
1701
|
+
else if (state.view === "thread" && state.peer) { await refreshThreadSilent(); await loadInbox(); }
|
|
1702
|
+
} catch { /* polling is silent */ }
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
function syncTypingRow() {
|
|
1706
|
+
const active = typingState.from;
|
|
1707
|
+
$$("[data-chat]").forEach((row) => { row.dataset.typing = String(!!active && row.dataset.chat === active); });
|
|
1708
|
+
}
|
|
1709
|
+
function hideTyping(clearRow = true) {
|
|
1710
|
+
typingState.from = null;
|
|
1711
|
+
clearTimeout(typingState.timer);
|
|
1712
|
+
$("#thread-list .typing-bubble")?.remove();
|
|
1713
|
+
if (clearRow) syncTypingRow();
|
|
1714
|
+
}
|
|
1715
|
+
function showTyping(user) {
|
|
1716
|
+
if (state.view !== "thread" || state.peer !== user) return;
|
|
1717
|
+
const inner = $("#thread-list .thread-scroll-inner");
|
|
1718
|
+
if (!inner) return;
|
|
1719
|
+
$("#thread-list .typing-bubble")?.remove();
|
|
1720
|
+
const scroller = $("#thread-list");
|
|
1721
|
+
const nearBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < 120;
|
|
1722
|
+
const el = document.createElement("div");
|
|
1723
|
+
el.className = "typing-bubble";
|
|
1724
|
+
el.setAttribute("aria-label", "typing");
|
|
1725
|
+
el.innerHTML = "<i></i><i></i><i></i>";
|
|
1726
|
+
inner.appendChild(el);
|
|
1727
|
+
if (nearBottom) scroller.scrollTop = scroller.scrollHeight;
|
|
1728
|
+
clearTimeout(typingState.timer);
|
|
1729
|
+
typingState.timer = setTimeout(() => hideTyping(), 3000);
|
|
1730
|
+
}
|
|
1731
|
+
function receiveTyping(p) {
|
|
1732
|
+
if (p.stop) { if (typingState.from === p.user) hideTyping(); return; }
|
|
1733
|
+
typingState.from = p.user;
|
|
1734
|
+
syncTypingRow();
|
|
1735
|
+
clearTimeout(typingState.rowTimer);
|
|
1736
|
+
typingState.rowTimer = setTimeout(() => hideTyping(), 3000);
|
|
1737
|
+
showTyping(p.user);
|
|
1738
|
+
}
|
|
1739
|
+
function sendTypingStop(peer = state.peer) {
|
|
1740
|
+
if (!peer || !typingState.live) return;
|
|
1741
|
+
typingState.live = false;
|
|
1742
|
+
typingState.lastSentAt = 0;
|
|
1743
|
+
broadcastPulse("typing", peer, { stop: true });
|
|
1744
|
+
}
|
|
1745
|
+
function maybeBroadcastTyping() {
|
|
1746
|
+
const input = $("#thread-input");
|
|
1747
|
+
if (!input || state.view !== "thread" || !state.peer) return;
|
|
1748
|
+
if (!input.value.trim()) { sendTypingStop(); return; }
|
|
1749
|
+
const now = Date.now();
|
|
1750
|
+
if (now - typingState.lastSentAt < 1500) return;
|
|
1751
|
+
typingState.lastSentAt = now;
|
|
1752
|
+
typingState.live = true;
|
|
1753
|
+
broadcastPulse("typing", state.peer);
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1519
1756
|
/* ---------------------------------------------------------------- toast */
|
|
1520
1757
|
const TOAST_MS = 3500;
|
|
1521
1758
|
const toastLive = new Map();
|
|
@@ -1838,6 +2075,7 @@ $("#auth-submit").addEventListener("click", submitAuth);
|
|
|
1838
2075
|
|
|
1839
2076
|
async function loadMe() {
|
|
1840
2077
|
state.me = await api("yap_me", { p_token: state.token });
|
|
2078
|
+
startPulse();
|
|
1841
2079
|
return state.me;
|
|
1842
2080
|
}
|
|
1843
2081
|
|
|
@@ -1935,10 +2173,22 @@ async function loadFeed(opts = {}) {
|
|
|
1935
2173
|
const prevIds = new Set(state.feed.map((p) => p.id));
|
|
1936
2174
|
const fresh = rows.filter((p) => !prevIds.has(p.id)).length;
|
|
1937
2175
|
feedSnapshot = new Map($$(".post", list).map((el) => [el.dataset.post, el.getBoundingClientRect()]));
|
|
2176
|
+
let anchor = null;
|
|
2177
|
+
if (opts.silent) {
|
|
2178
|
+
const visible = $$(".post", list).find((el) => el.getBoundingClientRect().bottom > 80) || $(".post", list);
|
|
2179
|
+
if (visible) anchor = { id: visible.dataset.post, top: visible.getBoundingClientRect().top };
|
|
2180
|
+
}
|
|
1938
2181
|
state.feed = rows;
|
|
1939
2182
|
renderFeed();
|
|
1940
2183
|
updateRouteChrome();
|
|
1941
2184
|
if (opts.silent && fresh && window.scrollY > 240) showNewPill(fresh);
|
|
2185
|
+
if (anchor) {
|
|
2186
|
+
const next = $(`.post[data-post="${CSS.escape(anchor.id)}"]`, list);
|
|
2187
|
+
if (next) {
|
|
2188
|
+
const delta = next.getBoundingClientRect().top - anchor.top;
|
|
2189
|
+
if (Math.abs(delta) > 1) window.scrollBy(0, delta);
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
1942
2192
|
} catch (err) {
|
|
1943
2193
|
list.innerHTML = emptyState("bubble", "couldn't load yaps", err.message);
|
|
1944
2194
|
}
|
|
@@ -2104,6 +2354,7 @@ async function toggleReplies(postId) {
|
|
|
2104
2354
|
e.currentTarget.disabled = true;
|
|
2105
2355
|
try {
|
|
2106
2356
|
await api("yap_reply", { p_token: state.token, p_post_id: postId, p_body: body });
|
|
2357
|
+
broadcastPulse("reply");
|
|
2107
2358
|
const post = state.feed.find((p) => p.id === postId);
|
|
2108
2359
|
if (post) post.replies += 1;
|
|
2109
2360
|
const counter = $(`[data-reply="${postId}"] .count span`);
|
|
@@ -2194,6 +2445,7 @@ async function sendPost() {
|
|
|
2194
2445
|
imageUrl = sb.storage.from(CONFIG.mediaBucket).getPublicUrl(path).data.publicUrl;
|
|
2195
2446
|
}
|
|
2196
2447
|
await api("yap_post", { p_token: state.token, p_body: body, p_image_url: imageUrl, p_gif_url: state.gifUrl || null });
|
|
2448
|
+
broadcastPulse("post");
|
|
2197
2449
|
box.value = "";
|
|
2198
2450
|
box.style.height = "auto";
|
|
2199
2451
|
clearAttach();
|
|
@@ -2641,8 +2893,49 @@ async function loadInbox() {
|
|
|
2641
2893
|
}
|
|
2642
2894
|
}
|
|
2643
2895
|
|
|
2896
|
+
/* At-risk rule (client-side approximation): a nonzero streak is at risk when
|
|
2897
|
+
the latest inbox activity is either over 20 hours old or did not happen on
|
|
2898
|
+
the current UTC day. This intentionally mirrors Snapchat's "act today"
|
|
2899
|
+
mental model without requiring any backend change. */
|
|
2900
|
+
function streakAtRisk(c) {
|
|
2901
|
+
if (!c || !c.streak) return false;
|
|
2902
|
+
const at = Date.parse(c.last_at || "");
|
|
2903
|
+
if (!at) return true;
|
|
2904
|
+
const age = Date.now() - at;
|
|
2905
|
+
const utcDay = new Date(at).toISOString().slice(0, 10);
|
|
2906
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
2907
|
+
return age > 20 * 3600 * 1000 || utcDay !== today;
|
|
2908
|
+
}
|
|
2909
|
+
function streakHtml(count, risk = false) {
|
|
2910
|
+
return `<span class="streak" data-hot="${count >= 3}" data-risk="${risk}"><svg class="ico"><use href="#i-flame"/></svg>${count}${risk ? '<svg class="ico risk-hg"><use href="#i-hourglass"/></svg>' : ""}</span>`;
|
|
2911
|
+
}
|
|
2912
|
+
let nudgeDismissedKey = "";
|
|
2913
|
+
function renderStreakNudge() {
|
|
2914
|
+
const box = $("#streak-nudge");
|
|
2915
|
+
if (!box) return;
|
|
2916
|
+
const rows = state.inbox.filter((c) => !c.is_support && streakAtRisk(c)).sort((a, b) => (b.streak || 0) - (a.streak || 0));
|
|
2917
|
+
const top = rows[0];
|
|
2918
|
+
const key = top ? `${top.username}|${top.streak}|${new Date().toISOString().slice(0, 10)}` : "";
|
|
2919
|
+
if (!top || nudgeDismissedKey === key) {
|
|
2920
|
+
box.classList.add("hidden");
|
|
2921
|
+
box.innerHTML = "";
|
|
2922
|
+
return;
|
|
2923
|
+
}
|
|
2924
|
+
const name = top.display_name || top.username;
|
|
2925
|
+
box.innerHTML = `<div class="nudge-copy"><svg class="ico"><use href="#i-flame"/></svg><span>Your <strong>${top.streak}-day</strong> streak with <strong>${esc(name)}</strong> is at risk — send a snap</span></div>
|
|
2926
|
+
<button class="nudge-close" type="button" aria-label="Dismiss streak reminder"><svg class="ico"><use href="#i-x"/></svg></button>`;
|
|
2927
|
+
box.classList.remove("hidden");
|
|
2928
|
+
box.querySelector(".nudge-close").addEventListener("click", (e) => {
|
|
2929
|
+
e.stopPropagation();
|
|
2930
|
+
nudgeDismissedKey = key;
|
|
2931
|
+
box.classList.add("hidden");
|
|
2932
|
+
});
|
|
2933
|
+
box.querySelector(".nudge-copy").addEventListener("click", () => openThread(top.username));
|
|
2934
|
+
}
|
|
2935
|
+
|
|
2644
2936
|
function renderInbox() {
|
|
2645
2937
|
const list = $("#inbox-list");
|
|
2938
|
+
renderStreakNudge();
|
|
2646
2939
|
if (!state.inbox.length) {
|
|
2647
2940
|
list.innerHTML = emptyState("chat", "no conversations", "Find someone above and send the first yap. Streaks start with one.", "Find people", "inbox-cta");
|
|
2648
2941
|
$("#inbox-cta").addEventListener("click", () => $("#people-search").focus());
|
|
@@ -2655,7 +2948,7 @@ function renderInbox() {
|
|
|
2655
2948
|
<div class="name-row">
|
|
2656
2949
|
<span class="name">${esc(c.display_name || c.username)}</span>
|
|
2657
2950
|
${c.is_support ? '<span class="badge support"><svg class="ico"><use href="#i-check"/></svg>support</span>' : ""}
|
|
2658
|
-
${!c.is_support && c.streak ?
|
|
2951
|
+
${!c.is_support && c.streak ? streakHtml(c.streak, streakAtRisk(c)) : ""}
|
|
2659
2952
|
</div>
|
|
2660
2953
|
<div class="snippet">${c.last_from_me ? "You: " : ""}${esc(c.last || "say hi")}</div>
|
|
2661
2954
|
</div>
|
|
@@ -2666,6 +2959,7 @@ function renderInbox() {
|
|
|
2666
2959
|
</button>`).join("");
|
|
2667
2960
|
$$("[data-chat]", list).forEach((b) => b.addEventListener("click", () => openThread(b.dataset.chat)));
|
|
2668
2961
|
wireSpotlights(list);
|
|
2962
|
+
syncTypingRow();
|
|
2669
2963
|
const unread = state.inbox.reduce((n, c) => n + (c.unread || 0), 0);
|
|
2670
2964
|
["#rail-badge", "#tab-badge"].forEach((sel) => {
|
|
2671
2965
|
const b = $(sel);
|
|
@@ -2706,6 +3000,8 @@ $("#people-search").addEventListener("input", (e) => {
|
|
|
2706
3000
|
|
|
2707
3001
|
/* ----------------------------------------------------------------- thread */
|
|
2708
3002
|
async function openThread(username) {
|
|
3003
|
+
sendTypingStop();
|
|
3004
|
+
hideTyping();
|
|
2709
3005
|
state.peer = username;
|
|
2710
3006
|
go("thread");
|
|
2711
3007
|
$$("[data-chat]").forEach((b) => b.dataset.active = String(b.dataset.chat === username));
|
|
@@ -2716,13 +3012,32 @@ async function openThread(username) {
|
|
|
2716
3012
|
const t = await api("yap_thread", { p_token: state.token, p_peer: username });
|
|
2717
3013
|
state.thread = t;
|
|
2718
3014
|
renderThread();
|
|
2719
|
-
loadInbox();
|
|
3015
|
+
await loadInbox();
|
|
3016
|
+
broadcastPulse("read", username);
|
|
2720
3017
|
} catch (err) {
|
|
2721
3018
|
$("#thread-list").innerHTML = emptyState("chat", "couldn't open that", err.message);
|
|
2722
3019
|
}
|
|
2723
3020
|
}
|
|
2724
3021
|
|
|
2725
|
-
function
|
|
3022
|
+
async function refreshThreadSilent(options = {}) {
|
|
3023
|
+
if (!state.peer) return;
|
|
3024
|
+
const input = $("#thread-input");
|
|
3025
|
+
const draft = input.value;
|
|
3026
|
+
const scroller = $("#thread-list");
|
|
3027
|
+
const oldTop = scroller.scrollTop;
|
|
3028
|
+
const bottomDist = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight;
|
|
3029
|
+
try {
|
|
3030
|
+
const t = await api("yap_thread", { p_token: state.token, p_peer: state.peer });
|
|
3031
|
+
if (state.view !== "thread" || !state.peer) return;
|
|
3032
|
+
state.thread = t;
|
|
3033
|
+
renderThread({ scrollTop: bottomDist < 120 ? null : oldTop });
|
|
3034
|
+
if (options.notifyRead) broadcastPulse("read", state.peer);
|
|
3035
|
+
input.value = draft;
|
|
3036
|
+
syncThreadBar();
|
|
3037
|
+
} catch { /* silent realtime refresh */ }
|
|
3038
|
+
}
|
|
3039
|
+
|
|
3040
|
+
function renderThread(opts = {}) {
|
|
2726
3041
|
const t = state.thread;
|
|
2727
3042
|
const peer = t.peer || { username: state.peer, display_name: state.peer };
|
|
2728
3043
|
$("#thread-head").innerHTML = `${avatarHtml(peer, "sm")}
|
|
@@ -2733,8 +3048,13 @@ function renderThread() {
|
|
|
2733
3048
|
</div>
|
|
2734
3049
|
<div class="handle">@${esc(peer.username)}</div>
|
|
2735
3050
|
</div>`;
|
|
3051
|
+
const inboxRow = state.inbox.find((c) => c.username === peer.username);
|
|
3052
|
+
const risk = streakAtRisk({
|
|
3053
|
+
streak: t.streak,
|
|
3054
|
+
last_at: inboxRow?.last_at || (t.messages || []).at(-1)?.created_at,
|
|
3055
|
+
});
|
|
2736
3056
|
$("#thread-streak").innerHTML = t.streak
|
|
2737
|
-
? `<svg class="ico"><use href="#i-flame"/></svg>${t.streak} day${t.streak === 1 ? "" : "s"}
|
|
3057
|
+
? `<span class="streak" data-risk="${risk}" style="display:inline-flex;align-items:center;gap:4px"><svg class="ico"><use href="#i-flame"/></svg>${t.streak} day${t.streak === 1 ? "" : "s"}${risk ? '<svg class="ico risk-hg"><use href="#i-hourglass"/></svg>' : ""}</span>`
|
|
2738
3058
|
: "";
|
|
2739
3059
|
|
|
2740
3060
|
const rows = t.messages || [];
|
|
@@ -2751,29 +3071,34 @@ function renderThread() {
|
|
|
2751
3071
|
const samePrev = prev && prev.from_me === m.from_me && dayKey(prev.created_at) === day;
|
|
2752
3072
|
const sameNext = next && next.from_me === m.from_me && dayKey(next.created_at) === day;
|
|
2753
3073
|
const group = !samePrev && !sameNext ? "solo" : samePrev && sameNext ? "mid" : samePrev ? "last" : "first";
|
|
2754
|
-
|
|
3074
|
+
const lastOwn = rows.map((x) => !!x.from_me).lastIndexOf(true);
|
|
3075
|
+
out.push(bubbleHtml(m, group, i === lastOwn));
|
|
2755
3076
|
});
|
|
2756
3077
|
$("#thread-list").innerHTML = `<div class="thread-scroll-inner">${out.join("")}</div>`;
|
|
2757
3078
|
$$("#thread-list [data-open-dm]").forEach((b) => b.addEventListener("click", () => viewDm(b.dataset.openDm)));
|
|
3079
|
+
$$("#thread-list .md-spoiler").forEach((b) => b.addEventListener("click", (e) => {
|
|
3080
|
+
e.stopPropagation();
|
|
3081
|
+
b.dataset.open = String(b.dataset.open !== "true");
|
|
3082
|
+
}));
|
|
2758
3083
|
const scroller = $("#thread-list");
|
|
2759
|
-
scroller.scrollTop = scroller.scrollHeight;
|
|
3084
|
+
scroller.scrollTop = opts.scrollTop == null ? scroller.scrollHeight : Math.min(opts.scrollTop, scroller.scrollHeight);
|
|
2760
3085
|
}
|
|
2761
3086
|
|
|
2762
3087
|
function bubbleHtml(m, group, isLast) {
|
|
2763
3088
|
const when = `<span class="when">${esc(fmtTime(m.created_at))}</span>`;
|
|
3089
|
+
const receipt = isLast && m.from_me
|
|
3090
|
+
? `<div class="thread-state" data-read="${!!m.viewed}">${m.viewed ? "Read" : "Delivered"}<svg class="ico" style="width:12px;height:12px"><use href="#i-${m.viewed ? "eye" : "check"}"/></svg></div>`
|
|
3091
|
+
: "";
|
|
2764
3092
|
if (m.kind === "photo") {
|
|
2765
|
-
if (m.from_me) return `<div class="bubble me photo" data-group="${group}"><svg class="ico" style="width:16px;height:16px"><use href="#i-cam"/></svg>Photo yap${when}</div
|
|
3093
|
+
if (m.from_me) return `<div class="bubble me photo" data-group="${group}"><svg class="ico" style="width:16px;height:16px"><use href="#i-cam"/></svg>Photo yap${when}</div>${receipt}`;
|
|
2766
3094
|
if (m.locked) return `<button class="bubble locked" data-open-dm="${esc(m.id)}" data-group="${group}">
|
|
2767
3095
|
<span class="locked-row"><svg class="ico"><use href="#i-cam"/></svg>Tap to view photo</span>
|
|
2768
3096
|
<span class="locked-sub">disappears once opened</span>${when}</button>`;
|
|
2769
3097
|
return `<div class="bubble photo" data-group="${group}"><svg class="ico" style="width:16px;height:16px"><use href="#i-cam"/></svg>Photo yap${when}</div>`;
|
|
2770
3098
|
}
|
|
2771
|
-
const body = `<span>${
|
|
3099
|
+
const body = `<span class="md-body">${mdRender(m.body || "")}</span>${when}`;
|
|
2772
3100
|
if (!m.from_me) return `<div class="bubble" data-group="${group}">${body}</div>`;
|
|
2773
|
-
|
|
2774
|
-
? `<div class="thread-state">${m.viewed ? "opened" : "sent"}<svg class="ico" style="width:12px;height:12px"><use href="#i-${m.viewed ? "check" : "send"}"/></svg></div>`
|
|
2775
|
-
: "";
|
|
2776
|
-
return `<div class="bubble me" data-group="${group}">${body}</div>${stateLine}`;
|
|
3101
|
+
return `<div class="bubble me" data-group="${group}">${body}</div>${receipt}`;
|
|
2777
3102
|
}
|
|
2778
3103
|
|
|
2779
3104
|
async function viewDm(id) {
|
|
@@ -2797,7 +3122,7 @@ function syncThreadBar() {
|
|
|
2797
3122
|
input.style.height = "auto";
|
|
2798
3123
|
input.style.height = Math.min(input.scrollHeight, 160) + "px";
|
|
2799
3124
|
}
|
|
2800
|
-
$("#thread-input").addEventListener("input", syncThreadBar);
|
|
3125
|
+
$("#thread-input").addEventListener("input", () => { syncThreadBar(); maybeBroadcastTyping(); });
|
|
2801
3126
|
$("#thread-input").addEventListener("keydown", (e) => {
|
|
2802
3127
|
if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); sendThread(); }
|
|
2803
3128
|
});
|
|
@@ -2807,6 +3132,7 @@ async function sendThread() {
|
|
|
2807
3132
|
const body = input.value.trim();
|
|
2808
3133
|
if (!body) return;
|
|
2809
3134
|
input.value = "";
|
|
3135
|
+
sendTypingStop();
|
|
2810
3136
|
syncThreadBar();
|
|
2811
3137
|
const inner = $("#thread-list .thread-scroll-inner");
|
|
2812
3138
|
if (inner) {
|
|
@@ -2814,7 +3140,7 @@ async function sendThread() {
|
|
|
2814
3140
|
el.className = "bubble me";
|
|
2815
3141
|
el.dataset.group = "solo";
|
|
2816
3142
|
el.style.opacity = "0.6";
|
|
2817
|
-
el.innerHTML = `<span>${
|
|
3143
|
+
el.innerHTML = `<span class="md-body">${mdRender(body)}</span>`;
|
|
2818
3144
|
inner.appendChild(el);
|
|
2819
3145
|
if (!REDUCED()) {
|
|
2820
3146
|
el.animate([{ opacity: 0, transform: "translateY(10px) scale(.8)" }, { opacity: 0.6, transform: "none" }], { duration: 320, easing: "cubic-bezier(.34,1.56,.64,1)" });
|
|
@@ -2826,18 +3152,21 @@ async function sendThread() {
|
|
|
2826
3152
|
}
|
|
2827
3153
|
try {
|
|
2828
3154
|
await api("yap_send_yap", { p_token: state.token, p_to: state.peer, p_kind: "text", p_body: body });
|
|
2829
|
-
|
|
3155
|
+
broadcastPulse("msg", state.peer);
|
|
3156
|
+
await refreshThreadSilent();
|
|
3157
|
+
await loadInbox();
|
|
2830
3158
|
} catch (err) {
|
|
2831
3159
|
toast(err.message, "err");
|
|
2832
3160
|
input.value = body;
|
|
2833
3161
|
syncThreadBar();
|
|
2834
|
-
await
|
|
3162
|
+
await refreshThreadSilent();
|
|
2835
3163
|
}
|
|
2836
3164
|
}
|
|
2837
3165
|
$("#thread-send").addEventListener("click", sendThread);
|
|
2838
3166
|
$("#thread-back").addEventListener("click", () => { go("chats"); loadInbox(); });
|
|
2839
3167
|
|
|
2840
3168
|
const threadPhoto = document.createElement("input");
|
|
3169
|
+
threadPhoto.id = "thread-photo-input";
|
|
2841
3170
|
threadPhoto.type = "file";
|
|
2842
3171
|
threadPhoto.accept = "image/*";
|
|
2843
3172
|
threadPhoto.hidden = true;
|
|
@@ -2848,21 +3177,15 @@ threadPhoto.addEventListener("change", async (e) => {
|
|
|
2848
3177
|
const file = e.target.files[0];
|
|
2849
3178
|
e.target.value = "";
|
|
2850
3179
|
if (!file) return;
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
p_token: state.token, p_to: state.peer, p_kind: "photo",
|
|
2861
|
-
p_image_data: canvas.toDataURL("image/jpeg", 0.7), p_filter: "none",
|
|
2862
|
-
});
|
|
2863
|
-
toast("Photo yap sent", "ok");
|
|
2864
|
-
await openThread(state.peer);
|
|
2865
|
-
} catch (err) { toast(err.message, "err"); }
|
|
3180
|
+
/* Photo DMs use the exact same review/edit pipeline as camera captures. */
|
|
3181
|
+
state.dmTarget = state.peer;
|
|
3182
|
+
if (await acceptImage(file)) {
|
|
3183
|
+
go("camera");
|
|
3184
|
+
syncCamSendTarget();
|
|
3185
|
+
toast("Edit your photo yap");
|
|
3186
|
+
} else {
|
|
3187
|
+
state.dmTarget = null;
|
|
3188
|
+
}
|
|
2866
3189
|
});
|
|
2867
3190
|
|
|
2868
3191
|
</script>
|
|
@@ -2908,13 +3231,85 @@ function setFilter(id, focus = false) {
|
|
|
2908
3231
|
applyPreviewFilter();
|
|
2909
3232
|
}
|
|
2910
3233
|
const filterCss = () => (FILTERS.find((f) => f.id === state.filter) || FILTERS[0]).css;
|
|
3234
|
+
const previewFilterCss = () => (state.blankMode && state.camReview) ? "none" : filterCss();
|
|
2911
3235
|
const applyPreviewFilter = () => {
|
|
2912
3236
|
const v = $("#cam-video");
|
|
2913
3237
|
const s = $("#cam-shot");
|
|
2914
|
-
|
|
2915
|
-
if (
|
|
3238
|
+
const css = previewFilterCss();
|
|
3239
|
+
if (v) v.style.filter = css;
|
|
3240
|
+
if (s) s.style.filter = css;
|
|
2916
3241
|
};
|
|
2917
3242
|
|
|
3243
|
+
/* Blank-canvas mode: the solid color is generated as the base image, then the
|
|
3244
|
+
ordinary capture/review/posting pipeline carries it everywhere unchanged. */
|
|
3245
|
+
const BLANK_COLORS = [
|
|
3246
|
+
{ id: "black", label: "Black", color: "#000000" },
|
|
3247
|
+
{ id: "white", label: "White", color: "#FFFFFF" },
|
|
3248
|
+
{ id: "navy", label: "Navy", color: "#0A0F1E" },
|
|
3249
|
+
{ id: "blue", label: "Blue", color: "#2F6BFF" },
|
|
3250
|
+
{ id: "sky", label: "Sky", color: "#3CC8FF" },
|
|
3251
|
+
{ id: "pale", label: "Pale", color: "#8FA8FF" },
|
|
3252
|
+
{ id: "grey", label: "Grey", color: "#6E6E73" },
|
|
3253
|
+
];
|
|
3254
|
+
const blankColorRow = () => BLANK_COLORS.find((c) => c.color.toUpperCase() === String(state.blankColor || "").toUpperCase()) || BLANK_COLORS[2];
|
|
3255
|
+
function makeBlankCanvas(color) {
|
|
3256
|
+
const canvas = document.createElement("canvas");
|
|
3257
|
+
canvas.width = 1080;
|
|
3258
|
+
canvas.height = 1440;
|
|
3259
|
+
const ctx = canvas.getContext("2d");
|
|
3260
|
+
ctx.fillStyle = color;
|
|
3261
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
3262
|
+
return canvas;
|
|
3263
|
+
}
|
|
3264
|
+
function renderBlankSwatches() {
|
|
3265
|
+
const row = $("#blank-row");
|
|
3266
|
+
if (!row || row.dataset.ready) return;
|
|
3267
|
+
row.dataset.ready = "1";
|
|
3268
|
+
row.innerHTML = BLANK_COLORS.map((c) => `
|
|
3269
|
+
<button class="blank-swatch" type="button" data-bg="${c.color}" role="radio" aria-checked="false" aria-label="${esc(c.label)} background">
|
|
3270
|
+
<span class="blank-dot" style="--swatch:${c.color}"></span>${esc(c.label)}
|
|
3271
|
+
</button>`).join("");
|
|
3272
|
+
row.querySelectorAll("[data-bg]").forEach((b) => b.addEventListener("click", () => updateBlankBase(b.dataset.bg)));
|
|
3273
|
+
}
|
|
3274
|
+
function syncBlankUI() {
|
|
3275
|
+
renderBlankSwatches();
|
|
3276
|
+
const active = !!(state.blankMode && state.camReview);
|
|
3277
|
+
$("#blank-row")?.classList.toggle("hidden", !active);
|
|
3278
|
+
$("#filter-row")?.classList.toggle("hidden", active);
|
|
3279
|
+
$("#cam-box")?.setAttribute("data-blank", String(active));
|
|
3280
|
+
const current = blankColorRow().color.toUpperCase();
|
|
3281
|
+
$$("#blank-row [data-bg]").forEach((b) => {
|
|
3282
|
+
const on = b.dataset.bg.toUpperCase() === current;
|
|
3283
|
+
b.dataset.on = String(on);
|
|
3284
|
+
b.setAttribute("aria-checked", String(on));
|
|
3285
|
+
});
|
|
3286
|
+
}
|
|
3287
|
+
function writeShot(canvas, type = "image/jpeg") {
|
|
3288
|
+
const quality = type === "image/jpeg" ? .72 : undefined;
|
|
3289
|
+
state.shot = type === "image/png" ? canvas.toDataURL("image/png") : canvas.toDataURL(type, quality);
|
|
3290
|
+
state.shotBlob = null;
|
|
3291
|
+
const dataUrl = state.shot;
|
|
3292
|
+
canvas.toBlob((blob) => { if (state.shot === dataUrl) state.shotBlob = blob; }, type, quality);
|
|
3293
|
+
$("#cam-shot").src = state.shot;
|
|
3294
|
+
}
|
|
3295
|
+
function updateBlankBase(color) {
|
|
3296
|
+
if (!state.blankMode || !state.camReview) return;
|
|
3297
|
+
const next = BLANK_COLORS.find((c) => c.color.toUpperCase() === String(color || "").toUpperCase());
|
|
3298
|
+
state.blankColor = (next || blankColorRow()).color;
|
|
3299
|
+
writeShot(makeBlankCanvas(state.blankColor), "image/png");
|
|
3300
|
+
applyPreviewFilter();
|
|
3301
|
+
syncBlankUI();
|
|
3302
|
+
}
|
|
3303
|
+
function enterBlankMode() {
|
|
3304
|
+
setFilter("none");
|
|
3305
|
+
state.blankMode = true;
|
|
3306
|
+
state.blankColor = blankColorRow().color;
|
|
3307
|
+
enterReview(makeBlankCanvas(state.blankColor), "image/png");
|
|
3308
|
+
state.blankMode = true;
|
|
3309
|
+
applyPreviewFilter();
|
|
3310
|
+
syncBlankUI();
|
|
3311
|
+
}
|
|
3312
|
+
|
|
2918
3313
|
function showCamBlocked(err) {
|
|
2919
3314
|
state.camError = err;
|
|
2920
3315
|
const box = $("#cam-box");
|
|
@@ -3158,6 +3553,13 @@ document.addEventListener("keydown", (e) => {
|
|
|
3158
3553
|
});
|
|
3159
3554
|
window.addEventListener("resize", () => { if (state.camReview) renderCamTexts(); sizeStoryTexts(); });
|
|
3160
3555
|
|
|
3556
|
+
function syncCamSendTarget() {
|
|
3557
|
+
const btn = $("#cam-send");
|
|
3558
|
+
if (!btn) return;
|
|
3559
|
+
btn.textContent = state.dmTarget ? "Send yap" : "Send to…";
|
|
3560
|
+
btn.title = state.dmTarget ? `Send to @${state.dmTarget}` : "";
|
|
3561
|
+
}
|
|
3562
|
+
|
|
3161
3563
|
function setReview(on) {
|
|
3162
3564
|
state.camReview = on;
|
|
3163
3565
|
$("#cam-box").dataset.review = String(on);
|
|
@@ -3173,6 +3575,8 @@ function setReview(on) {
|
|
|
3173
3575
|
$("#cam-box").dataset.live = "true";
|
|
3174
3576
|
}
|
|
3175
3577
|
renderCamTexts();
|
|
3578
|
+
syncCamSendTarget();
|
|
3579
|
+
syncBlankUI();
|
|
3176
3580
|
}
|
|
3177
3581
|
|
|
3178
3582
|
function clearCaption() {
|
|
@@ -3185,11 +3589,8 @@ function clearCamTexts() {
|
|
|
3185
3589
|
renderCamTexts();
|
|
3186
3590
|
}
|
|
3187
3591
|
|
|
3188
|
-
function enterReview(canvas) {
|
|
3189
|
-
|
|
3190
|
-
state.shotBlob = null;
|
|
3191
|
-
canvas.toBlob((blob) => { state.shotBlob = blob; }, "image/jpeg", 0.72);
|
|
3192
|
-
$("#cam-shot").src = state.shot;
|
|
3592
|
+
function enterReview(canvas, type = "image/jpeg") {
|
|
3593
|
+
writeShot(canvas, type);
|
|
3193
3594
|
state.hasShotOnce = true;
|
|
3194
3595
|
clearCaption();
|
|
3195
3596
|
clearCamTexts();
|
|
@@ -3206,12 +3607,15 @@ function takeShot() {
|
|
|
3206
3607
|
return;
|
|
3207
3608
|
}
|
|
3208
3609
|
flash();
|
|
3610
|
+
state.blankMode = false;
|
|
3209
3611
|
enterReview(drawShot(video, 1080, 1440));
|
|
3210
3612
|
}
|
|
3211
3613
|
|
|
3212
3614
|
function retake() {
|
|
3213
3615
|
state.shot = null;
|
|
3214
3616
|
state.shotBlob = null;
|
|
3617
|
+
state.blankMode = false;
|
|
3618
|
+
state.dmTarget = null;
|
|
3215
3619
|
$("#cam-shot").src = "";
|
|
3216
3620
|
clearCamTexts();
|
|
3217
3621
|
setReview(false);
|
|
@@ -3221,18 +3625,21 @@ function retake() {
|
|
|
3221
3625
|
}
|
|
3222
3626
|
|
|
3223
3627
|
async function acceptImage(file) {
|
|
3224
|
-
if (!file) return;
|
|
3225
|
-
if (!file.type.startsWith("image/"))
|
|
3628
|
+
if (!file) return false;
|
|
3629
|
+
if (!file.type.startsWith("image/")) { toast("That's not an image", "err"); return false; }
|
|
3226
3630
|
try {
|
|
3227
3631
|
const bitmap = await createImageBitmap(file);
|
|
3632
|
+
state.blankMode = false;
|
|
3228
3633
|
enterReview(drawShot(bitmap, 1080, 1440));
|
|
3229
|
-
|
|
3634
|
+
return true;
|
|
3635
|
+
} catch (err) { toast("Couldn't read that image: " + err.message, "err"); return false; }
|
|
3230
3636
|
}
|
|
3231
3637
|
|
|
3232
3638
|
$("#shutter").addEventListener("click", takeShot);
|
|
3233
3639
|
$("#cam-retake").addEventListener("click", retake);
|
|
3234
|
-
$("#cam-
|
|
3235
|
-
$("#cam-
|
|
3640
|
+
$("#cam-create").addEventListener("click", enterBlankMode);
|
|
3641
|
+
$("#cam-file").addEventListener("click", () => { state.dmTarget = null; $("#cam-fileinput").click(); });
|
|
3642
|
+
$("#cam-empty-upload").addEventListener("click", () => { state.dmTarget = null; $("#cam-fileinput").click(); });
|
|
3236
3643
|
$("#cam-empty-retry").addEventListener("click", () => {
|
|
3237
3644
|
state.camError = null;
|
|
3238
3645
|
$("#cam-empty").classList.add("hidden");
|
|
@@ -3242,6 +3649,7 @@ $("#cam-empty-retry").addEventListener("click", () => {
|
|
|
3242
3649
|
$("#cam-fileinput").addEventListener("change", async (e) => {
|
|
3243
3650
|
const file = e.target.files[0];
|
|
3244
3651
|
e.target.value = "";
|
|
3652
|
+
state.dmTarget = null;
|
|
3245
3653
|
await acceptImage(file);
|
|
3246
3654
|
});
|
|
3247
3655
|
$("#cap-input").addEventListener("input", (e) => { $("#cam-cap").textContent = e.target.value; });
|
|
@@ -3380,6 +3788,7 @@ async function postStoryDirect() {
|
|
|
3380
3788
|
const caption = $("#cap-input").value.trim();
|
|
3381
3789
|
const url = await uploadBlob(await getShotBlob());
|
|
3382
3790
|
await api("yap_story_add", { p_token: state.token, p_image_url: url, p_caption: caption, p_filter: state.filter, p_meta: storyMeta() });
|
|
3791
|
+
broadcastPulse("story");
|
|
3383
3792
|
toast("Story added", "ok");
|
|
3384
3793
|
await loadStories();
|
|
3385
3794
|
clearCaption();
|
|
@@ -3399,6 +3808,29 @@ $("#cam-story").addEventListener("click", postStoryDirect);
|
|
|
3399
3808
|
$("#cam-send").addEventListener("click", () => {
|
|
3400
3809
|
if (!state.shot) return;
|
|
3401
3810
|
const caption = $("#cap-input").value.trim();
|
|
3811
|
+
if (state.dmTarget) {
|
|
3812
|
+
const target = state.dmTarget;
|
|
3813
|
+
const btn = $("#cam-send");
|
|
3814
|
+
btn.disabled = true;
|
|
3815
|
+
const label = btn.innerHTML;
|
|
3816
|
+
btn.innerHTML = '<span class="spinner"></span>';
|
|
3817
|
+
(async () => {
|
|
3818
|
+
try {
|
|
3819
|
+
await sendPhotoYap(target, caption);
|
|
3820
|
+
toast("Photo yap sent", "ok");
|
|
3821
|
+
clearCaption();
|
|
3822
|
+
retake();
|
|
3823
|
+
await openThread(target);
|
|
3824
|
+
} catch (err) {
|
|
3825
|
+
toast(err.message, "err");
|
|
3826
|
+
} finally {
|
|
3827
|
+
btn.innerHTML = label;
|
|
3828
|
+
syncCamSendTarget();
|
|
3829
|
+
btn.disabled = !state.shot;
|
|
3830
|
+
}
|
|
3831
|
+
})();
|
|
3832
|
+
return;
|
|
3833
|
+
}
|
|
3402
3834
|
const sheet = openSheet(`<h3>Send your yap</h3>
|
|
3403
3835
|
<p class="small" style="color:var(--tx-2);margin:6px 0 16px">It disappears after 24 hours.</p>
|
|
3404
3836
|
<div class="sheet-actions">
|
|
@@ -3413,6 +3845,7 @@ $("#cam-send").addEventListener("click", () => {
|
|
|
3413
3845
|
b.innerHTML = '<span class="spinner"></span>';
|
|
3414
3846
|
const url = await uploadBlob(await compositeShotBlob());
|
|
3415
3847
|
await api("yap_post", { p_token: state.token, p_body: caption, p_image_url: url });
|
|
3848
|
+
broadcastPulse("post");
|
|
3416
3849
|
toast("Posted to the feed", "ok");
|
|
3417
3850
|
await loadFeed();
|
|
3418
3851
|
closeSheet();
|
|
@@ -3437,6 +3870,15 @@ async function uploadBlob(blob) {
|
|
|
3437
3870
|
return sb.storage.from(CONFIG.mediaBucket).getPublicUrl(path).data.publicUrl;
|
|
3438
3871
|
}
|
|
3439
3872
|
|
|
3873
|
+
async function sendPhotoYap(username, caption) {
|
|
3874
|
+
const imageData = await compositeShotDataUrl();
|
|
3875
|
+
await api("yap_send_yap", {
|
|
3876
|
+
p_token: state.token, p_to: username, p_kind: "photo",
|
|
3877
|
+
p_body: caption, p_image_data: imageData, p_filter: state.filter,
|
|
3878
|
+
});
|
|
3879
|
+
broadcastPulse("msg", username);
|
|
3880
|
+
}
|
|
3881
|
+
|
|
3440
3882
|
async function openSendTo(caption) {
|
|
3441
3883
|
let people = [];
|
|
3442
3884
|
try { people = await api("yap_search_users", { p_token: state.token, p_q: "" }); } catch (err) { toast(err.message, "err"); }
|
|
@@ -3457,11 +3899,7 @@ async function openSendTo(caption) {
|
|
|
3457
3899
|
list.querySelectorAll("[data-send]").forEach((b) => b.addEventListener("click", async () => {
|
|
3458
3900
|
b.disabled = true;
|
|
3459
3901
|
try {
|
|
3460
|
-
|
|
3461
|
-
await api("yap_send_yap", {
|
|
3462
|
-
p_token: state.token, p_to: b.dataset.send, p_kind: "photo",
|
|
3463
|
-
p_body: caption, p_image_data: imageData, p_filter: state.filter,
|
|
3464
|
-
});
|
|
3902
|
+
await sendPhotoYap(b.dataset.send, caption);
|
|
3465
3903
|
toast("Yap sent", "ok");
|
|
3466
3904
|
closeSheet();
|
|
3467
3905
|
retake();
|
|
@@ -4467,7 +4905,10 @@ boot();
|
|
|
4467
4905
|
window.addEventListener("pagehide", () => stopCamera());
|
|
4468
4906
|
document.addEventListener("visibilitychange", () => {
|
|
4469
4907
|
if (document.hidden) stopCamera();
|
|
4470
|
-
else
|
|
4908
|
+
else {
|
|
4909
|
+
if (state.view === "camera") startCamera();
|
|
4910
|
+
void silentPulseRefresh();
|
|
4911
|
+
}
|
|
4471
4912
|
});
|
|
4472
4913
|
|
|
4473
4914
|
</script>
|