Надёжная real-time доставка сообщений в чатах: SSE buffer, Last-Event-ID, polling fallback
This commit is contained in:
@@ -2,7 +2,7 @@ import { Router } from "express";
|
||||
import { z } from "zod";
|
||||
import { db, openTenantCtx } from "../db";
|
||||
import { conversations, conversationMembers, conversationMessages, users, bots, type Bot } from "@shared/schema";
|
||||
import { eq, and, lt, desc, sql, inArray } from "drizzle-orm";
|
||||
import { eq, and, lt, gt, desc, sql, inArray } from "drizzle-orm";
|
||||
import { authenticateToken, type AuthenticatedRequest } from "../middleware/auth.middleware";
|
||||
import { tenantIsolation } from "../middleware/tenant.middleware";
|
||||
import { eventBus } from "./shared";
|
||||
@@ -28,6 +28,7 @@ export function registerMessengerMessageRoutes(router: Router): void {
|
||||
|
||||
const limit = Math.min(parseInt((req.query.limit as string) ?? "50"), 100);
|
||||
const beforeId = req.query.beforeId ? parseInt(req.query.beforeId as string) : null;
|
||||
const afterId = req.query.afterId ? parseInt(req.query.afterId as string) : null;
|
||||
|
||||
const conditions = [
|
||||
eq(conversationMessages.conversationId, convId),
|
||||
@@ -36,6 +37,9 @@ export function registerMessengerMessageRoutes(router: Router): void {
|
||||
if (beforeId !== null && !isNaN(beforeId)) {
|
||||
conditions.push(lt(conversationMessages.id, beforeId));
|
||||
}
|
||||
if (afterId !== null && !isNaN(afterId)) {
|
||||
conditions.push(gt(conversationMessages.id, afterId));
|
||||
}
|
||||
|
||||
const msgs = await db
|
||||
.select({
|
||||
|
||||
Reference in New Issue
Block a user