mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
Extract swipe gesture logic and improve push notification handling (#135)
This commit is contained in:
1 parent
24609ef6c3
commit
687ad405ae
13 files changed
+259
-78
No files matched your search
@@ -94,7 +94,7 @@ export function createSSERoutes() {
|
||||
if (!result.success) {
|
||||
return c.json({ success: false, error: 'Invalid request', details: result.error.issues }, 400)
|
||||
}
|
||||
const success = sseAggregator.setClientVisibility(result.data.clientId, result.data.visible)
|
||||
const success = sseAggregator.setClientVisibility(result.data.clientId, result.data.visible, result.data.activeSessionId ?? null)
|
||||
if (!success) {
|
||||
return c.json({ success: false, error: 'Client not found' }, 404)
|
||||
}
|
||||
|
||||
@@ -191,10 +191,6 @@ export class NotificationService {
|
||||
return rows.map((r) => r.user_id);
|
||||
}
|
||||
|
||||
private hasActiveSSEClients(): boolean {
|
||||
return sseAggregator.hasVisibleClients();
|
||||
}
|
||||
|
||||
async handleSSEEvent(
|
||||
_directory: string,
|
||||
event: SSEEvent
|
||||
@@ -202,7 +198,8 @@ export class NotificationService {
|
||||
const config = EVENT_CONFIG[event.type];
|
||||
if (!config) return;
|
||||
|
||||
if (this.hasActiveSSEClients()) return;
|
||||
const sessionId = event.properties.sessionID as string | undefined;
|
||||
if (sessionId && sseAggregator.isSessionBeingViewed(sessionId)) return;
|
||||
|
||||
if (!this.isConfigured()) return;
|
||||
|
||||
@@ -216,27 +213,38 @@ export class NotificationService {
|
||||
if (!notifPrefs.enabled) continue;
|
||||
if (!notifPrefs.events[config.preferencesKey]) continue;
|
||||
|
||||
const sessionId = event.properties.sessionID as string | undefined;
|
||||
|
||||
let notificationUrl = "/";
|
||||
if (sessionId && _directory) {
|
||||
let repoName = "";
|
||||
let repoId: number | undefined;
|
||||
|
||||
if (_directory) {
|
||||
const reposBasePath = getReposPath();
|
||||
const localPath = path.relative(reposBasePath, _directory);
|
||||
const repo = getRepoByLocalPath(this.db, localPath);
|
||||
|
||||
|
||||
if (repo) {
|
||||
notificationUrl = `/repos/${repo.id}/sessions/${sessionId}`;
|
||||
repoId = repo.id;
|
||||
repoName = path.basename(repo.localPath);
|
||||
if (sessionId) {
|
||||
notificationUrl = `/repos/${repo.id}/sessions/${sessionId}`;
|
||||
} else {
|
||||
notificationUrl = `/repos/${repo.id}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const body = config.bodyFn(event.properties);
|
||||
|
||||
const payload: PushNotificationPayload = {
|
||||
title: config.title,
|
||||
body: config.bodyFn(event.properties),
|
||||
title: repoName ? `[${repoName.toUpperCase()}] ${config.title}` : config.title,
|
||||
body: body,
|
||||
tag: `${event.type}-${sessionId ?? "global"}`,
|
||||
data: {
|
||||
eventType: event.type,
|
||||
sessionId,
|
||||
directory: _directory,
|
||||
repoId,
|
||||
repoName,
|
||||
url: notificationUrl,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@ interface SSEClient {
|
||||
callback: SSEClientCallback
|
||||
directories: Set<string>
|
||||
visible: boolean
|
||||
activeSessionId: string | null
|
||||
}
|
||||
|
||||
interface DirectoryConnection {
|
||||
@@ -51,7 +52,8 @@ class SSEAggregator {
|
||||
id,
|
||||
callback,
|
||||
directories: new Set(directories),
|
||||
visible: false
|
||||
visible: false,
|
||||
activeSessionId: null
|
||||
}
|
||||
this.clients.set(id, client)
|
||||
|
||||
@@ -353,19 +355,22 @@ class SSEAggregator {
|
||||
return this.clients.size
|
||||
}
|
||||
|
||||
setClientVisibility(id: string, visible: boolean): boolean {
|
||||
setClientVisibility(id: string, visible: boolean, activeSessionId: string | null = null): boolean {
|
||||
const client = this.clients.get(id)
|
||||
if (!client) {
|
||||
logger.warn(`setClientVisibility: client ${id} not found`)
|
||||
return false
|
||||
}
|
||||
client.visible = visible
|
||||
client.activeSessionId = visible ? activeSessionId : null
|
||||
return true
|
||||
}
|
||||
|
||||
hasVisibleClients(): boolean {
|
||||
isSessionBeingViewed(sessionId: string): boolean {
|
||||
for (const client of this.clients.values()) {
|
||||
if (client.visible) return true
|
||||
if (client.visible && client.activeSessionId === sessionId) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user