forked from retoor/devplacepy
feat: add telegram notification channel with outbox service and per-user preferences
Extend the notification system with a third channel (telegram) alongside existing in_app and push channels. Add `telegram_enabled` column to `notification_preferences` table, update `NOTIFICATION_CHANNELS` and `_NOTIFICATION_CHANNEL_COLUMNS` mappings, and set telegram default to off (`_NOTIFICATION_CHANNEL_DEFAULTS`). Create `telegram_outbox` table with columns for uid, user_uid, chat_id, text, status, attempts, created_at, and sent_at, plus an index on status/id for efficient polling. Register `TelegramOutboxService` in the service manager lifecycle. Update API documentation strings to describe the new channel and its pairing requirement. Extend admin notification defaults view to include telegram column. Pass `notif_telegram_paired` flag to profile template based on `telegram_store.is_paired()` check. Update `NotificationPrefForm` and `NotificationDefaultForm` model literals to accept "telegram" as a valid channel value.
This commit is contained in:
@@ -1216,7 +1216,12 @@ body:has(.page-messages) {
|
||||
|
||||
.card-link-host a:not(.card-link),
|
||||
.card-link-host button,
|
||||
.card-link-host form {
|
||||
.card-link-host form,
|
||||
.card-link-host label,
|
||||
.card-link-host input,
|
||||
.card-link-host select,
|
||||
.card-link-host textarea,
|
||||
.card-link-host summary {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
@@ -233,6 +233,7 @@
|
||||
}
|
||||
|
||||
.game-lb-rank {
|
||||
flex-shrink: 0;
|
||||
color: var(--text-muted);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.8rem;
|
||||
@@ -241,6 +242,10 @@
|
||||
|
||||
.game-lb-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--text-primary);
|
||||
text-decoration: none;
|
||||
font-weight: 600;
|
||||
@@ -252,10 +257,20 @@
|
||||
}
|
||||
|
||||
.game-lb-level {
|
||||
flex-shrink: 0;
|
||||
color: var(--text-secondary);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.game-lb-score {
|
||||
flex-shrink: 0;
|
||||
color: var(--text-muted);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.8rem;
|
||||
min-width: 4em;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.game-lb-empty {
|
||||
color: var(--text-muted);
|
||||
font-size: 0.85rem;
|
||||
|
||||
@@ -506,3 +506,135 @@
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.landing-game {
|
||||
max-width: 960px;
|
||||
margin: 0 auto 3rem;
|
||||
padding: 0 2rem;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.landing-game-body {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--accent);
|
||||
border-radius: var(--radius-xl);
|
||||
background: var(--bg-card);
|
||||
padding: 2.25rem 2rem;
|
||||
text-align: center;
|
||||
box-shadow: var(--shadow-lg);
|
||||
}
|
||||
|
||||
.landing-game-glow {
|
||||
position: absolute;
|
||||
inset: -40% -10% auto -10%;
|
||||
height: 280px;
|
||||
background: radial-gradient(circle at 50% 0%, var(--accent) 0%, transparent 70%);
|
||||
opacity: 0.18;
|
||||
pointer-events: none;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.landing-game-body > * {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.landing-game-eyebrow {
|
||||
display: inline-block;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
color: var(--accent);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.landing-game-title {
|
||||
margin: 0 0 0.75rem;
|
||||
font-size: 1.9rem;
|
||||
font-weight: 800;
|
||||
color: var(--text-primary);
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.landing-game-title span {
|
||||
color: var(--text-secondary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.landing-game-tagline {
|
||||
max-width: 640px;
|
||||
margin: 0 auto 1.25rem;
|
||||
color: var(--text-secondary);
|
||||
font-size: 1.02rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.landing-game-crops {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 0.75rem;
|
||||
font-size: 1.85rem;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.landing-game-points {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0 auto 1.5rem;
|
||||
max-width: 620px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.landing-game-points li {
|
||||
position: relative;
|
||||
padding-left: 1.5rem;
|
||||
color: var(--text-primary);
|
||||
font-size: 0.95rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.landing-game-points li::before {
|
||||
content: "\2714";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
color: var(--accent);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.landing-game-cta {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.9rem 2.25rem;
|
||||
font-size: 1.05rem;
|
||||
border-radius: var(--radius-lg);
|
||||
background: var(--accent);
|
||||
color: var(--white);
|
||||
font-weight: 700;
|
||||
text-decoration: none;
|
||||
transition: filter 0.15s ease, transform 0.15s ease;
|
||||
}
|
||||
|
||||
.landing-game-cta:hover {
|
||||
filter: brightness(1.08);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.landing-game-title {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.landing-game-cta {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,6 +185,7 @@ a.profile-stat-value:hover {
|
||||
border: 1px solid var(--border);
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
scroll-margin-top: calc(var(--nav-height) + 1rem);
|
||||
}
|
||||
|
||||
.profile-tabs.tabs-managed {
|
||||
@@ -218,6 +219,13 @@ a.profile-stat-value:hover {
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.profile-panel {
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.profile-layout {
|
||||
grid-template-columns: 1fr;
|
||||
@@ -688,7 +696,7 @@ a.profile-stat-value:hover {
|
||||
}
|
||||
|
||||
.notif-prefs {
|
||||
padding: 0.5rem 0;
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.notif-prefs-intro {
|
||||
@@ -788,10 +796,51 @@ a.profile-stat-value:hover {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.notif-switch-disabled {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.notif-prefs-hint {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.notif-prefs-scroll {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.notif-prefs-actions {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.notif-prefs-table th,
|
||||
.notif-prefs-table td {
|
||||
padding: 0.6rem 0.35rem;
|
||||
}
|
||||
|
||||
.notif-prefs-col {
|
||||
width: 3.25rem;
|
||||
}
|
||||
|
||||
.notif-prefs-desc {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.notif-switch-track {
|
||||
width: 2.1rem;
|
||||
height: 1.15rem;
|
||||
}
|
||||
|
||||
.notif-switch-track::after {
|
||||
width: 0.9rem;
|
||||
height: 0.9rem;
|
||||
}
|
||||
|
||||
.notif-switch input:checked + .notif-switch-track::after {
|
||||
transform: translateX(0.95rem);
|
||||
}
|
||||
}
|
||||
|
||||
.profile-achievements {
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
|
||||
@@ -68,10 +68,10 @@ class Application {
|
||||
this.polls = new PollManager();
|
||||
this.apiKey = new ApiKeyManager();
|
||||
this.customizationToggle = new CustomizationToggle();
|
||||
this.notificationPrefs = new NotificationPrefs();
|
||||
this.notificationPrefs = new NotificationPrefs(this.pubsub);
|
||||
this.aiCorrection = new AiCorrection();
|
||||
this.aiModifier = new AiModifier();
|
||||
this.telegramPairing = new TelegramPairing();
|
||||
this.telegramPairing = new TelegramPairing(this.pubsub);
|
||||
this.adminNotificationDefaults = new AdminNotificationDefaults();
|
||||
this.userAiUsage = new UserAiUsage();
|
||||
this.tabs = new Tabs();
|
||||
|
||||
@@ -247,7 +247,7 @@ export class GameFarm {
|
||||
list.innerHTML = data.entries
|
||||
.map(
|
||||
(entry) =>
|
||||
`<li class="game-lb-row${entry.username === this.username ? " game-lb-self" : ""}"><span class="game-lb-rank">#${entry.rank}</span><a class="game-lb-name" href="/game/farm/${entry.username}">${entry.username}</a><span class="game-lb-level">Lv ${entry.level}</span></li>`
|
||||
`<li class="game-lb-row${entry.username === this.username ? " game-lb-self" : ""}"><span class="game-lb-rank">#${entry.rank}</span><a class="game-lb-name" href="/game/farm/${entry.username}">${entry.username}</a><span class="game-lb-level">Lv ${entry.level}</span><span class="game-lb-score">${entry.score.toLocaleString()}</span></li>`
|
||||
)
|
||||
.join("");
|
||||
} catch (error) {
|
||||
|
||||
@@ -3,15 +3,37 @@
|
||||
import { Http } from "./Http.js";
|
||||
|
||||
class NotificationPrefs {
|
||||
constructor() {
|
||||
constructor(pubsub) {
|
||||
this.root = document.querySelector("[data-notif-prefs]");
|
||||
if (!this.root) return;
|
||||
this.pubsub = pubsub;
|
||||
this.username = this.root.dataset.username;
|
||||
this.root
|
||||
.querySelectorAll("[data-notif-toggle]")
|
||||
.forEach((input) => this.bind(input));
|
||||
const reset = this.root.querySelector("[data-notif-reset]");
|
||||
if (reset) reset.addEventListener("click", () => this.reset(reset));
|
||||
this.subscribe();
|
||||
}
|
||||
|
||||
subscribe() {
|
||||
const uid = document.body.dataset.userUid || "";
|
||||
if (!uid || !this.pubsub) return;
|
||||
this.pubsub.subscribe(`user.${uid}.telegram`, (data) => {
|
||||
if (data && data.paired) this.enableTelegram();
|
||||
});
|
||||
}
|
||||
|
||||
enableTelegram() {
|
||||
this.root
|
||||
.querySelectorAll('[data-notif-toggle][data-channel="telegram"]')
|
||||
.forEach((input) => {
|
||||
input.disabled = false;
|
||||
const label = input.closest(".notif-switch");
|
||||
if (label) label.classList.remove("notif-switch-disabled");
|
||||
});
|
||||
const hint = this.root.querySelector(".notif-prefs-hint");
|
||||
if (hint) hint.hidden = true;
|
||||
}
|
||||
|
||||
bind(input) {
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
import { Http } from "./Http.js";
|
||||
|
||||
class TelegramPairing {
|
||||
constructor() {
|
||||
constructor(pubsub) {
|
||||
this.root = document.querySelector("[data-telegram-pairing]");
|
||||
if (!this.root) return;
|
||||
this.pubsub = pubsub;
|
||||
this.username = this.root.dataset.username;
|
||||
this.statusLabel = this.root.querySelector("[data-telegram-status]");
|
||||
this.requestBtn = this.root.querySelector("[data-telegram-request]");
|
||||
@@ -16,6 +17,21 @@ class TelegramPairing {
|
||||
this.message = this.root.querySelector("[data-telegram-status-msg]");
|
||||
if (this.requestBtn) this.requestBtn.addEventListener("click", () => this.request());
|
||||
if (this.unpairBtn) this.unpairBtn.addEventListener("click", () => this.unpair());
|
||||
this.subscribe();
|
||||
}
|
||||
|
||||
subscribe() {
|
||||
const uid = document.body.dataset.userUid || "";
|
||||
if (!uid || !this.pubsub) return;
|
||||
this.pubsub.subscribe(`user.${uid}.telegram`, (data) => {
|
||||
if (data && data.paired) this.onPaired();
|
||||
});
|
||||
}
|
||||
|
||||
onPaired() {
|
||||
this.setPaired(true);
|
||||
this.hideCode();
|
||||
this.setMessage("Telegram connected.", "success");
|
||||
}
|
||||
|
||||
async request() {
|
||||
|
||||
Reference in New Issue
Block a user