Поправил пуши для личных сообщений

This commit is contained in:
AidarKC
2026-10-21 11:47:27 +03:00
parent aa5addb5d9
commit 7a6ab3b35a
22 changed files with 723 additions and 678 deletions
@@ -1,5 +1,6 @@
package shine.db.dao;
import shine.db.DbController;
import shine.db.MsgSubType;
import shine.db.entities.SignedMessageEntry;
@@ -17,6 +18,7 @@ import java.util.Map;
public final class DmDialogStateDAO {
private static volatile DmDialogStateDAO instance;
private final DbController db = DbController.getInstance();
private DmDialogStateDAO() {}
@@ -129,6 +131,26 @@ public final class DmDialogStateDAO {
return out;
}
/** Снимок счётчика после записи DM. Используется только сервером для push/WS, не отдаёт текст сообщения. */
public NotificationState getNotificationState(String ownerLogin, String peerLogin) throws SQLException {
try (Connection c = db.getConnection();
PreparedStatement ps = c.prepareStatement("""
SELECT unread_count, updated_at_ms
FROM dm_dialog_state
WHERE LOWER(owner_login) = LOWER(?) AND LOWER(peer_login) = LOWER(?)
LIMIT 1
""")) {
ps.setString(1, normalize(ownerLogin));
ps.setString(2, normalize(peerLogin));
try (ResultSet rs = ps.executeQuery()) {
if (!rs.next()) return null;
return new NotificationState(Math.max(0, rs.getInt("unread_count")), rs.getLong("updated_at_ms"));
}
}
}
public record NotificationState(int unreadCount, long versionMs) {}
public void refreshFromEntry(Connection c, SignedMessageEntry entry) throws SQLException {
if (entry == null) return;
refreshConversationPair(c, entry.getFromLogin(), entry.getToLogin());
@@ -274,7 +296,7 @@ public final class DmDialogStateDAO {
last_message_time_ms = EXCLUDED.last_message_time_ms,
unread_count = EXCLUDED.unread_count,
last_read_receipt_time_ms = EXCLUDED.last_read_receipt_time_ms,
updated_at_ms = EXCLUDED.updated_at_ms
updated_at_ms = GREATEST(dm_dialog_state.updated_at_ms + 1, EXCLUDED.updated_at_ms)
""")) {
ps.setString(1, summary.ownerLogin());
ps.setString(2, summary.peerLogin());