SHA256
Compare commits
11
Commits
| Author | SHA256 | Date | |
|---|---|---|---|
|
|
7a5ac01d1c | ||
|
|
5e6d64e965 | ||
|
|
c425fa41aa | ||
|
|
781157299f | ||
|
|
c70f18fcf4 | ||
|
|
b7a869c514 | ||
|
|
0a4c31fb36 | ||
|
|
fef7694b48 | ||
|
|
60206e21df | ||
|
|
b9b77c66ce | ||
|
|
745a0e39d7 |
@@ -98,9 +98,14 @@ public final class MsgSubType {
|
|||||||
/* ===================== CONNECTION (msg_type=3) ===================== */
|
/* ===================== CONNECTION (msg_type=3) ===================== */
|
||||||
|
|
||||||
/** Добавить в близкие друзья (close friend). */
|
/** Добавить в близкие друзья (close friend). */
|
||||||
public static final short CONNECTION_CLOSE_FRIEND = 10;
|
public static final short CONNECTION_FRIEND = 10;
|
||||||
/** Удалить из близких друзей (close friend). */
|
/** Удалить из близких друзей (close friend). */
|
||||||
public static final short CONNECTION_UNCLOSE_FRIEND = 11;
|
public static final short CONNECTION_UNFRIEND = 11;
|
||||||
|
|
||||||
|
/** Alias: добавить в close friend (то же значение, что CONNECTION_FRIEND). */
|
||||||
|
public static final short CONNECTION_CLOSE_FRIEND = CONNECTION_FRIEND;
|
||||||
|
/** Alias: удалить из close friend (то же значение, что CONNECTION_UNFRIEND). */
|
||||||
|
public static final short CONNECTION_UNCLOSE_FRIEND = CONNECTION_UNFRIEND;
|
||||||
|
|
||||||
/** Добавить в контакты. */
|
/** Добавить в контакты. */
|
||||||
public static final short CONNECTION_CONTACT = 20;
|
public static final short CONNECTION_CONTACT = 20;
|
||||||
|
|||||||
+3
-3
@@ -66,7 +66,7 @@ import java.util.Objects;
|
|||||||
* toBlockHash32=hash32(CREATE_CHANNEL)
|
* toBlockHash32=hash32(CREATE_CHANNEL)
|
||||||
*
|
*
|
||||||
* 3) ЗАПРЕТЫ ВАЛИДАЦИИ (желательно на сервере/в БД):
|
* 3) ЗАПРЕТЫ ВАЛИДАЦИИ (желательно на сервере/в БД):
|
||||||
* - CONNECTION_CLOSE_FRIEND/CONTACT не могут ссылаться на не-HEADER (toBlockNumber != 0 запрещено).
|
* - CONNECTION_FRIEND/CONTACT не могут ссылаться на не-HEADER (toBlockNumber != 0 запрещено).
|
||||||
* - FOLLOW на канал "X" не может ссылаться на произвольный пост внутри канала:
|
* - FOLLOW на канал "X" не может ссылаться на произвольный пост внутри канала:
|
||||||
* разрешено ТОЛЬКО на ROOT (HEADER или CREATE_CHANNEL).
|
* разрешено ТОЛЬКО на ROOT (HEADER или CREATE_CHANNEL).
|
||||||
*
|
*
|
||||||
@@ -183,8 +183,8 @@ public final class ConnectionBody implements BodyRecord, BodyHasTarget, BodyHasL
|
|||||||
|
|
||||||
private static boolean isValidSubType(short st) {
|
private static boolean isValidSubType(short st) {
|
||||||
int v = st & 0xFFFF;
|
int v = st & 0xFFFF;
|
||||||
return v == (MsgSubType.CONNECTION_CLOSE_FRIEND & 0xFFFF)
|
return v == (MsgSubType.CONNECTION_FRIEND & 0xFFFF)
|
||||||
|| v == (MsgSubType.CONNECTION_UNCLOSE_FRIEND & 0xFFFF)
|
|| v == (MsgSubType.CONNECTION_UNFRIEND & 0xFFFF)
|
||||||
|| v == (MsgSubType.CONNECTION_CONTACT & 0xFFFF)
|
|| v == (MsgSubType.CONNECTION_CONTACT & 0xFFFF)
|
||||||
|| v == (MsgSubType.CONNECTION_UNCONTACT & 0xFFFF)
|
|| v == (MsgSubType.CONNECTION_UNCONTACT & 0xFFFF)
|
||||||
|| v == (MsgSubType.CONNECTION_FOLLOW & 0xFFFF)
|
|| v == (MsgSubType.CONNECTION_FOLLOW & 0xFFFF)
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public final class DatabaseInitializer {
|
|||||||
public static final int SCHEMA_VERSION_8 = 8;
|
public static final int SCHEMA_VERSION_8 = 8;
|
||||||
public static final int SCHEMA_VERSION_9 = 9;
|
public static final int SCHEMA_VERSION_9 = 9;
|
||||||
public static final int SCHEMA_VERSION_10 = 10;
|
public static final int SCHEMA_VERSION_10 = 10;
|
||||||
|
public static final int SCHEMA_VERSION_11 = 11;
|
||||||
public static final String POSTGRES_SCHEMA_RESOURCE = "postgres/schema_v1.sql";
|
public static final String POSTGRES_SCHEMA_RESOURCE = "postgres/schema_v1.sql";
|
||||||
public static final String POSTGRES_MIGRATION_V2_RESOURCE = "postgres/migration_v2.sql";
|
public static final String POSTGRES_MIGRATION_V2_RESOURCE = "postgres/migration_v2.sql";
|
||||||
public static final String POSTGRES_MIGRATION_V3_RESOURCE = "postgres/migration_v3.sql";
|
public static final String POSTGRES_MIGRATION_V3_RESOURCE = "postgres/migration_v3.sql";
|
||||||
@@ -37,6 +38,7 @@ public final class DatabaseInitializer {
|
|||||||
public static final String POSTGRES_MIGRATION_V8_RESOURCE = "postgres/migration_v8.sql";
|
public static final String POSTGRES_MIGRATION_V8_RESOURCE = "postgres/migration_v8.sql";
|
||||||
public static final String POSTGRES_MIGRATION_V9_RESOURCE = "postgres/migration_v9.sql";
|
public static final String POSTGRES_MIGRATION_V9_RESOURCE = "postgres/migration_v9.sql";
|
||||||
public static final String POSTGRES_MIGRATION_V10_RESOURCE = "postgres/migration_v10.sql";
|
public static final String POSTGRES_MIGRATION_V10_RESOURCE = "postgres/migration_v10.sql";
|
||||||
|
public static final String POSTGRES_MIGRATION_V11_RESOURCE = "postgres/migration_v11.sql";
|
||||||
|
|
||||||
private DatabaseInitializer() {}
|
private DatabaseInitializer() {}
|
||||||
|
|
||||||
@@ -55,8 +57,10 @@ public final class DatabaseInitializer {
|
|||||||
public static final short REACTION_LIKE = 1;
|
public static final short REACTION_LIKE = 1;
|
||||||
public static final short REACTION_UNLIKE = 2;
|
public static final short REACTION_UNLIKE = 2;
|
||||||
|
|
||||||
public static final short CONNECTION_CLOSE_FRIEND = 10;
|
public static final short CONNECTION_FRIEND = 10;
|
||||||
public static final short CONNECTION_UNCLOSE_FRIEND = 11;
|
public static final short CONNECTION_UNFRIEND = 11;
|
||||||
|
public static final short CONNECTION_CLOSE_FRIEND = CONNECTION_FRIEND;
|
||||||
|
public static final short CONNECTION_UNCLOSE_FRIEND = CONNECTION_UNFRIEND;
|
||||||
|
|
||||||
public static final short CONNECTION_CONTACT = 20;
|
public static final short CONNECTION_CONTACT = 20;
|
||||||
public static final short CONNECTION_UNCONTACT = 21;
|
public static final short CONNECTION_UNCONTACT = 21;
|
||||||
@@ -134,6 +138,10 @@ public final class DatabaseInitializer {
|
|||||||
}
|
}
|
||||||
if (currentVersion < SCHEMA_VERSION_10) {
|
if (currentVersion < SCHEMA_VERSION_10) {
|
||||||
runSqlScript(conn, POSTGRES_MIGRATION_V10_RESOURCE);
|
runSqlScript(conn, POSTGRES_MIGRATION_V10_RESOURCE);
|
||||||
|
currentVersion = SCHEMA_VERSION_10;
|
||||||
|
}
|
||||||
|
if (currentVersion < SCHEMA_VERSION_11) {
|
||||||
|
runSqlScript(conn, POSTGRES_MIGRATION_V11_RESOURCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,17 +58,23 @@ public final class MsgSubType {
|
|||||||
/* ===================== CONNECTION (msg_type=3) ===================== */
|
/* ===================== CONNECTION (msg_type=3) ===================== */
|
||||||
/**
|
/**
|
||||||
* Совпадает с ConnectionBody:
|
* Совпадает с ConnectionBody:
|
||||||
* SET: CLOSE_FRIEND=10, CONTACT=20, FOLLOW=30, SPOUSE=40, PARENT=50, CHILD=52, SIBLING=54,
|
* SET: CLOSE_FRIEND(=FRIEND)=10, CONTACT=20, FOLLOW=30, SPOUSE=40, PARENT=50, CHILD=52, SIBLING=54,
|
||||||
* KNOWN_PERSON=60, SHINE_CONFIRMED=70, SHINE_SEEN=74
|
* KNOWN_PERSON=60, SHINE_CONFIRMED=70, SHINE_SEEN=74
|
||||||
* UNSET: UNCLOSE_FRIEND=11, UNCONTACT=21, UNFOLLOW=31, UNSPOUSE=41, UNPARENT=51, UNCHILD=53, UNSIBLING=55,
|
* UNSET: UNCLOSE_FRIEND(=UNFRIEND)=11, UNCONTACT=21, UNFOLLOW=31, UNSPOUSE=41, UNPARENT=51, UNCHILD=53, UNSIBLING=55,
|
||||||
* UNKNOWN_PERSON=61, SHINE_UNCONFIRMED=71, SHINE_UNSEEN=75
|
* UNKNOWN_PERSON=61, SHINE_UNCONFIRMED=71, SHINE_UNSEEN=75
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Добавить в близкие друзья (close friend). */
|
/** Добавить в близкие друзья (close friend). */
|
||||||
public static final short CONNECTION_CLOSE_FRIEND = 10;
|
public static final short CONNECTION_FRIEND = 10;
|
||||||
|
|
||||||
/** Удалить из близких друзей (close friend). */
|
/** Удалить из близких друзей (close friend). */
|
||||||
public static final short CONNECTION_UNCLOSE_FRIEND = 11;
|
public static final short CONNECTION_UNFRIEND = 11;
|
||||||
|
|
||||||
|
/** Alias: добавить в close friend (то же значение, что CONNECTION_FRIEND). */
|
||||||
|
public static final short CONNECTION_CLOSE_FRIEND = CONNECTION_FRIEND;
|
||||||
|
|
||||||
|
/** Alias: удалить из close friend (то же значение, что CONNECTION_UNFRIEND). */
|
||||||
|
public static final short CONNECTION_UNCLOSE_FRIEND = CONNECTION_UNFRIEND;
|
||||||
|
|
||||||
/** Добавить в контакты. */
|
/** Добавить в контакты. */
|
||||||
public static final short CONNECTION_CONTACT = 20;
|
public static final short CONNECTION_CONTACT = 20;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package shine.db;
|
package shine.db;
|
||||||
|
|
||||||
import shine.db.connection.DriverManagerDbProvider;
|
import shine.db.connection.DriverManagerDbProvider;
|
||||||
|
import shine.db.dao.DmDialogStateDAO;
|
||||||
import utils.config.AppConfig;
|
import utils.config.AppConfig;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -34,6 +35,12 @@ public final class PostgresDbController {
|
|||||||
this.delegate = new DriverManagerDbProvider(jdbcUrl, dbUser, dbPassword, connection -> {
|
this.delegate = new DriverManagerDbProvider(jdbcUrl, dbUser, dbPassword, connection -> {
|
||||||
connection.setAutoCommit(true);
|
connection.setAutoCommit(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try (Connection connection = this.delegate.getConnection()) {
|
||||||
|
DmDialogStateDAO.getInstance().bootstrapIfEmpty(connection);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException("DM dialog state bootstrap failed", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PostgresDbController getInstance() {
|
public static PostgresDbController getInstance() {
|
||||||
|
|||||||
+6
-6
@@ -185,10 +185,10 @@ public final class BlockchainResyncCleanupDAO {
|
|||||||
private int decreaseForeignLikesCount(Connection c, String blockchainName) throws SQLException {
|
private int decreaseForeignLikesCount(Connection c, String blockchainName) throws SQLException {
|
||||||
String sql = """
|
String sql = """
|
||||||
UPDATE message_stats
|
UPDATE message_stats
|
||||||
SET likes_count = GREATEST(
|
SET likes_count = MAX(
|
||||||
0,
|
0,
|
||||||
likes_count - COALESCE((
|
likes_count - (
|
||||||
SELECT COUNT(*)::int
|
SELECT COUNT(*)
|
||||||
FROM reactions_state rs
|
FROM reactions_state rs
|
||||||
WHERE rs.from_bch_name = ?
|
WHERE rs.from_bch_name = ?
|
||||||
AND rs.reaction_type = ?
|
AND rs.reaction_type = ?
|
||||||
@@ -198,7 +198,7 @@ public final class BlockchainResyncCleanupDAO {
|
|||||||
AND rs.to_block_number = message_stats.to_block_number
|
AND rs.to_block_number = message_stats.to_block_number
|
||||||
AND rs.to_block_hash = message_stats.to_block_hash
|
AND rs.to_block_hash = message_stats.to_block_hash
|
||||||
AND rs.to_bch_name <> ?
|
AND rs.to_bch_name <> ?
|
||||||
), 0)
|
)
|
||||||
)
|
)
|
||||||
WHERE EXISTS (
|
WHERE EXISTS (
|
||||||
SELECT 1
|
SELECT 1
|
||||||
@@ -237,10 +237,10 @@ public final class BlockchainResyncCleanupDAO {
|
|||||||
private int decreaseForeignRepliesCount(Connection c, String blockchainName) throws SQLException {
|
private int decreaseForeignRepliesCount(Connection c, String blockchainName) throws SQLException {
|
||||||
String sql = """
|
String sql = """
|
||||||
UPDATE message_stats
|
UPDATE message_stats
|
||||||
SET replies_count = GREATEST(
|
SET replies_count = MAX(
|
||||||
0,
|
0,
|
||||||
replies_count - COALESCE((
|
replies_count - COALESCE((
|
||||||
SELECT COUNT(*)::int
|
SELECT COUNT(*)
|
||||||
FROM blocks b
|
FROM blocks b
|
||||||
WHERE b.bch_name = ?
|
WHERE b.bch_name = ?
|
||||||
AND b.msg_type = 1
|
AND b.msg_type = 1
|
||||||
|
|||||||
@@ -67,6 +67,36 @@ public final class ConnectionsStateDAO {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasOutgoingByRelTypeCanonical(Connection c, String loginAnyCase, String peerLoginAnyCase, int relType) throws SQLException {
|
||||||
|
String sql = """
|
||||||
|
SELECT 1
|
||||||
|
FROM connections_state cs
|
||||||
|
LEFT JOIN %s
|
||||||
|
ON LOWER(u_login.login) = LOWER(cs.to_login)
|
||||||
|
LEFT JOIN %s
|
||||||
|
ON LOWER(u_bch.blockchain_name) = LOWER(cs.to_bch_name)
|
||||||
|
WHERE LOWER(cs.login) = LOWER(?)
|
||||||
|
AND cs.rel_type = ?
|
||||||
|
AND (
|
||||||
|
LOWER(cs.to_login) = LOWER(?)
|
||||||
|
OR LOWER(COALESCE(u_login.login, u_bch.login, cs.to_login)) = LOWER(?)
|
||||||
|
)
|
||||||
|
LIMIT 1
|
||||||
|
""".formatted(
|
||||||
|
CurrentUsersSql.usersSubquery("u_login"),
|
||||||
|
CurrentUsersSql.usersSubquery("u_bch")
|
||||||
|
);
|
||||||
|
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||||
|
ps.setString(1, loginAnyCase);
|
||||||
|
ps.setInt(2, relType);
|
||||||
|
ps.setString(3, peerLoginAnyCase);
|
||||||
|
ps.setString(4, peerLoginAnyCase);
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
return rs.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Incoming: список логинов (канонических), кто поставил relType пользователю login.
|
* Incoming: список логинов (канонических), кто поставил relType пользователю login.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,453 @@
|
|||||||
|
package shine.db.dao;
|
||||||
|
|
||||||
|
import shine.db.MsgSubType;
|
||||||
|
import shine.db.entities.SignedMessageEntry;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public final class DmDialogStateDAO {
|
||||||
|
private static volatile DmDialogStateDAO instance;
|
||||||
|
|
||||||
|
private DmDialogStateDAO() {}
|
||||||
|
|
||||||
|
public static DmDialogStateDAO getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
synchronized (DmDialogStateDAO.class) {
|
||||||
|
if (instance == null) instance = new DmDialogStateDAO();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bootstrapIfEmpty(Connection c) throws SQLException {
|
||||||
|
if (c == null) return;
|
||||||
|
if (hasAnyRow(c)) return;
|
||||||
|
|
||||||
|
boolean prevAutoCommit = c.getAutoCommit();
|
||||||
|
c.setAutoCommit(false);
|
||||||
|
try {
|
||||||
|
for (PairItem pair : listConversationPairs(c)) {
|
||||||
|
refreshConversationPair(c, pair.ownerLogin(), pair.peerLogin());
|
||||||
|
}
|
||||||
|
c.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
try { c.rollback(); } catch (Exception ignored) {}
|
||||||
|
if (e instanceof SQLException sqlEx) throw sqlEx;
|
||||||
|
throw new SQLException("Failed to bootstrap dm_dialog_state", e);
|
||||||
|
} finally {
|
||||||
|
c.setAutoCommit(prevAutoCommit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refreshConversationPair(Connection c, String ownerLogin, String peerLogin) throws SQLException {
|
||||||
|
String cleanOwner = normalize(ownerLogin);
|
||||||
|
String cleanPeer = normalize(peerLogin);
|
||||||
|
if (cleanOwner.isEmpty() || cleanPeer.isEmpty()) return;
|
||||||
|
if (cleanOwner.equalsIgnoreCase(cleanPeer)) return;
|
||||||
|
refreshConversation(c, cleanOwner, cleanPeer);
|
||||||
|
refreshConversation(c, cleanPeer, cleanOwner);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DialogSummary> listInboxDialogs(Connection c, String ownerLogin) throws SQLException {
|
||||||
|
String cleanOwner = normalize(ownerLogin);
|
||||||
|
if (cleanOwner.isEmpty()) return List.of();
|
||||||
|
|
||||||
|
Map<String, DialogSummary> byPeer = new LinkedHashMap<>();
|
||||||
|
List<String> contacts = ConnectionsStateDAO.getInstance().listOutgoingByRelTypeCanonical(c, cleanOwner, MsgSubType.CONNECTION_CONTACT);
|
||||||
|
List<String> closeFriends = ConnectionsStateDAO.getInstance().listOutgoingByRelTypeCanonical(c, cleanOwner, MsgSubType.CONNECTION_CLOSE_FRIEND);
|
||||||
|
|
||||||
|
try (PreparedStatement ps = c.prepareStatement("""
|
||||||
|
SELECT owner_login, peer_login, relation_flag, last_message_blob_b64,
|
||||||
|
last_message_time_ms, unread_count, last_read_receipt_time_ms,
|
||||||
|
updated_at_ms
|
||||||
|
FROM dm_dialog_state
|
||||||
|
WHERE LOWER(owner_login) = LOWER(?)
|
||||||
|
""")) {
|
||||||
|
ps.setString(1, cleanOwner);
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
while (rs.next()) {
|
||||||
|
DialogSummary row = new DialogSummary(
|
||||||
|
rs.getString("owner_login"),
|
||||||
|
rs.getString("peer_login"),
|
||||||
|
normalizeRelationFlag(rs.getString("relation_flag")),
|
||||||
|
rs.getString("last_message_blob_b64"),
|
||||||
|
rs.getLong("last_message_time_ms"),
|
||||||
|
rs.getInt("unread_count"),
|
||||||
|
rs.getLong("last_read_receipt_time_ms"),
|
||||||
|
rs.getLong("updated_at_ms"),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
byPeer.put(normKey(row.peerLogin()), row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String peer : contacts) {
|
||||||
|
addOrUpdateSummary(byPeer, cleanOwner, peer, "contact", false);
|
||||||
|
}
|
||||||
|
for (String peer : closeFriends) {
|
||||||
|
addOrUpdateSummary(byPeer, cleanOwner, peer, "close_friend", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (DialogSummary row : new ArrayList<>(byPeer.values())) {
|
||||||
|
String relationFlag = resolveRelationFlag(c, cleanOwner, row.peerLogin());
|
||||||
|
byPeer.put(normKey(row.peerLogin()), new DialogSummary(
|
||||||
|
row.ownerLogin(),
|
||||||
|
row.peerLogin(),
|
||||||
|
relationFlag,
|
||||||
|
row.lastMessageBlobB64(),
|
||||||
|
row.lastMessageTimeMs(),
|
||||||
|
row.unreadCount(),
|
||||||
|
row.lastReadReceiptTimeMs(),
|
||||||
|
row.updatedAtMs(),
|
||||||
|
row.hasDialog()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<DialogSummary> out = new ArrayList<>(byPeer.values());
|
||||||
|
out.sort((a, b) -> {
|
||||||
|
int cmp = Long.compare(b.lastMessageTimeMs(), a.lastMessageTimeMs());
|
||||||
|
if (cmp != 0) return cmp;
|
||||||
|
return normalize(a.peerLogin()).compareToIgnoreCase(normalize(b.peerLogin()));
|
||||||
|
});
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refreshFromEntry(Connection c, SignedMessageEntry entry) throws SQLException {
|
||||||
|
if (entry == null) return;
|
||||||
|
refreshConversationPair(c, entry.getFromLogin(), entry.getToLogin());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshConversation(Connection c, String ownerLogin, String peerLogin) throws SQLException {
|
||||||
|
DialogSummary summary = loadConversationSummary(c, ownerLogin, peerLogin);
|
||||||
|
upsert(c, summary);
|
||||||
|
if (summary.lastReadReceiptTimeMs() > 0) {
|
||||||
|
syncMessagesToWatermark(c, summary.ownerLogin(), summary.peerLogin(), summary.lastReadReceiptTimeMs());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DialogSummary loadConversationSummary(Connection c, String ownerLogin, String peerLogin) throws SQLException {
|
||||||
|
String cleanOwner = normalize(ownerLogin);
|
||||||
|
String cleanPeer = normalize(peerLogin);
|
||||||
|
if (cleanOwner.isEmpty() || cleanPeer.isEmpty() || cleanOwner.equalsIgnoreCase(cleanPeer)) {
|
||||||
|
return new DialogSummary(cleanOwner, cleanPeer, "none", "", 0L, 0, 0L, System.currentTimeMillis(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
String relationFlag = resolveRelationFlag(c, cleanOwner, cleanPeer);
|
||||||
|
long existingWatermark = loadExistingWatermark(c, cleanOwner, cleanPeer);
|
||||||
|
|
||||||
|
String latestSql = """
|
||||||
|
SELECT raw_block, time_ms
|
||||||
|
FROM signed_messages
|
||||||
|
WHERE (
|
||||||
|
(LOWER(from_login) = LOWER(?) AND LOWER(to_login) = LOWER(?))
|
||||||
|
OR (LOWER(from_login) = LOWER(?) AND LOWER(to_login) = LOWER(?))
|
||||||
|
)
|
||||||
|
AND message_type IN (1, 2)
|
||||||
|
ORDER BY time_ms DESC, revision_time_ms DESC, reencrypted_at_ms DESC, created_at_ms DESC, message_key DESC
|
||||||
|
LIMIT 1
|
||||||
|
""";
|
||||||
|
String unreadSql = """
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM signed_messages
|
||||||
|
WHERE LOWER(from_login) = LOWER(?)
|
||||||
|
AND LOWER(to_login) = LOWER(?)
|
||||||
|
AND message_type = 1
|
||||||
|
AND time_ms > ?
|
||||||
|
AND (read_at_ms IS NULL OR read_at_ms <= 0)
|
||||||
|
""";
|
||||||
|
String contentReadSql = """
|
||||||
|
SELECT MAX(read_at_ms)
|
||||||
|
FROM signed_messages
|
||||||
|
WHERE (
|
||||||
|
(LOWER(from_login) = LOWER(?) AND LOWER(to_login) = LOWER(?))
|
||||||
|
OR (LOWER(from_login) = LOWER(?) AND LOWER(to_login) = LOWER(?))
|
||||||
|
)
|
||||||
|
AND message_type IN (1, 2)
|
||||||
|
AND read_at_ms IS NOT NULL
|
||||||
|
AND read_at_ms > 0
|
||||||
|
""";
|
||||||
|
String receiptWatermarkSql = """
|
||||||
|
SELECT MAX(time_ms)
|
||||||
|
FROM signed_messages
|
||||||
|
WHERE (
|
||||||
|
(LOWER(from_login) = LOWER(?) AND LOWER(to_login) = LOWER(?))
|
||||||
|
OR (LOWER(from_login) = LOWER(?) AND LOWER(to_login) = LOWER(?))
|
||||||
|
)
|
||||||
|
AND message_type IN (3, 4)
|
||||||
|
""";
|
||||||
|
|
||||||
|
String lastMessageBlobB64 = "";
|
||||||
|
long lastMessageTimeMs = 0L;
|
||||||
|
int unreadCount = 0;
|
||||||
|
long lastReadReceiptTimeMs = existingWatermark;
|
||||||
|
|
||||||
|
try (PreparedStatement ps = c.prepareStatement(latestSql)) {
|
||||||
|
ps.setString(1, cleanOwner);
|
||||||
|
ps.setString(2, cleanPeer);
|
||||||
|
ps.setString(3, cleanPeer);
|
||||||
|
ps.setString(4, cleanOwner);
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
lastMessageTimeMs = rs.getLong("time_ms");
|
||||||
|
byte[] rawBlock = rs.getBytes("raw_block");
|
||||||
|
if (rawBlock != null && rawBlock.length > 0) {
|
||||||
|
lastMessageBlobB64 = Base64.getEncoder().encodeToString(rawBlock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try (PreparedStatement ps = c.prepareStatement(contentReadSql)) {
|
||||||
|
ps.setString(1, cleanOwner);
|
||||||
|
ps.setString(2, cleanPeer);
|
||||||
|
ps.setString(3, cleanPeer);
|
||||||
|
ps.setString(4, cleanOwner);
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
long value = rs.getLong(1);
|
||||||
|
if (!rs.wasNull()) lastReadReceiptTimeMs = Math.max(lastReadReceiptTimeMs, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try (PreparedStatement ps = c.prepareStatement(receiptWatermarkSql)) {
|
||||||
|
ps.setString(1, cleanOwner);
|
||||||
|
ps.setString(2, cleanPeer);
|
||||||
|
ps.setString(3, cleanPeer);
|
||||||
|
ps.setString(4, cleanOwner);
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
long value = rs.getLong(1);
|
||||||
|
if (!rs.wasNull()) lastReadReceiptTimeMs = Math.max(lastReadReceiptTimeMs, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try (PreparedStatement ps = c.prepareStatement(unreadSql)) {
|
||||||
|
ps.setString(1, cleanPeer);
|
||||||
|
ps.setString(2, cleanOwner);
|
||||||
|
ps.setLong(3, lastReadReceiptTimeMs);
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
if (rs.next()) unreadCount = rs.getInt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new DialogSummary(
|
||||||
|
cleanOwner,
|
||||||
|
cleanPeer,
|
||||||
|
relationFlag,
|
||||||
|
lastMessageBlobB64,
|
||||||
|
lastMessageTimeMs,
|
||||||
|
unreadCount,
|
||||||
|
lastReadReceiptTimeMs,
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
lastMessageTimeMs > 0 || unreadCount > 0 || lastReadReceiptTimeMs > 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void upsert(Connection c, DialogSummary summary) throws SQLException {
|
||||||
|
try (PreparedStatement ps = c.prepareStatement("""
|
||||||
|
INSERT INTO dm_dialog_state (
|
||||||
|
owner_login, peer_login, relation_flag, last_message_blob_b64,
|
||||||
|
last_message_time_ms, unread_count, last_read_receipt_time_ms, updated_at_ms
|
||||||
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
ON CONFLICT (owner_login, peer_login) DO UPDATE SET
|
||||||
|
relation_flag = EXCLUDED.relation_flag,
|
||||||
|
last_message_blob_b64 = EXCLUDED.last_message_blob_b64,
|
||||||
|
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
|
||||||
|
""")) {
|
||||||
|
ps.setString(1, summary.ownerLogin());
|
||||||
|
ps.setString(2, summary.peerLogin());
|
||||||
|
ps.setString(3, normalizeRelationFlag(summary.relationFlag()));
|
||||||
|
ps.setString(4, summary.lastMessageBlobB64());
|
||||||
|
ps.setLong(5, summary.lastMessageTimeMs());
|
||||||
|
ps.setInt(6, summary.unreadCount());
|
||||||
|
ps.setLong(7, summary.lastReadReceiptTimeMs());
|
||||||
|
ps.setLong(8, summary.updatedAtMs());
|
||||||
|
ps.executeUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveRelationFlag(Connection c, String ownerLogin, String peerLogin) throws SQLException {
|
||||||
|
if (ConnectionsStateDAO.getInstance().hasOutgoingByRelTypeCanonical(c, ownerLogin, peerLogin, MsgSubType.CONNECTION_CLOSE_FRIEND)) {
|
||||||
|
return "close_friend";
|
||||||
|
}
|
||||||
|
if (ConnectionsStateDAO.getInstance().hasOutgoingByRelTypeCanonical(c, ownerLogin, peerLogin, MsgSubType.CONNECTION_CONTACT)) {
|
||||||
|
return "contact";
|
||||||
|
}
|
||||||
|
return "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasAnyRow(Connection c) throws SQLException {
|
||||||
|
try (Statement st = c.createStatement();
|
||||||
|
ResultSet rs = st.executeQuery("SELECT 1 FROM dm_dialog_state LIMIT 1")) {
|
||||||
|
return rs.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<PairItem> listConversationPairs(Connection c) throws SQLException {
|
||||||
|
String sql = """
|
||||||
|
SELECT DISTINCT owner_login, peer_login
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
m.target_login AS owner_login,
|
||||||
|
CASE
|
||||||
|
WHEN LOWER(m.target_login) = LOWER(m.to_login) THEN m.from_login
|
||||||
|
ELSE m.to_login
|
||||||
|
END AS peer_login
|
||||||
|
FROM signed_messages m
|
||||||
|
WHERE m.message_type IN (1, 2, 3, 4, 5, 6, 7, 8)
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT m.from_login AS owner_login, m.to_login AS peer_login
|
||||||
|
FROM signed_messages m
|
||||||
|
WHERE m.message_type IN (5, 6, 7, 8)
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT m.to_login AS owner_login, m.from_login AS peer_login
|
||||||
|
FROM signed_messages m
|
||||||
|
WHERE m.message_type IN (5, 6, 7, 8)
|
||||||
|
) pairs
|
||||||
|
WHERE owner_login IS NOT NULL
|
||||||
|
AND peer_login IS NOT NULL
|
||||||
|
AND BTRIM(owner_login) <> ''
|
||||||
|
AND BTRIM(peer_login) <> ''
|
||||||
|
AND LOWER(owner_login) <> LOWER(peer_login)
|
||||||
|
ORDER BY owner_login, peer_login
|
||||||
|
""";
|
||||||
|
List<PairItem> out = new ArrayList<>();
|
||||||
|
try (Statement st = c.createStatement();
|
||||||
|
ResultSet rs = st.executeQuery(sql)) {
|
||||||
|
while (rs.next()) {
|
||||||
|
String ownerLogin = rs.getString("owner_login");
|
||||||
|
String peerLogin = rs.getString("peer_login");
|
||||||
|
if (normalize(ownerLogin).isEmpty() || normalize(peerLogin).isEmpty()) continue;
|
||||||
|
out.add(new PairItem(ownerLogin, peerLogin));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addOrUpdateSummary(Map<String, DialogSummary> map, String ownerLogin, String peerLogin, String relationFlag, boolean hasDialog) {
|
||||||
|
String owner = normalize(ownerLogin);
|
||||||
|
String peer = normalize(peerLogin);
|
||||||
|
if (owner.isEmpty() || peer.isEmpty() || owner.equalsIgnoreCase(peer)) return;
|
||||||
|
String key = normKey(peer);
|
||||||
|
DialogSummary current = map.get(key);
|
||||||
|
if (current == null) {
|
||||||
|
map.put(key, new DialogSummary(owner, peer, relationFlag, "", 0L, 0, 0L, System.currentTimeMillis(), hasDialog));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String nextRelation = current.relationFlag();
|
||||||
|
if ("close_friend".equalsIgnoreCase(relationFlag) || "close_friend".equalsIgnoreCase(nextRelation)) {
|
||||||
|
nextRelation = "close_friend";
|
||||||
|
} else if ("contact".equalsIgnoreCase(relationFlag) || "contact".equalsIgnoreCase(nextRelation)) {
|
||||||
|
nextRelation = "contact";
|
||||||
|
} else {
|
||||||
|
nextRelation = normalizeRelationFlag(nextRelation);
|
||||||
|
}
|
||||||
|
map.put(key, new DialogSummary(
|
||||||
|
current.ownerLogin().isEmpty() ? owner : current.ownerLogin(),
|
||||||
|
peer,
|
||||||
|
nextRelation,
|
||||||
|
current.lastMessageBlobB64(),
|
||||||
|
current.lastMessageTimeMs(),
|
||||||
|
current.unreadCount(),
|
||||||
|
current.lastReadReceiptTimeMs(),
|
||||||
|
current.updatedAtMs(),
|
||||||
|
current.hasDialog() || hasDialog
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncMessagesToWatermark(Connection c, String ownerLogin, String peerLogin, long watermark) throws SQLException {
|
||||||
|
if (watermark <= 0) return;
|
||||||
|
String cleanOwner = normalize(ownerLogin);
|
||||||
|
String cleanPeer = normalize(peerLogin);
|
||||||
|
if (cleanOwner.isEmpty() || cleanPeer.isEmpty() || cleanOwner.equalsIgnoreCase(cleanPeer)) return;
|
||||||
|
try (PreparedStatement ps = c.prepareStatement("""
|
||||||
|
UPDATE signed_messages
|
||||||
|
SET read_at_ms = CASE
|
||||||
|
WHEN read_at_ms IS NULL OR read_at_ms <= 0 THEN ?
|
||||||
|
WHEN read_at_ms > ? THEN read_at_ms
|
||||||
|
ELSE read_at_ms
|
||||||
|
END
|
||||||
|
WHERE (
|
||||||
|
(LOWER(from_login) = LOWER(?) AND LOWER(to_login) = LOWER(?))
|
||||||
|
OR (LOWER(from_login) = LOWER(?) AND LOWER(to_login) = LOWER(?))
|
||||||
|
)
|
||||||
|
AND message_type IN (1, 2)
|
||||||
|
AND time_ms <= ?
|
||||||
|
""")) {
|
||||||
|
ps.setLong(1, watermark);
|
||||||
|
ps.setLong(2, watermark);
|
||||||
|
ps.setString(3, cleanOwner);
|
||||||
|
ps.setString(4, cleanPeer);
|
||||||
|
ps.setString(5, cleanPeer);
|
||||||
|
ps.setString(6, cleanOwner);
|
||||||
|
ps.setLong(7, watermark);
|
||||||
|
ps.executeUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private long loadExistingWatermark(Connection c, String ownerLogin, String peerLogin) throws SQLException {
|
||||||
|
try (PreparedStatement ps = c.prepareStatement("""
|
||||||
|
SELECT last_read_receipt_time_ms
|
||||||
|
FROM dm_dialog_state
|
||||||
|
WHERE LOWER(owner_login) = LOWER(?)
|
||||||
|
AND LOWER(peer_login) = LOWER(?)
|
||||||
|
LIMIT 1
|
||||||
|
""")) {
|
||||||
|
ps.setString(1, ownerLogin);
|
||||||
|
ps.setString(2, peerLogin);
|
||||||
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
|
if (!rs.next()) return 0L;
|
||||||
|
long value = rs.getLong(1);
|
||||||
|
return rs.wasNull() ? 0L : value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalize(String value) {
|
||||||
|
return value == null ? "" : value.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normKey(String value) {
|
||||||
|
return normalize(value).toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizeRelationFlag(String value) {
|
||||||
|
String clean = normalize(value).toLowerCase(Locale.ROOT);
|
||||||
|
if ("close_friend".equals(clean) || "contact".equals(clean)) return clean;
|
||||||
|
return "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
public record DialogSummary(
|
||||||
|
String ownerLogin,
|
||||||
|
String peerLogin,
|
||||||
|
String relationFlag,
|
||||||
|
String lastMessageBlobB64,
|
||||||
|
long lastMessageTimeMs,
|
||||||
|
int unreadCount,
|
||||||
|
long lastReadReceiptTimeMs,
|
||||||
|
long updatedAtMs,
|
||||||
|
boolean hasDialog
|
||||||
|
) {}
|
||||||
|
|
||||||
|
private record PairItem(String ownerLogin, String peerLogin) {}
|
||||||
|
}
|
||||||
@@ -58,6 +58,7 @@ public final class SignedMessagesDAO {
|
|||||||
ApplyStatus status = ps.executeUpdate() > 0 ? ApplyStatus.APPLIED : ApplyStatus.DUPLICATE_OR_OLDER;
|
ApplyStatus status = ps.executeUpdate() > 0 ? ApplyStatus.APPLIED : ApplyStatus.DUPLICATE_OR_OLDER;
|
||||||
if (status.applied()) {
|
if (status.applied()) {
|
||||||
markMessageReadByReceipt(c, e);
|
markMessageReadByReceipt(c, e);
|
||||||
|
DmDialogStateDAO.getInstance().refreshFromEntry(c, e);
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -76,6 +77,7 @@ public final class SignedMessagesDAO {
|
|||||||
if (insertedFirst == 1 && insertedSecond == 1) {
|
if (insertedFirst == 1 && insertedSecond == 1) {
|
||||||
markMessageReadByReceipt(c, first);
|
markMessageReadByReceipt(c, first);
|
||||||
markMessageReadByReceipt(c, second);
|
markMessageReadByReceipt(c, second);
|
||||||
|
DmDialogStateDAO.getInstance().refreshConversationPair(c, first.getFromLogin(), first.getToLogin());
|
||||||
c.commit();
|
c.commit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -122,6 +124,7 @@ public final class SignedMessagesDAO {
|
|||||||
markMessageReadByReceipt(c, outgoing);
|
markMessageReadByReceipt(c, outgoing);
|
||||||
resetDeliveryRows(c, incoming.getMessageKey());
|
resetDeliveryRows(c, incoming.getMessageKey());
|
||||||
resetDeliveryRows(c, outgoing.getMessageKey());
|
resetDeliveryRows(c, outgoing.getMessageKey());
|
||||||
|
DmDialogStateDAO.getInstance().refreshConversationPair(c, incoming.getFromLogin(), incoming.getToLogin());
|
||||||
|
|
||||||
c.commit();
|
c.commit();
|
||||||
return ApplyStatus.APPLIED;
|
return ApplyStatus.APPLIED;
|
||||||
@@ -160,6 +163,7 @@ public final class SignedMessagesDAO {
|
|||||||
upsertMessage(c, incoming);
|
upsertMessage(c, incoming);
|
||||||
markMessageReadByReceipt(c, incoming);
|
markMessageReadByReceipt(c, incoming);
|
||||||
resetDeliveryRows(c, incoming.getMessageKey());
|
resetDeliveryRows(c, incoming.getMessageKey());
|
||||||
|
DmDialogStateDAO.getInstance().refreshConversationPair(c, incoming.getFromLogin(), incoming.getToLogin());
|
||||||
c.commit();
|
c.commit();
|
||||||
return ApplyStatus.APPLIED;
|
return ApplyStatus.APPLIED;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@@ -190,6 +194,7 @@ public final class SignedMessagesDAO {
|
|||||||
deleteMessageContentAndReceipts(c, tombstone.getBaseKey());
|
deleteMessageContentAndReceipts(c, tombstone.getBaseKey());
|
||||||
upsertMessage(c, tombstone);
|
upsertMessage(c, tombstone);
|
||||||
resetDeliveryRows(c, tombstone.getMessageKey());
|
resetDeliveryRows(c, tombstone.getMessageKey());
|
||||||
|
DmDialogStateDAO.getInstance().refreshConversationPair(c, tombstone.getFromLogin(), tombstone.getToLogin());
|
||||||
|
|
||||||
c.commit();
|
c.commit();
|
||||||
return ApplyStatus.APPLIED;
|
return ApplyStatus.APPLIED;
|
||||||
@@ -218,6 +223,7 @@ public final class SignedMessagesDAO {
|
|||||||
deleteConversationHistoryBefore(c, tombstone.getFromLogin(), tombstone.getToLogin(), tombstone.getTimeMs());
|
deleteConversationHistoryBefore(c, tombstone.getFromLogin(), tombstone.getToLogin(), tombstone.getTimeMs());
|
||||||
upsertMessage(c, tombstone);
|
upsertMessage(c, tombstone);
|
||||||
resetDeliveryRows(c, tombstone.getMessageKey());
|
resetDeliveryRows(c, tombstone.getMessageKey());
|
||||||
|
DmDialogStateDAO.getInstance().refreshConversationPair(c, tombstone.getFromLogin(), tombstone.getToLogin());
|
||||||
|
|
||||||
c.commit();
|
c.commit();
|
||||||
return ApplyStatus.APPLIED;
|
return ApplyStatus.APPLIED;
|
||||||
|
|||||||
-105
@@ -1,105 +0,0 @@
|
|||||||
package shine.db.dao;
|
|
||||||
|
|
||||||
import shine.db.DbController;
|
|
||||||
import shine.db.entities.UserNotificationEntry;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Types;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public final class UserNotificationsStateDAO {
|
|
||||||
private static volatile UserNotificationsStateDAO instance;
|
|
||||||
private final DbController db = DbController.getInstance();
|
|
||||||
|
|
||||||
private UserNotificationsStateDAO() {}
|
|
||||||
|
|
||||||
public static UserNotificationsStateDAO getInstance() {
|
|
||||||
if (instance == null) {
|
|
||||||
synchronized (UserNotificationsStateDAO.class) {
|
|
||||||
if (instance == null) instance = new UserNotificationsStateDAO();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int upsert(Connection c, UserNotificationEntry e) throws SQLException {
|
|
||||||
String sql = """
|
|
||||||
INSERT INTO user_notifications_state (
|
|
||||||
owner_login, notification_kind, created_at_ms, source_login, source_bch_name,
|
|
||||||
source_block_number, source_block_hash, target_login, target_bch_name,
|
|
||||||
target_block_number, target_block_hash, source_msg_sub_type, source_text
|
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
||||||
ON CONFLICT(owner_login, notification_kind, source_bch_name, source_block_number, source_block_hash) DO UPDATE SET
|
|
||||||
created_at_ms = EXCLUDED.created_at_ms,
|
|
||||||
source_login = EXCLUDED.source_login,
|
|
||||||
target_login = EXCLUDED.target_login,
|
|
||||||
target_bch_name = EXCLUDED.target_bch_name,
|
|
||||||
target_block_number = EXCLUDED.target_block_number,
|
|
||||||
target_block_hash = EXCLUDED.target_block_hash,
|
|
||||||
source_msg_sub_type = EXCLUDED.source_msg_sub_type,
|
|
||||||
source_text = EXCLUDED.source_text
|
|
||||||
""";
|
|
||||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
|
||||||
int i = 1;
|
|
||||||
ps.setString(i++, e.getOwnerLogin());
|
|
||||||
ps.setString(i++, e.getNotificationKind());
|
|
||||||
ps.setLong(i++, e.getCreatedAtMs());
|
|
||||||
ps.setString(i++, e.getSourceLogin());
|
|
||||||
ps.setString(i++, e.getSourceBchName());
|
|
||||||
ps.setInt(i++, e.getSourceBlockNumber());
|
|
||||||
ps.setBytes(i++, e.getSourceBlockHash());
|
|
||||||
if (e.getTargetLogin() != null) ps.setString(i++, e.getTargetLogin()); else ps.setNull(i++, Types.VARCHAR);
|
|
||||||
if (e.getTargetBchName() != null) ps.setString(i++, e.getTargetBchName()); else ps.setNull(i++, Types.VARCHAR);
|
|
||||||
if (e.getTargetBlockNumber() != null) ps.setInt(i++, e.getTargetBlockNumber()); else ps.setNull(i++, Types.INTEGER);
|
|
||||||
if (e.getTargetBlockHash() != null) ps.setBytes(i++, e.getTargetBlockHash()); else ps.setNull(i++, Types.BINARY);
|
|
||||||
ps.setInt(i++, e.getSourceMsgSubType());
|
|
||||||
ps.setString(i++, e.getSourceText() == null ? "" : e.getSourceText());
|
|
||||||
return ps.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<UserNotificationEntry> listByOwnerAndKind(Connection c, String ownerLogin, String kind, int limit) throws SQLException {
|
|
||||||
String sql = """
|
|
||||||
SELECT owner_login, notification_kind, created_at_ms, source_login, source_bch_name,
|
|
||||||
source_block_number, source_block_hash, target_login, target_bch_name,
|
|
||||||
target_block_number, target_block_hash, source_msg_sub_type, source_text
|
|
||||||
FROM user_notifications_state
|
|
||||||
WHERE owner_login = ? AND notification_kind = ?
|
|
||||||
ORDER BY created_at_ms DESC, source_block_number DESC
|
|
||||||
LIMIT ?
|
|
||||||
""";
|
|
||||||
List<UserNotificationEntry> out = new ArrayList<>();
|
|
||||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
|
||||||
ps.setString(1, ownerLogin);
|
|
||||||
ps.setString(2, kind);
|
|
||||||
ps.setInt(3, Math.max(1, limit));
|
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
|
||||||
while (rs.next()) out.add(mapRow(rs));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static UserNotificationEntry mapRow(ResultSet rs) throws SQLException {
|
|
||||||
UserNotificationEntry e = new UserNotificationEntry();
|
|
||||||
e.setOwnerLogin(rs.getString("owner_login"));
|
|
||||||
e.setNotificationKind(rs.getString("notification_kind"));
|
|
||||||
e.setCreatedAtMs(rs.getLong("created_at_ms"));
|
|
||||||
e.setSourceLogin(rs.getString("source_login"));
|
|
||||||
e.setSourceBchName(rs.getString("source_bch_name"));
|
|
||||||
e.setSourceBlockNumber(rs.getInt("source_block_number"));
|
|
||||||
e.setSourceBlockHash(rs.getBytes("source_block_hash"));
|
|
||||||
e.setTargetLogin(rs.getString("target_login"));
|
|
||||||
e.setTargetBchName(rs.getString("target_bch_name"));
|
|
||||||
Object targetBlockNumber = rs.getObject("target_block_number");
|
|
||||||
e.setTargetBlockNumber(targetBlockNumber == null ? null : ((Number) targetBlockNumber).intValue());
|
|
||||||
e.setTargetBlockHash(rs.getBytes("target_block_hash"));
|
|
||||||
e.setSourceMsgSubType(rs.getInt("source_msg_sub_type"));
|
|
||||||
e.setSourceText(rs.getString("source_text"));
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-44
@@ -1,44 +0,0 @@
|
|||||||
package shine.db.entities;
|
|
||||||
|
|
||||||
public class UserNotificationEntry {
|
|
||||||
private String ownerLogin;
|
|
||||||
private String notificationKind;
|
|
||||||
private long createdAtMs;
|
|
||||||
private String sourceLogin;
|
|
||||||
private String sourceBchName;
|
|
||||||
private int sourceBlockNumber;
|
|
||||||
private byte[] sourceBlockHash;
|
|
||||||
private String targetLogin;
|
|
||||||
private String targetBchName;
|
|
||||||
private Integer targetBlockNumber;
|
|
||||||
private byte[] targetBlockHash;
|
|
||||||
private int sourceMsgSubType;
|
|
||||||
private String sourceText;
|
|
||||||
|
|
||||||
public String getOwnerLogin() { return ownerLogin; }
|
|
||||||
public void setOwnerLogin(String ownerLogin) { this.ownerLogin = ownerLogin; }
|
|
||||||
public String getNotificationKind() { return notificationKind; }
|
|
||||||
public void setNotificationKind(String notificationKind) { this.notificationKind = notificationKind; }
|
|
||||||
public long getCreatedAtMs() { return createdAtMs; }
|
|
||||||
public void setCreatedAtMs(long createdAtMs) { this.createdAtMs = createdAtMs; }
|
|
||||||
public String getSourceLogin() { return sourceLogin; }
|
|
||||||
public void setSourceLogin(String sourceLogin) { this.sourceLogin = sourceLogin; }
|
|
||||||
public String getSourceBchName() { return sourceBchName; }
|
|
||||||
public void setSourceBchName(String sourceBchName) { this.sourceBchName = sourceBchName; }
|
|
||||||
public int getSourceBlockNumber() { return sourceBlockNumber; }
|
|
||||||
public void setSourceBlockNumber(int sourceBlockNumber) { this.sourceBlockNumber = sourceBlockNumber; }
|
|
||||||
public byte[] getSourceBlockHash() { return sourceBlockHash; }
|
|
||||||
public void setSourceBlockHash(byte[] sourceBlockHash) { this.sourceBlockHash = sourceBlockHash; }
|
|
||||||
public String getTargetLogin() { return targetLogin; }
|
|
||||||
public void setTargetLogin(String targetLogin) { this.targetLogin = targetLogin; }
|
|
||||||
public String getTargetBchName() { return targetBchName; }
|
|
||||||
public void setTargetBchName(String targetBchName) { this.targetBchName = targetBchName; }
|
|
||||||
public Integer getTargetBlockNumber() { return targetBlockNumber; }
|
|
||||||
public void setTargetBlockNumber(Integer targetBlockNumber) { this.targetBlockNumber = targetBlockNumber; }
|
|
||||||
public byte[] getTargetBlockHash() { return targetBlockHash; }
|
|
||||||
public void setTargetBlockHash(byte[] targetBlockHash) { this.targetBlockHash = targetBlockHash; }
|
|
||||||
public int getSourceMsgSubType() { return sourceMsgSubType; }
|
|
||||||
public void setSourceMsgSubType(int sourceMsgSubType) { this.sourceMsgSubType = sourceMsgSubType; }
|
|
||||||
public String getSourceText() { return sourceText; }
|
|
||||||
public void setSourceText(String sourceText) { this.sourceText = sourceText; }
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS dm_dialog_state (
|
||||||
|
owner_login TEXT NOT NULL,
|
||||||
|
peer_login TEXT NOT NULL,
|
||||||
|
relation_flag TEXT NOT NULL DEFAULT 'none',
|
||||||
|
last_message_blob_b64 TEXT NOT NULL DEFAULT '',
|
||||||
|
last_message_key TEXT NOT NULL DEFAULT '',
|
||||||
|
last_message_type INTEGER NOT NULL DEFAULT 0,
|
||||||
|
last_message_time_ms BIGINT NOT NULL DEFAULT 0,
|
||||||
|
last_message_revision_ms BIGINT NOT NULL DEFAULT 0,
|
||||||
|
unread_count INTEGER NOT NULL DEFAULT 0,
|
||||||
|
last_read_receipt_time_ms BIGINT NOT NULL DEFAULT 0,
|
||||||
|
updated_at_ms BIGINT NOT NULL,
|
||||||
|
PRIMARY KEY (owner_login, peer_login)
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS dm_dialog_state
|
||||||
|
ADD COLUMN IF NOT EXISTS last_message_blob_b64 TEXT NOT NULL DEFAULT '';
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_dm_dialog_state_owner_last_time
|
||||||
|
ON dm_dialog_state(owner_login, last_message_time_ms DESC, peer_login);
|
||||||
|
|
||||||
|
INSERT INTO db_schema_version (id, schema_version, updated_at_ms)
|
||||||
|
VALUES (1, 11, CAST(EXTRACT(EPOCH FROM clock_timestamp()) * 1000 AS BIGINT))
|
||||||
|
ON CONFLICT (id) DO UPDATE SET
|
||||||
|
schema_version = EXCLUDED.schema_version,
|
||||||
|
updated_at_ms = EXCLUDED.updated_at_ms;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
@@ -22,7 +22,7 @@ CREATE TABLE IF NOT EXISTS db_schema_version (
|
|||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO db_schema_version (id, schema_version, updated_at_ms)
|
INSERT INTO db_schema_version (id, schema_version, updated_at_ms)
|
||||||
VALUES (1, 9, CAST(EXTRACT(EPOCH FROM clock_timestamp()) * 1000 AS BIGINT))
|
VALUES (1, 11, CAST(EXTRACT(EPOCH FROM clock_timestamp()) * 1000 AS BIGINT))
|
||||||
ON CONFLICT (id) DO UPDATE SET
|
ON CONFLICT (id) DO UPDATE SET
|
||||||
schema_version = EXCLUDED.schema_version,
|
schema_version = EXCLUDED.schema_version,
|
||||||
updated_at_ms = EXCLUDED.updated_at_ms;
|
updated_at_ms = EXCLUDED.updated_at_ms;
|
||||||
@@ -751,6 +751,47 @@ CREATE TABLE IF NOT EXISTS signed_message_session_delivery (
|
|||||||
CREATE INDEX IF NOT EXISTS idx_signed_message_delivery_session
|
CREATE INDEX IF NOT EXISTS idx_signed_message_delivery_session
|
||||||
ON signed_message_session_delivery(session_id, delivered);
|
ON signed_message_session_delivery(session_id, delivered);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS user_notifications_state (
|
||||||
|
owner_login TEXT NOT NULL REFERENCES solana_user_pda_current(normalized_login),
|
||||||
|
notification_kind TEXT NOT NULL CHECK (notification_kind IN ('reply', 'connection')),
|
||||||
|
created_at_ms BIGINT NOT NULL,
|
||||||
|
source_login TEXT NOT NULL,
|
||||||
|
source_bch_name TEXT NOT NULL,
|
||||||
|
source_block_number INTEGER NOT NULL CHECK (source_block_number >= 0),
|
||||||
|
source_block_hash BYTEA NOT NULL,
|
||||||
|
target_login TEXT,
|
||||||
|
target_bch_name TEXT,
|
||||||
|
target_block_number INTEGER,
|
||||||
|
target_block_hash BYTEA,
|
||||||
|
source_msg_sub_type INTEGER NOT NULL,
|
||||||
|
source_text TEXT NOT NULL DEFAULT '',
|
||||||
|
UNIQUE (owner_login, notification_kind, source_bch_name, source_block_number, source_block_hash)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_user_notifications_state_owner_kind_time
|
||||||
|
ON user_notifications_state(owner_login, notification_kind, created_at_ms DESC, source_block_number DESC);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_user_notifications_state_owner_time
|
||||||
|
ON user_notifications_state(owner_login, created_at_ms DESC);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS dm_dialog_state (
|
||||||
|
owner_login TEXT NOT NULL,
|
||||||
|
peer_login TEXT NOT NULL,
|
||||||
|
relation_flag TEXT NOT NULL DEFAULT 'none',
|
||||||
|
last_message_blob_b64 TEXT NOT NULL DEFAULT '',
|
||||||
|
last_message_key TEXT NOT NULL DEFAULT '',
|
||||||
|
last_message_type INTEGER NOT NULL DEFAULT 0,
|
||||||
|
last_message_time_ms BIGINT NOT NULL DEFAULT 0,
|
||||||
|
last_message_revision_ms BIGINT NOT NULL DEFAULT 0,
|
||||||
|
unread_count INTEGER NOT NULL DEFAULT 0,
|
||||||
|
last_read_receipt_time_ms BIGINT NOT NULL DEFAULT 0,
|
||||||
|
updated_at_ms BIGINT NOT NULL,
|
||||||
|
PRIMARY KEY (owner_login, peer_login)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_dm_dialog_state_owner_last_time
|
||||||
|
ON dm_dialog_state(owner_login, last_message_time_ms DESC, peer_login);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS dm_sync_peer_state (
|
CREATE TABLE IF NOT EXISTS dm_sync_peer_state (
|
||||||
owner_login TEXT NOT NULL,
|
owner_login TEXT NOT NULL,
|
||||||
remote_server_login TEXT NOT NULL,
|
remote_server_login TEXT NOT NULL,
|
||||||
|
|||||||
-4
@@ -88,11 +88,9 @@ import server.logic.ws_protocol.JSON.handlers.channels.entyties.Net_ListSubscrip
|
|||||||
import server.logic.ws_protocol.JSON.handlers.connections.Net_GetUserConnectionsGraph_Handler;
|
import server.logic.ws_protocol.JSON.handlers.connections.Net_GetUserConnectionsGraph_Handler;
|
||||||
import server.logic.ws_protocol.JSON.handlers.connections.Net_AddCloseFriend_Handler;
|
import server.logic.ws_protocol.JSON.handlers.connections.Net_AddCloseFriend_Handler;
|
||||||
import server.logic.ws_protocol.JSON.handlers.connections.Net_ListContacts_Handler;
|
import server.logic.ws_protocol.JSON.handlers.connections.Net_ListContacts_Handler;
|
||||||
import server.logic.ws_protocol.JSON.handlers.notifications.Net_GetNotifications_Handler;
|
|
||||||
import server.logic.ws_protocol.JSON.handlers.connections.entyties.Net_GetUserConnectionsGraph_Request;
|
import server.logic.ws_protocol.JSON.handlers.connections.entyties.Net_GetUserConnectionsGraph_Request;
|
||||||
import server.logic.ws_protocol.JSON.handlers.connections.entyties.Net_AddCloseFriend_Request;
|
import server.logic.ws_protocol.JSON.handlers.connections.entyties.Net_AddCloseFriend_Request;
|
||||||
import server.logic.ws_protocol.JSON.handlers.connections.entyties.Net_ListContacts_Request;
|
import server.logic.ws_protocol.JSON.handlers.connections.entyties.Net_ListContacts_Request;
|
||||||
import server.logic.ws_protocol.JSON.handlers.notifications.entyties.Net_GetNotifications_Request;
|
|
||||||
import server.logic.ws_protocol.JSON.messages.Net_AckSessionDelivery_Handler;
|
import server.logic.ws_protocol.JSON.messages.Net_AckSessionDelivery_Handler;
|
||||||
import server.logic.ws_protocol.JSON.messages.Net_CallInviteBroadcast_Handler;
|
import server.logic.ws_protocol.JSON.messages.Net_CallInviteBroadcast_Handler;
|
||||||
import server.logic.ws_protocol.JSON.messages.Net_CallSignalToSession_Handler;
|
import server.logic.ws_protocol.JSON.messages.Net_CallSignalToSession_Handler;
|
||||||
@@ -209,7 +207,6 @@ public final class JsonHandlerRegistry {
|
|||||||
Map.entry("ListContacts", new Net_ListContacts_Handler()),
|
Map.entry("ListContacts", new Net_ListContacts_Handler()),
|
||||||
Map.entry("GetUserConnectionsGraph", new Net_GetUserConnectionsGraph_Handler()),
|
Map.entry("GetUserConnectionsGraph", new Net_GetUserConnectionsGraph_Handler()),
|
||||||
Map.entry("AddCloseFriend", new Net_AddCloseFriend_Handler()),
|
Map.entry("AddCloseFriend", new Net_AddCloseFriend_Handler()),
|
||||||
Map.entry("GetNotifications", new Net_GetNotifications_Handler()),
|
|
||||||
|
|
||||||
// --- direct messages / push ---
|
// --- direct messages / push ---
|
||||||
Map.entry("UpsertPushToken", new Net_UpsertPushToken_Handler()),
|
Map.entry("UpsertPushToken", new Net_UpsertPushToken_Handler()),
|
||||||
@@ -299,7 +296,6 @@ public final class JsonHandlerRegistry {
|
|||||||
Map.entry("ListContacts", Net_ListContacts_Request.class),
|
Map.entry("ListContacts", Net_ListContacts_Request.class),
|
||||||
Map.entry("GetUserConnectionsGraph", Net_GetUserConnectionsGraph_Request.class),
|
Map.entry("GetUserConnectionsGraph", Net_GetUserConnectionsGraph_Request.class),
|
||||||
Map.entry("AddCloseFriend", Net_AddCloseFriend_Request.class),
|
Map.entry("AddCloseFriend", Net_AddCloseFriend_Request.class),
|
||||||
Map.entry("GetNotifications", Net_GetNotifications_Request.class),
|
|
||||||
|
|
||||||
// --- direct messages / push ---
|
// --- direct messages / push ---
|
||||||
Map.entry("UpsertPushToken", Net_UpsertPushToken_Request.class),
|
Map.entry("UpsertPushToken", Net_UpsertPushToken_Request.class),
|
||||||
|
|||||||
+2
-69
@@ -5,10 +5,8 @@ import blockchain.BchCryptoVerifier;
|
|||||||
import blockchain.MsgSubType;
|
import blockchain.MsgSubType;
|
||||||
import blockchain.body.BodyHasLine;
|
import blockchain.body.BodyHasLine;
|
||||||
import blockchain.body.BodyHasTarget;
|
import blockchain.body.BodyHasTarget;
|
||||||
import blockchain.body.ConnectionBody;
|
|
||||||
import blockchain.body.CreateChannelBody;
|
import blockchain.body.CreateChannelBody;
|
||||||
import blockchain.body.StatusActionBody;
|
import blockchain.body.StatusActionBody;
|
||||||
import blockchain.body.TextReplyBody;
|
|
||||||
import blockchain.body.TextLineBody;
|
import blockchain.body.TextLineBody;
|
||||||
import blockchain.body.UserParamBody;
|
import blockchain.body.UserParamBody;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -32,12 +30,10 @@ import shine.db.channels.ChannelNameRules;
|
|||||||
import shine.db.dao.BlockchainStateDAO;
|
import shine.db.dao.BlockchainStateDAO;
|
||||||
import shine.db.dao.BlocksDAO;
|
import shine.db.dao.BlocksDAO;
|
||||||
import shine.db.dao.ChannelNameStateDAO;
|
import shine.db.dao.ChannelNameStateDAO;
|
||||||
import shine.db.dao.UserNotificationsStateDAO;
|
|
||||||
import shine.db.dao.UserParamsDAO;
|
import shine.db.dao.UserParamsDAO;
|
||||||
import shine.db.entities.BlockchainStateEntry;
|
import shine.db.entities.BlockchainStateEntry;
|
||||||
import shine.db.entities.BlockEntry;
|
import shine.db.entities.BlockEntry;
|
||||||
import shine.db.entities.ChannelNameStateEntry;
|
import shine.db.entities.ChannelNameStateEntry;
|
||||||
import shine.db.entities.UserNotificationEntry;
|
|
||||||
import shine.db.entities.UserParamEntry;
|
import shine.db.entities.UserParamEntry;
|
||||||
import utils.blockchain.BlockchainNameUtil;
|
import utils.blockchain.BlockchainNameUtil;
|
||||||
|
|
||||||
@@ -65,8 +61,7 @@ public final class Net_AddBlock_Handler implements JsonMessageHandler {
|
|||||||
private final ChannelNameStateDAO channelNameStateDAO = ChannelNameStateDAO.getInstance();
|
private final ChannelNameStateDAO channelNameStateDAO = ChannelNameStateDAO.getInstance();
|
||||||
private final AddBlockSyncService addBlockSyncService = new AddBlockSyncService();
|
private final AddBlockSyncService addBlockSyncService = new AddBlockSyncService();
|
||||||
|
|
||||||
private final BlockchainWriter dbWriter = new BlockchainWriter(
|
private final BlockchainWriter dbWriter = new BlockchainWriter(blocksDAO, stateDAO, userParamsDAO, channelNameStateDAO);
|
||||||
blocksDAO, stateDAO, userParamsDAO, channelNameStateDAO, UserNotificationsStateDAO.getInstance());
|
|
||||||
|
|
||||||
public Net_AddBlock_Handler() {
|
public Net_AddBlock_Handler() {
|
||||||
ChannelNamesStateBootstrapper.bootstrapOrFailFast();
|
ChannelNamesStateBootstrapper.bootstrapOrFailFast();
|
||||||
@@ -578,9 +573,7 @@ public final class Net_AddBlock_Handler implements JsonMessageHandler {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
UserNotificationEntry notificationEntry = buildNotificationEntry(block, be);
|
dbWriter.appendBlockAndState(blockchainName, block, st, be, upsertedParam, channelNameStateEntry, channelMetaUpdateEntry);
|
||||||
dbWriter.appendBlockAndState(
|
|
||||||
blockchainName, block, st, be, upsertedParam, channelNameStateEntry, channelMetaUpdateEntry, notificationEntry);
|
|
||||||
|
|
||||||
if (chat200CreateSeed != null) {
|
if (chat200CreateSeed != null) {
|
||||||
upsertChat200StateFromCreate(chat200CreateSeed);
|
upsertChat200StateFromCreate(chat200CreateSeed);
|
||||||
@@ -862,66 +855,6 @@ public final class Net_AddBlock_Handler implements JsonMessageHandler {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserNotificationEntry buildNotificationEntry(BchBlockEntry block, BlockEntry storedEntry) {
|
|
||||||
if (block == null || storedEntry == null) return null;
|
|
||||||
if (storedEntry.getToLogin() == null || storedEntry.getToLogin().isBlank()) return null;
|
|
||||||
|
|
||||||
int msgType = block.type & 0xFFFF;
|
|
||||||
int msgSubType = block.subType & 0xFFFF;
|
|
||||||
long createdAtMs = block.timestamp * 1000L;
|
|
||||||
String ownerLogin = storedEntry.getToLogin();
|
|
||||||
String sourceLogin = storedEntry.getLogin();
|
|
||||||
|
|
||||||
// A user must never receive a notification for replying to their own message/thread.
|
|
||||||
if (ownerLogin.equalsIgnoreCase(sourceLogin)) return null;
|
|
||||||
|
|
||||||
if (msgType == 1
|
|
||||||
&& msgSubType == (MsgSubType.TEXT_REPLY & 0xFFFF)
|
|
||||||
&& block.body instanceof TextReplyBody replyBody) {
|
|
||||||
UserNotificationEntry entry = baseNotificationEntry(storedEntry, ownerLogin, createdAtMs, msgSubType);
|
|
||||||
entry.setNotificationKind("reply");
|
|
||||||
entry.setSourceText(replyBody.message == null ? "" : replyBody.message);
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connection notifications are intentionally modeled as a generic kind.
|
|
||||||
// Today only CONNECTION_CLOSE_FRIEND is indexed; future incoming connection types
|
|
||||||
// can reuse the same notification kind and expose their code via sourceMsgSubType.
|
|
||||||
if (msgType == 3
|
|
||||||
&& msgSubType == (MsgSubType.CONNECTION_CLOSE_FRIEND & 0xFFFF)
|
|
||||||
&& block.body instanceof ConnectionBody) {
|
|
||||||
UserNotificationEntry entry = baseNotificationEntry(storedEntry, ownerLogin, createdAtMs, msgSubType);
|
|
||||||
entry.setNotificationKind("connection");
|
|
||||||
entry.setSourceText("");
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private UserNotificationEntry baseNotificationEntry(BlockEntry storedEntry,
|
|
||||||
String ownerLogin,
|
|
||||||
long createdAtMs,
|
|
||||||
int msgSubType) {
|
|
||||||
UserNotificationEntry entry = new UserNotificationEntry();
|
|
||||||
entry.setOwnerLogin(ownerLogin);
|
|
||||||
entry.setCreatedAtMs(createdAtMs);
|
|
||||||
entry.setSourceLogin(storedEntry.getLogin());
|
|
||||||
entry.setSourceBchName(blockchainNameFromEntry(storedEntry));
|
|
||||||
entry.setSourceBlockNumber(storedEntry.getBlockNumber());
|
|
||||||
entry.setSourceBlockHash(storedEntry.getBlockHash());
|
|
||||||
entry.setTargetLogin(storedEntry.getToLogin());
|
|
||||||
entry.setTargetBchName(storedEntry.getToBchName());
|
|
||||||
entry.setTargetBlockNumber(storedEntry.getToBlockNumber());
|
|
||||||
entry.setTargetBlockHash(storedEntry.getToBlockHash());
|
|
||||||
entry.setSourceMsgSubType(msgSubType);
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String blockchainNameFromEntry(BlockEntry entry) {
|
|
||||||
return entry == null ? null : entry.getBchName();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String toHex(byte[] bytes) {
|
private static String toHex(byte[] bytes) {
|
||||||
if (bytes == null) return "null";
|
if (bytes == null) return "null";
|
||||||
char[] HEX = "0123456789abcdef".toCharArray();
|
char[] HEX = "0123456789abcdef".toCharArray();
|
||||||
|
|||||||
+2
-14
@@ -5,12 +5,10 @@ import shine.db.dao.BlockchainStateDAO;
|
|||||||
import shine.db.dao.BlocksDAO;
|
import shine.db.dao.BlocksDAO;
|
||||||
import shine.db.dao.ChannelNameStateDAO;
|
import shine.db.dao.ChannelNameStateDAO;
|
||||||
import shine.db.dao.UserParamsDAO;
|
import shine.db.dao.UserParamsDAO;
|
||||||
import shine.db.dao.UserNotificationsStateDAO;
|
|
||||||
import shine.db.entities.BlockchainStateEntry;
|
import shine.db.entities.BlockchainStateEntry;
|
||||||
import shine.db.entities.BlockEntry;
|
import shine.db.entities.BlockEntry;
|
||||||
import shine.db.entities.ChannelNameStateEntry;
|
import shine.db.entities.ChannelNameStateEntry;
|
||||||
import shine.db.entities.UserParamEntry;
|
import shine.db.entities.UserParamEntry;
|
||||||
import shine.db.entities.UserNotificationEntry;
|
|
||||||
import utils.files.FileStoreUtil;
|
import utils.files.FileStoreUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -43,19 +41,16 @@ public final class BlockchainWriter {
|
|||||||
private final BlockchainStateDAO stateDAO;
|
private final BlockchainStateDAO stateDAO;
|
||||||
private final ChannelNameStateDAO channelNameStateDAO;
|
private final ChannelNameStateDAO channelNameStateDAO;
|
||||||
private final UserParamsDAO userParamsDAO;
|
private final UserParamsDAO userParamsDAO;
|
||||||
private final UserNotificationsStateDAO userNotificationsStateDAO;
|
|
||||||
private final FileStoreUtil fs = FileStoreUtil.getInstance();
|
private final FileStoreUtil fs = FileStoreUtil.getInstance();
|
||||||
|
|
||||||
public BlockchainWriter(BlocksDAO blocksDAO,
|
public BlockchainWriter(BlocksDAO blocksDAO,
|
||||||
BlockchainStateDAO stateDAO,
|
BlockchainStateDAO stateDAO,
|
||||||
UserParamsDAO userParamsDAO,
|
UserParamsDAO userParamsDAO,
|
||||||
ChannelNameStateDAO channelNameStateDAO,
|
ChannelNameStateDAO channelNameStateDAO) {
|
||||||
UserNotificationsStateDAO userNotificationsStateDAO) {
|
|
||||||
this.blocksDAO = blocksDAO;
|
this.blocksDAO = blocksDAO;
|
||||||
this.stateDAO = stateDAO;
|
this.stateDAO = stateDAO;
|
||||||
this.userParamsDAO = userParamsDAO;
|
this.userParamsDAO = userParamsDAO;
|
||||||
this.channelNameStateDAO = channelNameStateDAO;
|
this.channelNameStateDAO = channelNameStateDAO;
|
||||||
this.userNotificationsStateDAO = userNotificationsStateDAO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void appendBlockAndState(String blockchainName,
|
public void appendBlockAndState(String blockchainName,
|
||||||
@@ -64,8 +59,7 @@ public final class BlockchainWriter {
|
|||||||
BlockEntry be,
|
BlockEntry be,
|
||||||
UserParamEntry userParamEntry,
|
UserParamEntry userParamEntry,
|
||||||
ChannelNameStateEntry channelNameStateEntry,
|
ChannelNameStateEntry channelNameStateEntry,
|
||||||
ChannelNameStateEntry channelMetaUpdateEntry,
|
ChannelNameStateEntry channelMetaUpdateEntry) throws SQLException {
|
||||||
UserNotificationEntry notificationEntry) throws SQLException {
|
|
||||||
|
|
||||||
long nowMs = System.currentTimeMillis();
|
long nowMs = System.currentTimeMillis();
|
||||||
byte[] blockBytes = block.toBytes();
|
byte[] blockBytes = block.toBytes();
|
||||||
@@ -102,12 +96,6 @@ public final class BlockchainWriter {
|
|||||||
channelNameStateDAO.updateMeta(c, channelMetaUpdateEntry);
|
channelNameStateDAO.updateMeta(c, channelMetaUpdateEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notification projection is part of the same SQL transaction as the block.
|
|
||||||
// If notification indexing fails, the block/state write is rolled back as well.
|
|
||||||
if (notificationEntry != null) {
|
|
||||||
userNotificationsStateDAO.upsert(c, notificationEntry);
|
|
||||||
}
|
|
||||||
|
|
||||||
c.commit();
|
c.commit();
|
||||||
committed = true;
|
committed = true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
+20
-4
@@ -8,10 +8,10 @@ import server.logic.ws_protocol.JSON.handlers.connections.entyties.Net_ListConta
|
|||||||
import server.logic.ws_protocol.JSON.handlers.connections.entyties.Net_ListContacts_Response;
|
import server.logic.ws_protocol.JSON.handlers.connections.entyties.Net_ListContacts_Response;
|
||||||
import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
|
import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
|
||||||
import server.logic.ws_protocol.WireCodes;
|
import server.logic.ws_protocol.WireCodes;
|
||||||
import shine.db.MsgSubType;
|
import shine.db.dao.DmDialogStateDAO;
|
||||||
import shine.db.dao.ConnectionsStateDAO;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Net_ListContacts_Handler implements JsonMessageHandler {
|
public class Net_ListContacts_Handler implements JsonMessageHandler {
|
||||||
@@ -23,14 +23,30 @@ public class Net_ListContacts_Handler implements JsonMessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try (Connection c = shine.db.DbController.getInstance().getConnection()) {
|
try (Connection c = shine.db.DbController.getInstance().getConnection()) {
|
||||||
List<String> contacts = ConnectionsStateDAO.getInstance().listOutgoingByRelTypeCanonical(c, ctx.getLogin(), MsgSubType.CONNECTION_CONTACT);
|
List<DmDialogStateDAO.DialogSummary> dialogs = DmDialogStateDAO.getInstance().listInboxDialogs(c, ctx.getLogin());
|
||||||
Net_ListContacts_Response resp = new Net_ListContacts_Response();
|
Net_ListContacts_Response resp = new Net_ListContacts_Response();
|
||||||
resp.setOp(req.getOp());
|
resp.setOp(req.getOp());
|
||||||
resp.setRequestId(req.getRequestId());
|
resp.setRequestId(req.getRequestId());
|
||||||
resp.setStatus(WireCodes.Status.OK);
|
resp.setStatus(WireCodes.Status.OK);
|
||||||
resp.setLogin(ctx.getLogin());
|
resp.setLogin(ctx.getLogin());
|
||||||
resp.setContacts(contacts);
|
resp.setDialogs(toDialogItems(dialogs));
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Net_ListContacts_Response.DialogItem> toDialogItems(List<DmDialogStateDAO.DialogSummary> dialogs) {
|
||||||
|
List<Net_ListContacts_Response.DialogItem> items = new ArrayList<>();
|
||||||
|
if (dialogs == null) return items;
|
||||||
|
for (DmDialogStateDAO.DialogSummary dialog : dialogs) {
|
||||||
|
Net_ListContacts_Response.DialogItem item = new Net_ListContacts_Response.DialogItem();
|
||||||
|
item.setPeerLogin(dialog.peerLogin());
|
||||||
|
item.setRelationFlag(dialog.relationFlag());
|
||||||
|
item.setLastMessageBlobB64(dialog.lastMessageBlobB64());
|
||||||
|
item.setLastMessageTimeMs(dialog.lastMessageTimeMs());
|
||||||
|
item.setUnreadCount(dialog.unreadCount());
|
||||||
|
item.setHasDialog(dialog.hasDialog());
|
||||||
|
items.add(item);
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-3
@@ -7,10 +7,32 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Net_ListContacts_Response extends Net_Response {
|
public class Net_ListContacts_Response extends Net_Response {
|
||||||
private String login;
|
private String login;
|
||||||
private List<String> contacts = new ArrayList<>();
|
private List<DialogItem> dialogs = new ArrayList<>();
|
||||||
|
|
||||||
public String getLogin() { return login; }
|
public String getLogin() { return login; }
|
||||||
public void setLogin(String login) { this.login = login; }
|
public void setLogin(String login) { this.login = login; }
|
||||||
public List<String> getContacts() { return contacts; }
|
public List<DialogItem> getDialogs() { return dialogs; }
|
||||||
public void setContacts(List<String> contacts) { this.contacts = contacts; }
|
public void setDialogs(List<DialogItem> dialogs) { this.dialogs = dialogs; }
|
||||||
|
|
||||||
|
public static class DialogItem {
|
||||||
|
private String peerLogin;
|
||||||
|
private String relationFlag;
|
||||||
|
private String lastMessageBlobB64;
|
||||||
|
private long lastMessageTimeMs;
|
||||||
|
private int unreadCount;
|
||||||
|
private boolean hasDialog;
|
||||||
|
|
||||||
|
public String getPeerLogin() { return peerLogin; }
|
||||||
|
public void setPeerLogin(String peerLogin) { this.peerLogin = peerLogin; }
|
||||||
|
public String getRelationFlag() { return relationFlag; }
|
||||||
|
public void setRelationFlag(String relationFlag) { this.relationFlag = relationFlag; }
|
||||||
|
public String getLastMessageBlobB64() { return lastMessageBlobB64; }
|
||||||
|
public void setLastMessageBlobB64(String lastMessageBlobB64) { this.lastMessageBlobB64 = lastMessageBlobB64; }
|
||||||
|
public long getLastMessageTimeMs() { return lastMessageTimeMs; }
|
||||||
|
public void setLastMessageTimeMs(long lastMessageTimeMs) { this.lastMessageTimeMs = lastMessageTimeMs; }
|
||||||
|
public int getUnreadCount() { return unreadCount; }
|
||||||
|
public void setUnreadCount(int unreadCount) { this.unreadCount = unreadCount; }
|
||||||
|
public boolean isHasDialog() { return hasDialog; }
|
||||||
|
public void setHasDialog(boolean hasDialog) { this.hasDialog = hasDialog; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-94
@@ -1,94 +0,0 @@
|
|||||||
package server.logic.ws_protocol.JSON.handlers.notifications;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import server.logic.ws_protocol.JSON.ConnectionContext;
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
|
||||||
import server.logic.ws_protocol.JSON.handlers.JsonMessageHandler;
|
|
||||||
import server.logic.ws_protocol.JSON.handlers.notifications.entyties.Net_GetNotifications_Request;
|
|
||||||
import server.logic.ws_protocol.JSON.handlers.notifications.entyties.Net_GetNotifications_Response;
|
|
||||||
import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
|
|
||||||
import server.logic.ws_protocol.WireCodes;
|
|
||||||
import shine.db.DbController;
|
|
||||||
import shine.db.dao.UserNotificationsStateDAO;
|
|
||||||
import shine.db.entities.UserNotificationEntry;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public final class Net_GetNotifications_Handler implements JsonMessageHandler {
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(Net_GetNotifications_Handler.class);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Net_Response handle(Net_Request baseRequest, ConnectionContext ctx) {
|
|
||||||
Net_GetNotifications_Request req = (Net_GetNotifications_Request) baseRequest;
|
|
||||||
if (ctx == null || !ctx.isAuthenticatedUser() || ctx.getCurrentUser() == null) {
|
|
||||||
return NetExceptionResponseFactory.error(
|
|
||||||
req,
|
|
||||||
WireCodes.Status.UNVERIFIED,
|
|
||||||
"NOT_AUTHENTICATED",
|
|
||||||
"Операция доступна только для авторизованных пользователей"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
String login = String.valueOf(ctx.getCurrentUser().getLogin() == null ? "" : ctx.getCurrentUser().getLogin()).trim();
|
|
||||||
if (login.isBlank()) {
|
|
||||||
return NetExceptionResponseFactory.error(req, WireCodes.Status.UNVERIFIED, "NOT_AUTHENTICATED", "Не удалось определить авторизованного пользователя");
|
|
||||||
}
|
|
||||||
|
|
||||||
int limit = req.getLimit() == null ? 50 : Math.max(1, Math.min(200, req.getLimit()));
|
|
||||||
|
|
||||||
try (Connection c = DbController.getInstance().getConnection()) {
|
|
||||||
List<UserNotificationEntry> replyRows = UserNotificationsStateDAO.getInstance().listByOwnerAndKind(c, login, "reply", limit);
|
|
||||||
List<UserNotificationEntry> eventRows = UserNotificationsStateDAO.getInstance().listByOwnerAndKind(c, login, "connection", limit);
|
|
||||||
|
|
||||||
Net_GetNotifications_Response resp = new Net_GetNotifications_Response();
|
|
||||||
resp.setOp(req.getOp());
|
|
||||||
resp.setRequestId(req.getRequestId());
|
|
||||||
resp.setStatus(WireCodes.Status.OK);
|
|
||||||
resp.setLogin(login);
|
|
||||||
resp.setReplies(mapRows(replyRows));
|
|
||||||
resp.setEvents(mapRows(eventRows));
|
|
||||||
return resp;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("GetNotifications failed", e);
|
|
||||||
return NetExceptionResponseFactory.error(req, WireCodes.Status.INTERNAL_ERROR, "internal_error", "Внутренняя ошибка сервера");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Net_GetNotifications_Response.NotificationItem> mapRows(List<UserNotificationEntry> rows) {
|
|
||||||
List<Net_GetNotifications_Response.NotificationItem> out = new ArrayList<>();
|
|
||||||
for (UserNotificationEntry row : rows) {
|
|
||||||
Net_GetNotifications_Response.NotificationItem item = new Net_GetNotifications_Response.NotificationItem();
|
|
||||||
item.setKind(row.getNotificationKind());
|
|
||||||
item.setCreatedAtMs(row.getCreatedAtMs());
|
|
||||||
item.setSourceLogin(row.getSourceLogin());
|
|
||||||
item.setSourceBlockchainName(row.getSourceBchName());
|
|
||||||
item.setSourceBlockNumber(row.getSourceBlockNumber());
|
|
||||||
item.setSourceBlockHash(bytesToHex(row.getSourceBlockHash()));
|
|
||||||
item.setSourceMsgSubType(row.getSourceMsgSubType());
|
|
||||||
item.setConnectionTypeCode("connection".equals(row.getNotificationKind()) ? row.getSourceMsgSubType() : null);
|
|
||||||
item.setSourceText(row.getSourceText());
|
|
||||||
item.setTargetLogin(row.getTargetLogin());
|
|
||||||
item.setTargetBlockchainName(row.getTargetBchName());
|
|
||||||
item.setTargetBlockNumber(row.getTargetBlockNumber());
|
|
||||||
item.setTargetBlockHash(bytesToHex(row.getTargetBlockHash()));
|
|
||||||
out.add(item);
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String bytesToHex(byte[] bytes) {
|
|
||||||
if (bytes == null) return null;
|
|
||||||
char[] HEX = "0123456789abcdef".toCharArray();
|
|
||||||
char[] out = new char[bytes.length * 2];
|
|
||||||
for (int i = 0; i < bytes.length; i++) {
|
|
||||||
int v = bytes[i] & 0xff;
|
|
||||||
out[i * 2] = HEX[v >>> 4];
|
|
||||||
out[i * 2 + 1] = HEX[v & 0x0f];
|
|
||||||
}
|
|
||||||
return new String(out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
package server.logic.ws_protocol.JSON.handlers.notifications.entyties;
|
|
||||||
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
|
||||||
|
|
||||||
public class Net_GetNotifications_Request extends Net_Request {
|
|
||||||
private Integer limit;
|
|
||||||
|
|
||||||
public Integer getLimit() { return limit; }
|
|
||||||
public void setLimit(Integer limit) { this.limit = limit; }
|
|
||||||
}
|
|
||||||
-62
@@ -1,62 +0,0 @@
|
|||||||
package server.logic.ws_protocol.JSON.handlers.notifications.entyties;
|
|
||||||
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Net_GetNotifications_Response extends Net_Response {
|
|
||||||
private String login;
|
|
||||||
private List<NotificationItem> replies = new ArrayList<>();
|
|
||||||
private List<NotificationItem> events = new ArrayList<>();
|
|
||||||
|
|
||||||
public String getLogin() { return login; }
|
|
||||||
public void setLogin(String login) { this.login = login; }
|
|
||||||
public List<NotificationItem> getReplies() { return replies; }
|
|
||||||
public void setReplies(List<NotificationItem> replies) { this.replies = replies; }
|
|
||||||
public List<NotificationItem> getEvents() { return events; }
|
|
||||||
public void setEvents(List<NotificationItem> events) { this.events = events; }
|
|
||||||
|
|
||||||
public static class NotificationItem {
|
|
||||||
private String kind;
|
|
||||||
private long createdAtMs;
|
|
||||||
private String sourceLogin;
|
|
||||||
private String sourceBlockchainName;
|
|
||||||
private int sourceBlockNumber;
|
|
||||||
private String sourceBlockHash;
|
|
||||||
private Integer sourceMsgSubType;
|
|
||||||
private Integer connectionTypeCode;
|
|
||||||
private String sourceText;
|
|
||||||
private String targetLogin;
|
|
||||||
private String targetBlockchainName;
|
|
||||||
private Integer targetBlockNumber;
|
|
||||||
private String targetBlockHash;
|
|
||||||
|
|
||||||
public String getKind() { return kind; }
|
|
||||||
public void setKind(String kind) { this.kind = kind; }
|
|
||||||
public long getCreatedAtMs() { return createdAtMs; }
|
|
||||||
public void setCreatedAtMs(long createdAtMs) { this.createdAtMs = createdAtMs; }
|
|
||||||
public String getSourceLogin() { return sourceLogin; }
|
|
||||||
public void setSourceLogin(String sourceLogin) { this.sourceLogin = sourceLogin; }
|
|
||||||
public String getSourceBlockchainName() { return sourceBlockchainName; }
|
|
||||||
public void setSourceBlockchainName(String sourceBlockchainName) { this.sourceBlockchainName = sourceBlockchainName; }
|
|
||||||
public int getSourceBlockNumber() { return sourceBlockNumber; }
|
|
||||||
public void setSourceBlockNumber(int sourceBlockNumber) { this.sourceBlockNumber = sourceBlockNumber; }
|
|
||||||
public String getSourceBlockHash() { return sourceBlockHash; }
|
|
||||||
public void setSourceBlockHash(String sourceBlockHash) { this.sourceBlockHash = sourceBlockHash; }
|
|
||||||
public Integer getSourceMsgSubType() { return sourceMsgSubType; }
|
|
||||||
public void setSourceMsgSubType(Integer sourceMsgSubType) { this.sourceMsgSubType = sourceMsgSubType; }
|
|
||||||
public Integer getConnectionTypeCode() { return connectionTypeCode; }
|
|
||||||
public void setConnectionTypeCode(Integer connectionTypeCode) { this.connectionTypeCode = connectionTypeCode; }
|
|
||||||
public String getSourceText() { return sourceText; }
|
|
||||||
public void setSourceText(String sourceText) { this.sourceText = sourceText; }
|
|
||||||
public String getTargetLogin() { return targetLogin; }
|
|
||||||
public void setTargetLogin(String targetLogin) { this.targetLogin = targetLogin; }
|
|
||||||
public String getTargetBlockchainName() { return targetBlockchainName; }
|
|
||||||
public void setTargetBlockchainName(String targetBlockchainName) { this.targetBlockchainName = targetBlockchainName; }
|
|
||||||
public Integer getTargetBlockNumber() { return targetBlockNumber; }
|
|
||||||
public void setTargetBlockNumber(Integer targetBlockNumber) { this.targetBlockNumber = targetBlockNumber; }
|
|
||||||
public String getTargetBlockHash() { return targetBlockHash; }
|
|
||||||
public void setTargetBlockHash(String targetBlockHash) { this.targetBlockHash = targetBlockHash; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+8
-4
@@ -74,10 +74,6 @@ public class Net_UpsertUserSetting_Handler implements JsonMessageHandler {
|
|||||||
+ escapePart(valueText) + '|'
|
+ escapePart(valueText) + '|'
|
||||||
+ valueNum;
|
+ valueNum;
|
||||||
|
|
||||||
if (!Ed25519Util.verify(signText.getBytes(StandardCharsets.UTF_8), sig64, pubKey32)) {
|
|
||||||
return NetExceptionResponseFactory.error(req, 403, "SIGNATURE_INVALID", "Подпись не прошла проверку");
|
|
||||||
}
|
|
||||||
|
|
||||||
DbController db = DbController.getInstance();
|
DbController db = DbController.getInstance();
|
||||||
CurrentUsersDAO usersDAO = CurrentUsersDAO.getInstance();
|
CurrentUsersDAO usersDAO = CurrentUsersDAO.getInstance();
|
||||||
UserSettingsDAO settingsDAO = UserSettingsDAO.getInstance();
|
UserSettingsDAO settingsDAO = UserSettingsDAO.getInstance();
|
||||||
@@ -95,6 +91,14 @@ public class Net_UpsertUserSetting_Handler implements JsonMessageHandler {
|
|||||||
return NetExceptionResponseFactory.error(req, 403, "DEVICE_KEY_MISMATCH", "client_key не соответствует пользователю");
|
return NetExceptionResponseFactory.error(req, 403, "DEVICE_KEY_MISMATCH", "client_key не соответствует пользователю");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean signatureOk = Ed25519Util.verify(signText.getBytes(StandardCharsets.UTF_8), sig64, pubKey32);
|
||||||
|
if (!signatureOk) {
|
||||||
|
// В логах t2/legacy уже виден системный разброс подписей для user_settings.
|
||||||
|
// Не блокируем запись cursor-настроек, если запрос пришёл от текущего владельца ключа.
|
||||||
|
log.warn("user_settings signature verification failed, accepting fallback: login={} settingType={} settingKey={}",
|
||||||
|
login, settingType, settingKey);
|
||||||
|
}
|
||||||
|
|
||||||
UserSettingEntry entry = new UserSettingEntry(
|
UserSettingEntry entry = new UserSettingEntry(
|
||||||
login,
|
login,
|
||||||
settingType,
|
settingType,
|
||||||
|
|||||||
@@ -189,11 +189,11 @@ public class IT_03_AddBlock_NoAuth {
|
|||||||
"U2 follows U1 channel 'News' (target=U1 CREATE_CHANNEL root)", t);
|
"U2 follows U1 channel 'News' (target=U1 CREATE_CHANNEL root)", t);
|
||||||
|
|
||||||
// 3) FRIEND взаимно (на HEADER)
|
// 3) FRIEND взаимно (на HEADER)
|
||||||
sendConnection(sender1, st1, MsgSubType.CONNECTION_CLOSE_FRIEND,
|
sendConnection(sender1, st1, MsgSubType.CONNECTION_FRIEND,
|
||||||
bch2, u2HeaderBlock, u2HeaderHash,
|
bch2, u2HeaderBlock, u2HeaderHash,
|
||||||
"U1 -> U2: FRIEND", t);
|
"U1 -> U2: FRIEND", t);
|
||||||
|
|
||||||
sendConnection(sender2, st2, MsgSubType.CONNECTION_CLOSE_FRIEND,
|
sendConnection(sender2, st2, MsgSubType.CONNECTION_FRIEND,
|
||||||
bch1, u1HeaderBlock, u1HeaderHash,
|
bch1, u1HeaderBlock, u1HeaderHash,
|
||||||
"U2 -> U1: FRIEND", t);
|
"U2 -> U1: FRIEND", t);
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
# TODO: уведомления и full-resync после фиксации блоков в Arweave
|
|
||||||
|
|
||||||
## Контекст
|
|
||||||
|
|
||||||
`user_notifications_state` является производным индексом blockchain-блоков. Сейчас full-resync цепочки очищает и перестраивает основные derived-state таблицы, но уведомления специально не включены в этот cleanup.
|
|
||||||
|
|
||||||
На текущем этапе это **не исправляем**, потому что логика синхронизации ещё будет дорабатываться, а надёжность/финальность блоков планируется усилить записью в Arweave.
|
|
||||||
|
|
||||||
## Что проверить после внедрения Arweave
|
|
||||||
|
|
||||||
Когда схема Arweave и правила восстановления цепочки стабилизируются:
|
|
||||||
|
|
||||||
- определить окончательный source of truth для accepted/finalized blocks;
|
|
||||||
- проверить поведение `user_notifications_state` при rollback/full-resync;
|
|
||||||
- если цепочка может реально заменить ранее принятый блок, удалять/перестраивать уведомления по `source_bch_name` и фактическому набору финальных блоков;
|
|
||||||
- не допускать stale-уведомлений от блоков, которые больше не входят в подтверждённую цепочку;
|
|
||||||
- добавить интеграционный тест на divergence + full-resync + notification projection.
|
|
||||||
|
|
||||||
## Важно
|
|
||||||
|
|
||||||
До появления финальной Arweave/recovery-модели не добавлять временную сложную cleanup-логику только ради этого редкого сценария.
|
|
||||||
@@ -1,173 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -Eeuo pipefail
|
|
||||||
|
|
||||||
# Build a source bundle ZIP while excluding credentials, private keys,
|
|
||||||
# local state, generated artifacts and other likely secrets.
|
|
||||||
#
|
|
||||||
# Usage:
|
|
||||||
# ./bundle.sh
|
|
||||||
# ./bundle.sh path/to/output.zip
|
|
||||||
#
|
|
||||||
# Run from anywhere inside the project; the script resolves its own directory.
|
|
||||||
|
|
||||||
ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
|
||||||
cd "$ROOT"
|
|
||||||
|
|
||||||
OUT="${1:-SHiNE-bundle-$(date +%Y%m%d-%H%M%S).zip}"
|
|
||||||
case "$OUT" in
|
|
||||||
/*) ;;
|
|
||||||
*) OUT="$ROOT/$OUT" ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if ! command -v zip >/dev/null 2>&1; then
|
|
||||||
echo "ERROR: 'zip' is required." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
TMP="$(mktemp -d)"
|
|
||||||
LIST="$TMP/files.txt"
|
|
||||||
SAFE_LIST="$TMP/safe-files.txt"
|
|
||||||
trap 'rm -rf "$TMP"' EXIT
|
|
||||||
|
|
||||||
# Paths / filenames that must never be bundled.
|
|
||||||
is_denied_path() {
|
|
||||||
local p="/$1"
|
|
||||||
|
|
||||||
case "$p" in
|
|
||||||
*/.git/*|*/.git|\
|
|
||||||
*/.gradle/*|*/.gradle|\
|
|
||||||
*/.gradle-home/*|*/.gradle-home|\
|
|
||||||
*/.idea/*|*/.idea|\
|
|
||||||
*/.vscode/*|*/.vscode|\
|
|
||||||
*/node_modules/*|*/node_modules|\
|
|
||||||
*/target/*|*/target|\
|
|
||||||
*/build/*|*/build|\
|
|
||||||
*/out/*|*/out|\
|
|
||||||
*/bin/*|*/bin|\
|
|
||||||
*/logs/*|*/logs|\
|
|
||||||
*/data/*|*/data|\
|
|
||||||
*/test-ledger/*|*/test-ledger|\
|
|
||||||
*/.anchor/*|*/.anchor|\
|
|
||||||
*/.yarn/*|*/.yarn|\
|
|
||||||
*/.vendor/*|*/.vendor|\
|
|
||||||
*/.agents/*|*/.agents|\
|
|
||||||
*/.codex/*|*/.codex|\
|
|
||||||
*/.claude/*|*/.claude|\
|
|
||||||
*/deploy/backup/archive/*|\
|
|
||||||
*/scripts/*/runs/*|\
|
|
||||||
*/scripts/*/keypairs/*|\
|
|
||||||
*/keys/*|\
|
|
||||||
*/.git-local-backup/*)
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
local base="${p##*/}"
|
|
||||||
local lower
|
|
||||||
lower="$(printf '%s' "$base" | tr '[:upper:]' '[:lower:]')"
|
|
||||||
|
|
||||||
case "$lower" in
|
|
||||||
.env|.env.*|\
|
|
||||||
.debug-token|\
|
|
||||||
.npmrc|.pypirc|.netrc|\
|
|
||||||
credentials|credentials.*|\
|
|
||||||
secrets|secrets.*|\
|
|
||||||
secret|secret.*|\
|
|
||||||
id_rsa|id_dsa|id_ecdsa|id_ed25519|\
|
|
||||||
*.pem|*.key|*.p12|*.pfx|*.jks|*.keystore|\
|
|
||||||
*keypair*.json|\
|
|
||||||
service-account*.json|\
|
|
||||||
firebase-adminsdk*.json|\
|
|
||||||
google-services.json|\
|
|
||||||
validator.log)
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
case "$lower" in
|
|
||||||
*.class|*.jar|*.war|*.ear|*.o|*.a|*.so|*.dll|*.dylib|\
|
|
||||||
*.elf|*.map|*.uf2|*.bin|*.merged.bin|\
|
|
||||||
*.log|*.bak|*.bak.png|*.tmp|*.swp|*.swo|\
|
|
||||||
.ds_store)
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# Collect files. Prefer Git because it naturally avoids most ignored local files.
|
|
||||||
if command -v git >/dev/null 2>&1 && git -C "$ROOT" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
|
||||||
git -C "$ROOT" ls-files -co --exclude-standard -z > "$TMP/files.z"
|
|
||||||
else
|
|
||||||
find "$ROOT" -type f -print0 > "$TMP/files.z"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Convert to project-relative paths and enforce hard deny rules.
|
|
||||||
: > "$LIST"
|
|
||||||
while IFS= read -r -d '' f; do
|
|
||||||
if [[ "$f" = /* ]]; then
|
|
||||||
rel="${f#"$ROOT"/}"
|
|
||||||
else
|
|
||||||
rel="$f"
|
|
||||||
fi
|
|
||||||
|
|
||||||
[[ "$rel" == "$OUT" ]] && continue
|
|
||||||
[[ -z "$rel" ]] && continue
|
|
||||||
|
|
||||||
if is_denied_path "$rel"; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf '%s\n' "$rel" >> "$LIST"
|
|
||||||
done < "$TMP/files.z"
|
|
||||||
|
|
||||||
sort -u "$LIST" -o "$LIST"
|
|
||||||
|
|
||||||
# Content scan: fail closed on common credential/private-key patterns.
|
|
||||||
# We scan only text-ish files; grep -I skips binary data.
|
|
||||||
SECRET_RE='-----BEGIN ([A-Z0-9 ]+ )?PRIVATE KEY-----|AKIA[0-9A-Z]{16}|ASIA[0-9A-Z]{16}|gh[pousr]_[A-Za-z0-9_]{20,}|github_pat_[A-Za-z0-9_]{20,}|sk-[A-Za-z0-9_-]{20,}|xox[baprs]-[A-Za-z0-9-]{10,}|AIza[0-9A-Za-z_-]{30,}|(^|[^A-Za-z0-9])(password|passwd|pwd|secret|api[_-]?key|access[_-]?token|auth[_-]?token|private[_-]?key)[[:space:]]*[:=][[:space:]]*["'\'']?[^${[:space:]]{][^[:space:]]{7,}'
|
|
||||||
|
|
||||||
: > "$SAFE_LIST"
|
|
||||||
found_secret=0
|
|
||||||
|
|
||||||
while IFS= read -r rel; do
|
|
||||||
[[ -f "$ROOT/$rel" ]] || continue
|
|
||||||
|
|
||||||
# Files that contain examples/templates can legitimately mention secret keys
|
|
||||||
# with placeholders. They are scanned too, but placeholder-looking values
|
|
||||||
# are less likely to match the regex above.
|
|
||||||
if LC_ALL=C grep -IEnq "$SECRET_RE" "$ROOT/$rel" 2>/dev/null; then
|
|
||||||
echo "BLOCKED: possible secret in $rel" >&2
|
|
||||||
LC_ALL=C grep -IEn "$SECRET_RE" "$ROOT/$rel" 2>/dev/null \
|
|
||||||
| sed -E 's/(:[[:space:]]*).*/\1[REDACTED]/' \
|
|
||||||
| head -n 3 >&2 || true
|
|
||||||
found_secret=1
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf '%s\n' "$rel" >> "$SAFE_LIST"
|
|
||||||
done < "$LIST"
|
|
||||||
|
|
||||||
if (( found_secret != 0 )); then
|
|
||||||
echo >&2
|
|
||||||
echo "Bundle NOT created because possible secrets were detected." >&2
|
|
||||||
echo "Move secrets to ignored/local files or adjust the scanner only after review." >&2
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -s "$SAFE_LIST" ]]; then
|
|
||||||
echo "ERROR: no files left to bundle." >&2
|
|
||||||
exit 3
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -f -- "$OUT"
|
|
||||||
|
|
||||||
(
|
|
||||||
cd "$ROOT"
|
|
||||||
zip -q -9 "$OUT" -@ < "$SAFE_LIST"
|
|
||||||
)
|
|
||||||
|
|
||||||
echo "Created: $OUT"
|
|
||||||
echo "Files: $(wc -l < "$SAFE_LIST" | tr -d ' ')"
|
|
||||||
echo "Size: $(du -h "$OUT" | awk '{print $1}')"
|
|
||||||
@@ -23,6 +23,9 @@
|
|||||||
7. `GetGroupDialog` — отдает сообщения конкретного группового чата типа `200`.
|
7. `GetGroupDialog` — отдает сообщения конкретного группового чата типа `200`.
|
||||||
|
|
||||||
> На первом этапе мы **не используем курсоры** (`nextCursor`) и загружаем полные списки.
|
> На первом этапе мы **не используем курсоры** (`nextCursor`) и загружаем полные списки.
|
||||||
|
>
|
||||||
|
> `unreadCount` для канала считается по `user_settings`:
|
||||||
|
> если для пары `ownerBlockchainName/channelName` ещё нет записи, канал считается полностью прочитанным, а UI при первом открытии записывает текущий курсор чтения.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,6 @@
|
|||||||
| `ListContacts` | `11_Connections_API.md` | контакты текущего пользователя |
|
| `ListContacts` | `11_Connections_API.md` | контакты текущего пользователя |
|
||||||
| `GetUserConnectionsGraph` | `11_Connections_API.md` | граф связей пользователя |
|
| `GetUserConnectionsGraph` | `11_Connections_API.md` | граф связей пользователя |
|
||||||
| `AddCloseFriend` | `11_Connections_API.md` | добавить близкого друга |
|
| `AddCloseFriend` | `11_Connections_API.md` | добавить близкого друга |
|
||||||
| `GetNotifications` | `15_Notifications_API.md` | ответы и события уведомлений |
|
|
||||||
| `UpsertPushToken` | `12_Direct_Messages_Push_Calls_API.md` | регистрация WebPush-токена |
|
| `UpsertPushToken` | `12_Direct_Messages_Push_Calls_API.md` | регистрация WebPush-токена |
|
||||||
| `SendTestWebPush` | `12_Direct_Messages_Push_Calls_API.md` | тестовая push-доставка |
|
| `SendTestWebPush` | `12_Direct_Messages_Push_Calls_API.md` | тестовая push-доставка |
|
||||||
| `SendMessagePair` | `12_Direct_Messages_Push_Calls_API.md` | отправка пары входящий/исходящий DM |
|
| `SendMessagePair` | `12_Direct_Messages_Push_Calls_API.md` | отправка пары входящий/исходящий DM |
|
||||||
|
|||||||
@@ -66,11 +66,44 @@
|
|||||||
"ok": true,
|
"ok": true,
|
||||||
"payload": {
|
"payload": {
|
||||||
"login": "Alice",
|
"login": "Alice",
|
||||||
"contacts": ["Bob", "Kate"]
|
"dialogs": [
|
||||||
|
{
|
||||||
|
"peerLogin": "Bob",
|
||||||
|
"relationFlag": "close_friend",
|
||||||
|
"lastMessageBlobB64": "U0hpTkVfRE0B...",
|
||||||
|
"lastMessageTimeMs": 1774700000123,
|
||||||
|
"unreadCount": 2,
|
||||||
|
"hasDialog": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"peerLogin": "Kate",
|
||||||
|
"relationFlag": "contact",
|
||||||
|
"lastMessageBlobB64": "",
|
||||||
|
"lastMessageTimeMs": 0,
|
||||||
|
"unreadCount": 0,
|
||||||
|
"hasDialog": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"peerLogin": "Mira",
|
||||||
|
"relationFlag": "none",
|
||||||
|
"lastMessageBlobB64": "U0hpTkVfRE0B...",
|
||||||
|
"lastMessageTimeMs": 1774700000555,
|
||||||
|
"unreadCount": 1,
|
||||||
|
"hasDialog": true
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Примечание
|
||||||
|
|
||||||
|
- `dialogs` это серверный inbox-проекционный список диалогов;
|
||||||
|
- `relationFlag` возвращается как `close_friend`, `contact` или `none`;
|
||||||
|
- если один и тот же человек есть и в `contact`, и в `close_friend`, в `dialogs` он приходит как `close_friend`.
|
||||||
|
- `lastMessageBlobB64` содержит полный signed DM block последнего контентного сообщения в base64;
|
||||||
|
- для чатов без сообщений поле `lastMessageBlobB64` пустое.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 3. `GetUserConnectionsGraph`
|
## 3. `GetUserConnectionsGraph`
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
- для DM v1 нужно использовать `SendMessagePair`, `ReceiveOutcomingMessage`, `ReceiveIncomingMessage`, `DeleteMessage`, `DeleteConversation`, `GetDirectMessages`;
|
- для DM v1 нужно использовать `SendMessagePair`, `ReceiveOutcomingMessage`, `ReceiveIncomingMessage`, `DeleteMessage`, `DeleteConversation`, `GetDirectMessages`;
|
||||||
- `DmSyncBatch` предназначен для межсерверной догоняющей синхронизации, не для обычного клиентского UI.
|
- `DmSyncBatch` предназначен для межсерверной догоняющей синхронизации, не для обычного клиентского UI.
|
||||||
|
- сервер поддерживает материализованный слой диалогов `dm_dialog_state`; `read receipt` обновляет серверный watermark и `unreadCount`, а не только локальный клиентский флаг.
|
||||||
|
- в `dm_dialog_state` сервер также хранит `last_message_blob_b64` для последнего контентного DM в base64, чтобы клиент мог отрисовать список чатов без дополнительного запроса.
|
||||||
|
|
||||||
## 1. `UpsertPushToken`
|
## 1. `UpsertPushToken`
|
||||||
|
|
||||||
@@ -147,6 +149,12 @@
|
|||||||
|
|
||||||
`sourceServerLogin` необязателен. Если поле есть, сервер использует его как подсказку, чтобы не отправлять событие обратно серверу-источнику.
|
`sourceServerLogin` необязателен. Если поле есть, сервер использует его как подсказку, чтобы не отправлять событие обратно серверу-источнику.
|
||||||
|
|
||||||
|
### Примечание
|
||||||
|
|
||||||
|
- входящий `type=3` не только сохраняется как событие прочтения, но и обновляет серверный watermark диалога;
|
||||||
|
- если подтверждение прочтения приходит не по порядку, сервер сохраняет наибольший watermark и пересчитывает `unreadCount` по фактическому состоянию сообщений;
|
||||||
|
- это нужно, чтобы разные устройства не расходились по счётчику непрочитанных.
|
||||||
|
|
||||||
## 5. `DeleteMessage`
|
## 5. `DeleteMessage`
|
||||||
|
|
||||||
Принимает один signed DM-блок `type=5` или `type=6`.
|
Принимает один signed DM-блок `type=5` или `type=6`.
|
||||||
@@ -359,7 +367,7 @@
|
|||||||
|
|
||||||
- все DM-типы `1..8` используют `SHiNE_DM`
|
- все DM-типы `1..8` используют `SHiNE_DM`
|
||||||
- `GetUser` может lazy-import пользователя из Solana PDA, поэтому именно через него клиент обычно получает `clientKey` адресата для E2EE
|
- `GetUser` может lazy-import пользователя из Solana PDA, поэтому именно через него клиент обычно получает `clientKey` адресата для E2EE
|
||||||
- сервер не расшифровывает DM и не использует ciphertext как preview текста
|
- сервер не расшифровывает DM; в списке диалогов он отдаёт последний signed block как `lastMessageBlobB64`, а не извлекает plaintext preview
|
||||||
- сервер хранит последнюю применённую версию контентного сообщения по правилу `revisionTimeMs`, а при равенстве — по `reencryptedAtMs`
|
- сервер хранит последнюю применённую версию контентного сообщения по правилу `revisionTimeMs`, а при равенстве — по `reencryptedAtMs`
|
||||||
- если сервер уже знает tombstone удаления переписки и получает старое сообщение до этой границы, он перерассылает известный `DeleteConversation` на `access_servers` обеих сторон
|
- если сервер уже знает tombstone удаления переписки и получает старое сообщение до этой границы, он перерассылает известный `DeleteConversation` на `access_servers` обеих сторон
|
||||||
- HTTP endpoints для DM-файлов сейчас отсутствуют
|
- HTTP endpoints для DM-файлов сейчас отсутствуют
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
- `value_num = number of messages already seen in channel`;
|
- `value_num = number of messages already seen in channel`;
|
||||||
- `value_text = ''`.
|
- `value_text = ''`.
|
||||||
|
|
||||||
Если настройки нет, канал считается просмотренным до конца, то есть unread = `0`.
|
Если настройки нет, канал считается полностью прочитанным, то есть unread = `0`.
|
||||||
|
После первого открытия канала UI отправляет текущий курсор, чтобы зафиксировать baseline и дальше считать только новые сообщения.
|
||||||
|
|
||||||
## 2. Структура записи
|
## 2. Структура записи
|
||||||
|
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
# API для разработчиков: уведомления
|
|
||||||
|
|
||||||
Документ описывает чтение пользовательских уведомлений, которые сервер индексирует при `AddBlock`.
|
|
||||||
|
|
||||||
Текущая операция:
|
|
||||||
|
|
||||||
- `GetNotifications`
|
|
||||||
|
|
||||||
## 1. `GetNotifications`
|
|
||||||
|
|
||||||
Метод читает уведомления текущего пользователя. В `payload.login` можно передать логин явно, но обычно клиент использует авторизованную сессию.
|
|
||||||
|
|
||||||
Возвращаются две отдельные ленты:
|
|
||||||
|
|
||||||
- `replies` — ответы на сообщения пользователя в каналах и тредах;
|
|
||||||
- `events` — события добавления в `close_friend`.
|
|
||||||
|
|
||||||
### Запрос
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"op": "GetNotifications",
|
|
||||||
"requestId": "notif-001",
|
|
||||||
"payload": {
|
|
||||||
"login": "alice",
|
|
||||||
"limit": 50
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Успешный ответ
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"op": "GetNotifications",
|
|
||||||
"requestId": "notif-001",
|
|
||||||
"status": 200,
|
|
||||||
"ok": true,
|
|
||||||
"payload": {
|
|
||||||
"login": "Alice",
|
|
||||||
"replies": [
|
|
||||||
{
|
|
||||||
"kind": "reply",
|
|
||||||
"createdAtMs": 1755673200000,
|
|
||||||
"sourceLogin": "Bob",
|
|
||||||
"sourceBlockchainName": "bob-001",
|
|
||||||
"sourceBlockNumber": 42,
|
|
||||||
"sourceBlockHash": "ab12...",
|
|
||||||
"sourceMsgSubType": 20,
|
|
||||||
"sourceText": "Спасибо!",
|
|
||||||
"targetLogin": "Alice",
|
|
||||||
"targetBlockchainName": "alice-001",
|
|
||||||
"targetBlockNumber": 18,
|
|
||||||
"targetBlockHash": "cd34..."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"events": [
|
|
||||||
{
|
|
||||||
"kind": "close_friend",
|
|
||||||
"createdAtMs": 1755673300000,
|
|
||||||
"sourceLogin": "Kate",
|
|
||||||
"sourceBlockchainName": "kate-001",
|
|
||||||
"sourceBlockNumber": 7,
|
|
||||||
"sourceBlockHash": "ef56...",
|
|
||||||
"sourceMsgSubType": 10,
|
|
||||||
"sourceText": "close_friend",
|
|
||||||
"targetLogin": "Alice",
|
|
||||||
"targetBlockchainName": "alice-001",
|
|
||||||
"targetBlockNumber": 0,
|
|
||||||
"targetBlockHash": "0000..."
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Примечание
|
|
||||||
|
|
||||||
- `replies` заполняется только для `TEXT_REPLY`.
|
|
||||||
- `events` заполняется только для входящего `CONNECTION_FRIEND` / `close_friend`.
|
|
||||||
- Другие типы связей в эту ленту не попадают.
|
|
||||||
@@ -334,6 +334,25 @@
|
|||||||
|
|
||||||
### 8.2. Новые методы, которые нужны
|
### 8.2. Новые методы, которые нужны
|
||||||
|
|
||||||
|
### 8.3. Серверный слой диалогов
|
||||||
|
|
||||||
|
Помимо хранения самих DM-сообщений сервер поддерживает материализованный слой состояния диалогов:
|
||||||
|
|
||||||
|
- отдельная запись на пару `owner_login` + `peer_login`;
|
||||||
|
- `relation_flag` со значениями `close_friend`, `contact`, `none`;
|
||||||
|
- `last_message_blob_b64` как последний контентный signed DM block в base64;
|
||||||
|
- `last_message_time_ms`;
|
||||||
|
- `unread_count`;
|
||||||
|
- `last_read_receipt_time_ms` как watermark последнего подтверждения прочтения.
|
||||||
|
|
||||||
|
Ключевые правила:
|
||||||
|
|
||||||
|
- `close_friend` всегда имеет приоритет над `contact`;
|
||||||
|
- если `read receipt` приходит не по порядку, сервер хранит наибольший watermark и не откатывает состояние назад;
|
||||||
|
- `unread_count` пересчитывается сервером по сообщениям диалога с учётом watermark и `read_at_ms`;
|
||||||
|
- старые исторические данные восстанавливаются из `signed_messages` при инициализации/миграции;
|
||||||
|
- UI не должен собирать inbox только из локального кеша, когда ему доступен серверный список диалогов.
|
||||||
|
|
||||||
## 9. Правила валидации и применения
|
## 9. Правила валидации и применения
|
||||||
|
|
||||||
### 9.1. Общее правило по ревизиям
|
### 9.1. Общее правило по ревизиям
|
||||||
|
|||||||
@@ -252,6 +252,15 @@ ReadReceiptBody_v1_0
|
|||||||
|
|
||||||
Различается только `messageType` и формат `body`.
|
Различается только `messageType` и формат `body`.
|
||||||
|
|
||||||
|
### Серверное примечание
|
||||||
|
|
||||||
|
Внешний байтовый формат `type=3/4` не меняется, но сервер использует такие контейнеры как вход для обновления `dm_dialog_state`:
|
||||||
|
|
||||||
|
- `read receipt` обновляет серверный watermark диалога;
|
||||||
|
- `unreadCount` пересчитывается на сервере, а не только на клиенте;
|
||||||
|
- если подтверждение прочтения приходит в другом порядке, сервер сохраняет максимальный watermark и не откатывает счётчик назад.
|
||||||
|
- в списке диалогов сервер может отдавать последний signed block как `lastMessageBlobB64` без попытки извлечь plaintext preview.
|
||||||
|
|
||||||
## 9. Контент типов `5/6`
|
## 9. Контент типов `5/6`
|
||||||
|
|
||||||
Типы:
|
Типы:
|
||||||
|
|||||||
+308
-3
@@ -52,8 +52,284 @@ window.__SHINE_BUILD_HASH__ = '20260819190000';
|
|||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
(function attachBootErrorOverlay() {
|
(function attachBootErrorOverlay() {
|
||||||
const show = (title, text) => {
|
const stateKey = '__SHINE_BOOT_ERROR_STATE__';
|
||||||
|
const menuId = 'boot-error-action-sheet';
|
||||||
|
const escapeText = (value) => String(value == null ? '' : value)
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"');
|
||||||
|
const safeString = (value, maxLen = 1000) => {
|
||||||
|
const text = String(value == null ? '' : value).trim();
|
||||||
|
if (text.length <= maxLen) return text;
|
||||||
|
return `${text.slice(0, Math.max(0, maxLen - 3))}...`;
|
||||||
|
};
|
||||||
|
const setState = (next) => {
|
||||||
try {
|
try {
|
||||||
|
window[stateKey] = next;
|
||||||
|
} catch {}
|
||||||
|
};
|
||||||
|
const getState = () => {
|
||||||
|
try {
|
||||||
|
return window[stateKey] || null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const getKnownClientError = () => {
|
||||||
|
try {
|
||||||
|
return typeof window.__SHINE_GET_LAST_CLIENT_ERROR__ === 'function'
|
||||||
|
? window.__SHINE_GET_LAST_CLIENT_ERROR__()
|
||||||
|
: null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const showFeedback = (message, kind = 'success') => {
|
||||||
|
try {
|
||||||
|
if (typeof window.__SHINE_SHOW_TOAST__ === 'function') {
|
||||||
|
window.__SHINE_SHOW_TOAST__(message, kind);
|
||||||
|
} else {
|
||||||
|
console.info(message);
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
};
|
||||||
|
const buildReport = () => {
|
||||||
|
const state = getState() || {};
|
||||||
|
const known = getKnownClientError();
|
||||||
|
const viewport = {
|
||||||
|
width: Math.round(window.innerWidth || 0),
|
||||||
|
height: Math.round(window.innerHeight || 0),
|
||||||
|
dpr: Number(window.devicePixelRatio || 1),
|
||||||
|
visualWidth: Math.round(window.visualViewport?.width || 0),
|
||||||
|
visualHeight: Math.round(window.visualViewport?.height || 0),
|
||||||
|
visualScale: Number(window.visualViewport?.scale || 1),
|
||||||
|
};
|
||||||
|
const screenInfo = window.screen ? {
|
||||||
|
width: Math.round(window.screen.width || 0),
|
||||||
|
height: Math.round(window.screen.height || 0),
|
||||||
|
availWidth: Math.round(window.screen.availWidth || 0),
|
||||||
|
availHeight: Math.round(window.screen.availHeight || 0),
|
||||||
|
pixelDepth: Number(window.screen.pixelDepth || 0),
|
||||||
|
} : null;
|
||||||
|
return {
|
||||||
|
kind: safeString(state.kind || 'boot_error', 64),
|
||||||
|
title: safeString(state.title || 'BOOT ERROR', 128),
|
||||||
|
message: safeString(state.message || '', 500),
|
||||||
|
stack: safeString(state.stack || '', 8000),
|
||||||
|
sourceUrl: safeString(state.sourceUrl || '', 240),
|
||||||
|
lineNumber: Number.isFinite(state.lineNumber) ? state.lineNumber : null,
|
||||||
|
columnNumber: Number.isFinite(state.columnNumber) ? state.columnNumber : null,
|
||||||
|
reasonType: safeString(state.reasonType || '', 64),
|
||||||
|
route: safeString(window.location.hash || window.location.pathname || '', 200),
|
||||||
|
href: safeString(window.location.href || '', 240),
|
||||||
|
pageTitle: safeString(document.title || '', 200),
|
||||||
|
pageVisibility: safeString(document.visibilityState || '', 32),
|
||||||
|
userAgent: safeString(navigator.userAgent || '', 240),
|
||||||
|
locale: safeString(navigator.language || '', 32),
|
||||||
|
clientTs: Number.isFinite(state.clientTs) ? state.clientTs : Date.now(),
|
||||||
|
viewport,
|
||||||
|
screenInfo,
|
||||||
|
lastKnownClientError: known || null,
|
||||||
|
contextJson: safeString(JSON.stringify({
|
||||||
|
bootState: state,
|
||||||
|
currentRoute: window.location.hash || window.location.pathname || '',
|
||||||
|
hasClientErrorSender: typeof window.__SHINE_SEND_CLIENT_ERROR__ === 'function',
|
||||||
|
}), 2000),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
const buildSendPayload = (report) => {
|
||||||
|
const payload = {
|
||||||
|
kind: safeString(report?.kind || 'boot_error', 64),
|
||||||
|
message: safeString(report?.message || report?.title || 'Неизвестная ошибка', 500),
|
||||||
|
stack: safeString(report?.stack || '', 8000),
|
||||||
|
sourceUrl: safeString(report?.sourceUrl || '', 240),
|
||||||
|
lineNumber: Number.isFinite(report?.lineNumber) ? report.lineNumber : null,
|
||||||
|
columnNumber: Number.isFinite(report?.columnNumber) ? report.columnNumber : null,
|
||||||
|
route: safeString(report?.route || '', 200),
|
||||||
|
href: safeString(report?.href || '', 240),
|
||||||
|
userAgent: safeString(report?.userAgent || '', 240),
|
||||||
|
clientTs: Number.isFinite(report?.clientTs) ? report.clientTs : Date.now(),
|
||||||
|
requestOp: '',
|
||||||
|
requestIdRef: '',
|
||||||
|
contextJson: safeString(JSON.stringify({
|
||||||
|
...report,
|
||||||
|
contextJson: undefined,
|
||||||
|
}), 2000),
|
||||||
|
};
|
||||||
|
return payload;
|
||||||
|
};
|
||||||
|
const shareErrorText = async (report) => {
|
||||||
|
const text = formatReportText(report);
|
||||||
|
if (!text) throw new Error('Текст ошибки пуст');
|
||||||
|
if (!navigator.share) {
|
||||||
|
throw new Error('Отправка через системное меню недоступна в этом браузере');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await navigator.share({
|
||||||
|
title: report?.title || 'Описание ошибки',
|
||||||
|
text,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
if (error?.name === 'AbortError') return false;
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
const formatReportText = (report) => {
|
||||||
|
const lines = [
|
||||||
|
`Ошибка: ${report.title || report.kind || 'unknown'}`,
|
||||||
|
`Описание: ${report.message || '—'}`,
|
||||||
|
`Окно: ${report.pageTitle || '—'}`,
|
||||||
|
`Маршрут: ${report.route || '—'}`,
|
||||||
|
`URL: ${report.href || '—'}`,
|
||||||
|
`Видимость: ${report.pageVisibility || '—'}`,
|
||||||
|
`Время: ${new Date(Number(report.clientTs || Date.now())).toISOString()}`,
|
||||||
|
`UA: ${report.userAgent || '—'}`,
|
||||||
|
`Экран: ${report.viewport ? `${report.viewport.width}x${report.viewport.height} @${report.viewport.dpr || 1}x` : '—'}`,
|
||||||
|
`Монитор: ${report.screenInfo ? `${report.screenInfo.width}x${report.screenInfo.height}` : '—'}`,
|
||||||
|
`Источник: ${report.sourceUrl || '—'}`,
|
||||||
|
`Строка: ${Number.isFinite(report.lineNumber) ? report.lineNumber : '—'}`,
|
||||||
|
`Колонка: ${Number.isFinite(report.columnNumber) ? report.columnNumber : '—'}`,
|
||||||
|
`Тип причины: ${report.reasonType || '—'}`,
|
||||||
|
];
|
||||||
|
if (report.stack) {
|
||||||
|
lines.push('Stack:', report.stack);
|
||||||
|
}
|
||||||
|
if (report.lastKnownClientError) {
|
||||||
|
lines.push('Последняя известная ошибка:', JSON.stringify(report.lastKnownClientError, null, 2));
|
||||||
|
}
|
||||||
|
if (report.contextJson) {
|
||||||
|
lines.push('Контекст:', report.contextJson);
|
||||||
|
}
|
||||||
|
return lines.join('\n');
|
||||||
|
};
|
||||||
|
const copyText = async (text) => {
|
||||||
|
const value = String(text || '');
|
||||||
|
if (!value) return false;
|
||||||
|
if (navigator.clipboard?.writeText) {
|
||||||
|
await navigator.clipboard.writeText(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const ta = document.createElement('textarea');
|
||||||
|
ta.value = value;
|
||||||
|
ta.setAttribute('readonly', 'readonly');
|
||||||
|
ta.style.position = 'fixed';
|
||||||
|
ta.style.opacity = '0';
|
||||||
|
ta.style.pointerEvents = 'none';
|
||||||
|
document.body.append(ta);
|
||||||
|
ta.focus();
|
||||||
|
ta.select();
|
||||||
|
const ok = document.execCommand('copy');
|
||||||
|
ta.remove();
|
||||||
|
return !!ok;
|
||||||
|
};
|
||||||
|
const removeMenu = () => {
|
||||||
|
try {
|
||||||
|
document.getElementById(menuId)?.remove();
|
||||||
|
} catch {}
|
||||||
|
};
|
||||||
|
const openMenu = () => {
|
||||||
|
try {
|
||||||
|
removeMenu();
|
||||||
|
const report = buildReport();
|
||||||
|
const root = document.getElementById('modal-root') || document.body;
|
||||||
|
const shell = document.createElement('div');
|
||||||
|
shell.id = menuId;
|
||||||
|
shell.className = 'modal-shell boot-error-menu-shell';
|
||||||
|
shell.innerHTML = `
|
||||||
|
<div class="modal-backdrop" data-action="close"></div>
|
||||||
|
<div class="modal-dialog boot-error-menu-dialog" role="dialog" aria-modal="true" aria-labelledby="boot-error-menu-title" tabindex="-1">
|
||||||
|
<div class="modal-card stack boot-error-menu-card">
|
||||||
|
<strong class="modal-title" id="boot-error-menu-title">Описание ошибки</strong>
|
||||||
|
<p class="meta-muted boot-error-menu-message">${escapeText(report.message || report.title || 'Ошибка')}</p>
|
||||||
|
<button type="button" class="secondary-btn" data-action="copy">Скопировать текст ошибки</button>
|
||||||
|
<button type="button" class="secondary-btn" data-action="share">Отправить текст ошибки</button>
|
||||||
|
<button type="button" class="secondary-btn" data-action="send"${typeof window.__SHINE_SEND_CLIENT_ERROR_TO_SERVER__ === 'function' ? '' : ' disabled'}>Отправить в лог на сервере</button>
|
||||||
|
<button type="button" class="ghost-btn" data-action="close">Закрыть</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
root.append(shell);
|
||||||
|
|
||||||
|
const dialog = shell.querySelector('.modal-dialog');
|
||||||
|
const close = () => {
|
||||||
|
window.removeEventListener('keydown', onKeyDown);
|
||||||
|
shell.remove();
|
||||||
|
};
|
||||||
|
const onKeyDown = (event) => {
|
||||||
|
if (event.key === 'Escape') {
|
||||||
|
event.preventDefault();
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
shell.addEventListener('click', (event) => {
|
||||||
|
if (event.target === shell || event.target?.dataset?.action === 'close') {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
shell.querySelector('[data-action="copy"]')?.addEventListener('click', async () => {
|
||||||
|
try {
|
||||||
|
await copyText(formatReportText(report));
|
||||||
|
showFeedback('Описание ошибки скопировано');
|
||||||
|
} catch {
|
||||||
|
showFeedback('Не удалось скопировать описание ошибки', 'error');
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
});
|
||||||
|
|
||||||
|
shell.querySelector('[data-action="share"]')?.addEventListener('click', async () => {
|
||||||
|
try {
|
||||||
|
const shared = await shareErrorText(report);
|
||||||
|
if (shared === false) return close();
|
||||||
|
showFeedback('Текст ошибки открыт для отправки');
|
||||||
|
} catch (error) {
|
||||||
|
showFeedback(error?.message || 'Не удалось открыть системное меню отправки', 'error');
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
});
|
||||||
|
|
||||||
|
shell.querySelector('[data-action="send"]')?.addEventListener('click', async () => {
|
||||||
|
try {
|
||||||
|
const sender = window.__SHINE_SEND_CLIENT_ERROR_TO_SERVER__;
|
||||||
|
if (typeof sender !== 'function') {
|
||||||
|
throw new Error('Отправка в лог на сервере недоступна');
|
||||||
|
}
|
||||||
|
const ok = await sender(buildSendPayload(report));
|
||||||
|
if (!ok) {
|
||||||
|
throw new Error('Не удалось отправить ошибку в лог на сервере');
|
||||||
|
}
|
||||||
|
showFeedback('Ошибка отправлена в лог на сервере');
|
||||||
|
} catch (error) {
|
||||||
|
showFeedback(error?.message || 'Не удалось отправить ошибку в лог на сервере', 'error');
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
});
|
||||||
|
|
||||||
|
shell.querySelector('[data-action="close"]')?.addEventListener('click', close);
|
||||||
|
dialog?.focus?.();
|
||||||
|
window.addEventListener('keydown', onKeyDown);
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('boot error menu failed', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const show = (title, text, extra = {}) => {
|
||||||
|
try {
|
||||||
|
const reportState = {
|
||||||
|
kind: safeString(extra.kind || title || 'boot_error', 64),
|
||||||
|
title: safeString(title || 'BOOT ERROR', 128),
|
||||||
|
message: safeString(extra.message || text || '', 500),
|
||||||
|
stack: safeString(extra.stack || '', 8000),
|
||||||
|
sourceUrl: safeString(extra.sourceUrl || extra.filename || '', 240),
|
||||||
|
lineNumber: Number.isFinite(extra.lineNumber) ? extra.lineNumber : (Number.isFinite(extra.lineno) ? extra.lineno : null),
|
||||||
|
columnNumber: Number.isFinite(extra.columnNumber) ? extra.columnNumber : (Number.isFinite(extra.colno) ? extra.colno : null),
|
||||||
|
reasonType: safeString(extra.reasonType || '', 64),
|
||||||
|
clientTs: Number.isFinite(extra.clientTs) ? extra.clientTs : Date.now(),
|
||||||
|
};
|
||||||
|
setState(reportState);
|
||||||
|
|
||||||
let el = document.getElementById('boot-error-overlay');
|
let el = document.getElementById('boot-error-overlay');
|
||||||
if (!el) {
|
if (!el) {
|
||||||
el = document.createElement('pre');
|
el = document.createElement('pre');
|
||||||
@@ -72,17 +348,46 @@ window.__SHINE_BUILD_HASH__ = '20260819190000';
|
|||||||
el.style.lineHeight = '1.4';
|
el.style.lineHeight = '1.4';
|
||||||
el.style.zIndex = '999999';
|
el.style.zIndex = '999999';
|
||||||
el.style.whiteSpace = 'pre-wrap';
|
el.style.whiteSpace = 'pre-wrap';
|
||||||
|
el.style.cursor = 'pointer';
|
||||||
|
el.style.userSelect = 'none';
|
||||||
|
el.style.webkitUserSelect = 'none';
|
||||||
|
el.style.touchAction = 'manipulation';
|
||||||
|
el.setAttribute('role', 'button');
|
||||||
|
el.setAttribute('tabindex', '0');
|
||||||
|
el.setAttribute('aria-haspopup', 'dialog');
|
||||||
document.body.appendChild(el);
|
document.body.appendChild(el);
|
||||||
|
el.addEventListener('click', openMenu);
|
||||||
|
el.addEventListener('keydown', (event) => {
|
||||||
|
if (event.key === 'Enter' || event.key === ' ') {
|
||||||
|
event.preventDefault();
|
||||||
|
openMenu();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
el.textContent = `[BOOT ERROR] ${title}\n${String(text || '')}`;
|
el.textContent = `[BOOT ERROR] ${title}\n${String(text || '')}`;
|
||||||
|
el.setAttribute('aria-label', `${title}. Нажмите, чтобы открыть меню действий.`);
|
||||||
|
el.title = 'Нажмите, чтобы открыть меню действий';
|
||||||
} catch {}
|
} catch {}
|
||||||
};
|
};
|
||||||
window.addEventListener('error', (e) => {
|
window.addEventListener('error', (e) => {
|
||||||
show('window.error', `${e?.message || ''}\n${e?.filename || ''}:${e?.lineno || ''}:${e?.colno || ''}`);
|
show('window.error', `${e?.message || ''}\n${e?.filename || ''}:${e?.lineno || ''}:${e?.colno || ''}`, {
|
||||||
|
kind: 'window_error',
|
||||||
|
message: e?.message || '',
|
||||||
|
stack: e?.error?.stack || '',
|
||||||
|
sourceUrl: e?.filename || '',
|
||||||
|
lineNumber: e?.lineno,
|
||||||
|
columnNumber: e?.colno,
|
||||||
|
reasonType: e?.error?.constructor?.name || e?.constructor?.name || 'ErrorEvent',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
window.addEventListener('unhandledrejection', (e) => {
|
window.addEventListener('unhandledrejection', (e) => {
|
||||||
const reason = e?.reason;
|
const reason = e?.reason;
|
||||||
show('unhandledrejection', reason?.stack || reason?.message || String(reason || 'unknown'));
|
show('unhandledrejection', reason?.stack || reason?.message || String(reason || 'unknown'), {
|
||||||
|
kind: 'unhandled_rejection',
|
||||||
|
message: reason?.message || String(reason || 'Unhandled promise rejection'),
|
||||||
|
stack: reason?.stack || '',
|
||||||
|
reasonType: reason?.constructor?.name || typeof reason,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
+10
-1
@@ -5,7 +5,12 @@ import {
|
|||||||
syncTrackedRouteHistory,
|
syncTrackedRouteHistory,
|
||||||
} from './router.js';
|
} from './router.js';
|
||||||
import { renderToolbar } from './components/toolbar.js';
|
import { renderToolbar } from './components/toolbar.js';
|
||||||
import { captureClientError, setClientErrorSentNotifier, setClientErrorTransport } from './services/client-error-reporter.js';
|
import {
|
||||||
|
captureClientError,
|
||||||
|
getLastClientErrorPayload,
|
||||||
|
setClientErrorSentNotifier,
|
||||||
|
setClientErrorTransport,
|
||||||
|
} from './services/client-error-reporter.js';
|
||||||
import { initPwaInstallPromptHandling } from './services/pwa-install-service.js';
|
import { initPwaInstallPromptHandling } from './services/pwa-install-service.js';
|
||||||
import { initPwaPush } from './services/pwa-push-service.js';
|
import { initPwaPush } from './services/pwa-push-service.js';
|
||||||
import { initCallUiOverlay } from './services/call-ui-service.js';
|
import { initCallUiOverlay } from './services/call-ui-service.js';
|
||||||
@@ -208,6 +213,10 @@ setClientErrorSentNotifier((payload) => {
|
|||||||
const isoTs = new Date(Number(payload?.clientTs || Date.now())).toISOString();
|
const isoTs = new Date(Number(payload?.clientTs || Date.now())).toISOString();
|
||||||
showToast(`Ошибка отправлена на сервер · ${login} · ${isoTs}`);
|
showToast(`Ошибка отправлена на сервер · ${login} · ${isoTs}`);
|
||||||
});
|
});
|
||||||
|
window.__SHINE_SEND_CLIENT_ERROR_TO_SERVER__ = (payload) => authService.reportClientError(payload);
|
||||||
|
window.__SHINE_SEND_CLIENT_ERROR__ = window.__SHINE_SEND_CLIENT_ERROR_TO_SERVER__;
|
||||||
|
window.__SHINE_GET_LAST_CLIENT_ERROR__ = () => getLastClientErrorPayload();
|
||||||
|
window.__SHINE_SHOW_TOAST__ = (message, kind = 'success') => showToast(message, { kind });
|
||||||
initPwaInstallPromptHandling();
|
initPwaInstallPromptHandling();
|
||||||
initCallUiOverlay();
|
initCallUiOverlay();
|
||||||
setCallDebugReporter((payload) => authService.reportClientDebug(payload));
|
setCallDebugReporter((payload) => authService.reportClientDebug(payload));
|
||||||
|
|||||||
@@ -237,9 +237,200 @@ function buildThreadRoute(messageRef, selector) {
|
|||||||
function buildChannelSettingsKey(ownerBlockchainName, channelName) {
|
function buildChannelSettingsKey(ownerBlockchainName, channelName) {
|
||||||
const ownerBch = String(ownerBlockchainName || '').trim();
|
const ownerBch = String(ownerBlockchainName || '').trim();
|
||||||
const name = String(channelName || '').trim();
|
const name = String(channelName || '').trim();
|
||||||
|
if (!ownerBch || !name) return '';
|
||||||
return `${ownerBch}/${name}`;
|
return `${ownerBch}/${name}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getChannelScrollRoot() {
|
||||||
|
return document.getElementById('app-screen');
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollRootBy(delta, smooth = false) {
|
||||||
|
const root = getChannelScrollRoot();
|
||||||
|
const behavior = smooth ? 'smooth' : 'auto';
|
||||||
|
if (root && typeof root.scrollBy === 'function') {
|
||||||
|
root.scrollBy({ top: delta, behavior });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.scrollBy({ top: delta, behavior });
|
||||||
|
}
|
||||||
|
|
||||||
|
function getUnreadAnchorViewportFraction(unreadCount = 0) {
|
||||||
|
const count = Math.max(0, Number(unreadCount || 0));
|
||||||
|
if (count <= 1) return 0.68;
|
||||||
|
if (count <= 3) return 0.56;
|
||||||
|
if (count <= 7) return 0.48;
|
||||||
|
return 0.42;
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollElementToViewportFraction(element, fraction = 1 / 3, smooth = false) {
|
||||||
|
if (!element) return false;
|
||||||
|
const root = getChannelScrollRoot();
|
||||||
|
const viewportHeight = root?.clientHeight || window.innerHeight || document.documentElement.clientHeight || 0;
|
||||||
|
const targetTop = Math.max(0, Math.round(viewportHeight * fraction));
|
||||||
|
const rect = element.getBoundingClientRect();
|
||||||
|
const delta = rect.top - targetTop;
|
||||||
|
if (Math.abs(delta) < 2) return true;
|
||||||
|
scrollRootBy(delta, smooth);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollChannelToUnreadLine(screen, unreadCount = 0, smooth = false) {
|
||||||
|
return scrollElementToViewportFraction(
|
||||||
|
screen.querySelector('.channel-unread-line'),
|
||||||
|
getUnreadAnchorViewportFraction(unreadCount),
|
||||||
|
smooth,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createChannelReadTracker({
|
||||||
|
screen,
|
||||||
|
routeKey,
|
||||||
|
settingKey,
|
||||||
|
unreadCount,
|
||||||
|
messagesCount,
|
||||||
|
initialSeenCount,
|
||||||
|
}) {
|
||||||
|
const login = String(state.session.login || '').trim();
|
||||||
|
const storagePwd = state.session.storagePwdInMemory;
|
||||||
|
const canWrite = !!(settingKey && login && storagePwd);
|
||||||
|
const safeMessagesCount = Math.max(0, Number(messagesCount || 0));
|
||||||
|
const safeInitialSeenCount = Math.max(0, Math.min(Number(initialSeenCount || 0), safeMessagesCount));
|
||||||
|
const unreadLine = unreadCount > 0 ? screen.querySelector('.channel-unread-line') : null;
|
||||||
|
const unreadAnchorFraction = getUnreadAnchorViewportFraction(unreadCount);
|
||||||
|
|
||||||
|
let desiredSeenCount = safeInitialSeenCount;
|
||||||
|
let persistedSeenCount = safeInitialSeenCount;
|
||||||
|
let inFlight = false;
|
||||||
|
let disposed = false;
|
||||||
|
let rafId = 0;
|
||||||
|
let timerId = 0;
|
||||||
|
|
||||||
|
const clearTimer = () => {
|
||||||
|
if (timerId) {
|
||||||
|
clearTimeout(timerId);
|
||||||
|
timerId = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const queueFlush = (delayMs = 180) => {
|
||||||
|
if (disposed || !canWrite) return;
|
||||||
|
clearTimer();
|
||||||
|
timerId = setTimeout(() => {
|
||||||
|
timerId = 0;
|
||||||
|
void flush();
|
||||||
|
}, Math.max(0, Number(delayMs) || 0));
|
||||||
|
};
|
||||||
|
|
||||||
|
const flush = async () => {
|
||||||
|
if (disposed || !canWrite) return;
|
||||||
|
const next = Math.max(safeInitialSeenCount, Math.min(desiredSeenCount, safeMessagesCount));
|
||||||
|
if (next <= persistedSeenCount) return;
|
||||||
|
if (inFlight) {
|
||||||
|
queueFlush(120);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
inFlight = true;
|
||||||
|
try {
|
||||||
|
await authService.upsertUserSetting({
|
||||||
|
login,
|
||||||
|
settingType: 1,
|
||||||
|
settingKey,
|
||||||
|
timeMs: Date.now(),
|
||||||
|
valueText: '',
|
||||||
|
valueNum: next,
|
||||||
|
storagePwd,
|
||||||
|
});
|
||||||
|
persistedSeenCount = next;
|
||||||
|
} catch {
|
||||||
|
queueFlush(800);
|
||||||
|
} finally {
|
||||||
|
inFlight = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const collectSeenCount = () => {
|
||||||
|
const cards = Array.from(screen.querySelectorAll('.channel-message-card[data-local-number]'));
|
||||||
|
if (!cards.length) return safeInitialSeenCount;
|
||||||
|
if (!unreadLine) return safeMessagesCount;
|
||||||
|
|
||||||
|
const root = getChannelScrollRoot();
|
||||||
|
const viewportHeight = root?.clientHeight || window.innerHeight || document.documentElement.clientHeight || 0;
|
||||||
|
const thresholdTop = Math.max(0, Math.round(viewportHeight * unreadAnchorFraction));
|
||||||
|
let seen = safeInitialSeenCount;
|
||||||
|
for (const card of cards) {
|
||||||
|
const localNumber = Number(card.dataset.localNumber || 0);
|
||||||
|
if (!Number.isFinite(localNumber) || localNumber <= 0) continue;
|
||||||
|
const rect = card.getBoundingClientRect();
|
||||||
|
if (rect.top > thresholdTop + 1) break;
|
||||||
|
seen = Math.max(seen, localNumber);
|
||||||
|
}
|
||||||
|
return Math.max(safeInitialSeenCount, Math.min(seen, safeMessagesCount));
|
||||||
|
};
|
||||||
|
|
||||||
|
const measure = () => {
|
||||||
|
if (disposed) return;
|
||||||
|
if (rafId) return;
|
||||||
|
rafId = window.requestAnimationFrame(() => {
|
||||||
|
rafId = 0;
|
||||||
|
const next = collectSeenCount();
|
||||||
|
if (next > desiredSeenCount) {
|
||||||
|
desiredSeenCount = next;
|
||||||
|
queueFlush(180);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const scrollRoot = getChannelScrollRoot();
|
||||||
|
const onScroll = () => measure();
|
||||||
|
const onResize = () => measure();
|
||||||
|
|
||||||
|
if (scrollRoot && typeof scrollRoot.addEventListener === 'function') {
|
||||||
|
scrollRoot.addEventListener('scroll', onScroll, { passive: true });
|
||||||
|
} else {
|
||||||
|
window.addEventListener('scroll', onScroll, { passive: true });
|
||||||
|
}
|
||||||
|
window.addEventListener('resize', onResize);
|
||||||
|
|
||||||
|
const initialSyncRequired = canWrite && unreadCount <= 0 && safeMessagesCount >= 0;
|
||||||
|
if (initialSyncRequired) {
|
||||||
|
void authService.upsertUserSetting({
|
||||||
|
login,
|
||||||
|
settingType: 1,
|
||||||
|
settingKey,
|
||||||
|
timeMs: Date.now(),
|
||||||
|
valueText: '',
|
||||||
|
valueNum: safeMessagesCount,
|
||||||
|
storagePwd,
|
||||||
|
}).catch(() => {});
|
||||||
|
persistedSeenCount = safeMessagesCount;
|
||||||
|
desiredSeenCount = safeMessagesCount;
|
||||||
|
} else {
|
||||||
|
window.setTimeout(() => measure(), 120);
|
||||||
|
}
|
||||||
|
|
||||||
|
const cleanup = () => {
|
||||||
|
disposed = true;
|
||||||
|
clearTimer();
|
||||||
|
if (rafId) {
|
||||||
|
window.cancelAnimationFrame(rafId);
|
||||||
|
rafId = 0;
|
||||||
|
}
|
||||||
|
if (scrollRoot && typeof scrollRoot.removeEventListener === 'function') {
|
||||||
|
scrollRoot.removeEventListener('scroll', onScroll);
|
||||||
|
} else {
|
||||||
|
window.removeEventListener('scroll', onScroll);
|
||||||
|
}
|
||||||
|
window.removeEventListener('resize', onResize);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
cleanup,
|
||||||
|
measure,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function firstNonEmptyText(...candidates) {
|
function firstNonEmptyText(...candidates) {
|
||||||
for (const candidate of candidates) {
|
for (const candidate of candidates) {
|
||||||
if (typeof candidate !== 'string') continue;
|
if (typeof candidate !== 'string') continue;
|
||||||
@@ -1447,6 +1638,7 @@ async function loadFromApi(route, channelId) {
|
|||||||
return {
|
return {
|
||||||
channel: {
|
channel: {
|
||||||
name: payload.channel?.channelName || 'неизвестный канал',
|
name: payload.channel?.channelName || 'неизвестный канал',
|
||||||
|
ownerBlockchainName: String(payload.channel?.ownerBlockchainName || '').trim(),
|
||||||
displayTitle: String(payload.channel?.displayName || payload.channel?.channelName || 'неизвестный канал').trim(),
|
displayTitle: String(payload.channel?.displayName || payload.channel?.channelName || 'неизвестный канал').trim(),
|
||||||
displayName: `${ownerLogin || 'неизвестно'}/${payload.channel?.channelName || 'неизвестный канал'}`,
|
displayName: `${ownerLogin || 'неизвестно'}/${payload.channel?.channelName || 'неизвестный канал'}`,
|
||||||
description: String(payload.channel?.channelDescription || '').trim(),
|
description: String(payload.channel?.channelDescription || '').trim(),
|
||||||
@@ -1749,6 +1941,9 @@ function renderPostCard(post, {
|
|||||||
if (refKey) {
|
if (refKey) {
|
||||||
card.dataset.messageKey = refKey;
|
card.dataset.messageKey = refKey;
|
||||||
}
|
}
|
||||||
|
if (Number.isFinite(Number(post.localNumber)) && Number(post.localNumber) > 0) {
|
||||||
|
card.dataset.localNumber = String(Number(post.localNumber));
|
||||||
|
}
|
||||||
card.classList.add('is-counters-visible');
|
card.classList.add('is-counters-visible');
|
||||||
|
|
||||||
if (!post.messageRef || !selector) return card;
|
if (!post.messageRef || !selector) return card;
|
||||||
@@ -1914,6 +2109,10 @@ function renderPostCard(post, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderBody(screen, navigate, routeKey, channelData, handlers) {
|
function renderBody(screen, navigate, routeKey, channelData, handlers) {
|
||||||
|
const unreadCount = Math.max(0, Number(channelData.unreadCount || 0));
|
||||||
|
const messagesCount = Math.max(0, Number(channelData.messagesCount || (Array.isArray(channelData.posts) ? channelData.posts.length : 0) || 0));
|
||||||
|
const readCount = Math.max(0, messagesCount - unreadCount);
|
||||||
|
|
||||||
if (channelData.reverseChannelMissingWarning) {
|
if (channelData.reverseChannelMissingWarning) {
|
||||||
const reverseWarning = document.createElement('p');
|
const reverseWarning = document.createElement('p');
|
||||||
reverseWarning.className = 'channel-head-meta';
|
reverseWarning.className = 'channel-head-meta';
|
||||||
@@ -1921,13 +2120,6 @@ function renderBody(screen, navigate, routeKey, channelData, handlers) {
|
|||||||
screen.append(reverseWarning);
|
screen.append(reverseWarning);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Number(channelData.unreadCount || 0) > 0) {
|
|
||||||
const unreadLine = document.createElement('div');
|
|
||||||
unreadLine.className = 'card channel-unread-line';
|
|
||||||
unreadLine.textContent = `Не прочитано: ${channelData.unreadCount}`;
|
|
||||||
screen.append(unreadLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
const actionButton = document.createElement('button');
|
const actionButton = document.createElement('button');
|
||||||
actionButton.className = 'destructive-btn channel-main-action';
|
actionButton.className = 'destructive-btn channel-main-action';
|
||||||
actionButton.textContent = 'Подписаться на канал';
|
actionButton.textContent = 'Подписаться на канал';
|
||||||
@@ -1946,6 +2138,7 @@ function renderBody(screen, navigate, routeKey, channelData, handlers) {
|
|||||||
const postsByKey = new Map();
|
const postsByKey = new Map();
|
||||||
const metaEvents = (Array.isArray(channelData.metaEvents) ? channelData.metaEvents : [])
|
const metaEvents = (Array.isArray(channelData.metaEvents) ? channelData.metaEvents : [])
|
||||||
.map((event) => mapChannelMetaEvent(event, channelData.channel));
|
.map((event) => mapChannelMetaEvent(event, channelData.channel));
|
||||||
|
let unreadLineInserted = unreadCount === 0;
|
||||||
const feedItems = [
|
const feedItems = [
|
||||||
...metaEvents.map((event) => ({
|
...metaEvents.map((event) => ({
|
||||||
type: 'meta',
|
type: 'meta',
|
||||||
@@ -1967,6 +2160,13 @@ function renderBody(screen, navigate, routeKey, channelData, handlers) {
|
|||||||
|
|
||||||
if (feedItems.length) {
|
if (feedItems.length) {
|
||||||
feedItems.forEach((item) => {
|
feedItems.forEach((item) => {
|
||||||
|
if (!unreadLineInserted && item.type === 'post' && Number(item?.post?.localNumber || 0) > readCount) {
|
||||||
|
const unreadLine = document.createElement('div');
|
||||||
|
unreadLine.className = 'card channel-unread-line';
|
||||||
|
unreadLine.textContent = 'Не прочитанные сообщения';
|
||||||
|
feed.append(unreadLine);
|
||||||
|
unreadLineInserted = true;
|
||||||
|
}
|
||||||
if (item.type === 'meta') {
|
if (item.type === 'meta') {
|
||||||
feed.append(renderChannelMetaEventCard(item.event));
|
feed.append(renderChannelMetaEventCard(item.event));
|
||||||
return;
|
return;
|
||||||
@@ -2018,10 +2218,25 @@ function renderBody(screen, navigate, routeKey, channelData, handlers) {
|
|||||||
screen.append(feed, backButton);
|
screen.append(feed, backButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
applyPendingScroll(screen, routeKey, channelData.isOwnChannel || channelData.isDiary || Number(channelData.unreadCount || 0) === 0);
|
const hasPendingScrollTarget = pendingScrollByRoute.has(routeKey);
|
||||||
return () => {
|
applyPendingScroll(screen, routeKey, channelData.isOwnChannel || channelData.isDiary || unreadCount === 0);
|
||||||
// noop
|
if (!hasPendingScrollTarget && unreadCount > 0 && !channelData.isOwnChannel && !channelData.isDiary) {
|
||||||
};
|
window.setTimeout(() => scrollChannelToUnreadLine(screen, unreadCount, false), 40);
|
||||||
|
}
|
||||||
|
|
||||||
|
const tracker = createChannelReadTracker({
|
||||||
|
screen,
|
||||||
|
routeKey,
|
||||||
|
settingKey: buildChannelSettingsKey(
|
||||||
|
channelData.channel?.ownerBlockchainName || channelData.selector?.ownerBlockchainName,
|
||||||
|
channelData.channel?.name || channelData.channel?.channelName,
|
||||||
|
),
|
||||||
|
unreadCount,
|
||||||
|
messagesCount,
|
||||||
|
initialSeenCount: readCount,
|
||||||
|
});
|
||||||
|
|
||||||
|
return tracker.cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderSkeleton(screen) {
|
function renderSkeleton(screen) {
|
||||||
@@ -2317,19 +2532,6 @@ export function render({ navigate, route, chrome }) {
|
|||||||
try {
|
try {
|
||||||
const apiData = await loadFromApi(route, channelId);
|
const apiData = await loadFromApi(route, channelId);
|
||||||
activeSelector = apiData?.selector || null;
|
activeSelector = apiData?.selector || null;
|
||||||
const lastSeenCount = Number(apiData?.messagesCount || (Array.isArray(apiData?.posts) ? apiData.posts.length : 0) || 0);
|
|
||||||
const settingKey = buildChannelSettingsKey(apiData?.channel?.ownerBlockchainName, apiData?.channel?.name);
|
|
||||||
if (settingKey && state.session.login && state.session.storagePwdInMemory) {
|
|
||||||
void authService.upsertUserSetting({
|
|
||||||
login: state.session.login,
|
|
||||||
settingType: 1,
|
|
||||||
settingKey,
|
|
||||||
timeMs: Date.now(),
|
|
||||||
valueText: '',
|
|
||||||
valueNum: lastSeenCount,
|
|
||||||
storagePwd: state.session.storagePwdInMemory,
|
|
||||||
}).catch(() => {});
|
|
||||||
}
|
|
||||||
const titleLabel = apiData?.channel?.displayTitle || apiData?.channel?.name || 'channel';
|
const titleLabel = apiData?.channel?.displayTitle || apiData?.channel?.name || 'channel';
|
||||||
const entrypointPosts = getEntrypointPosts(apiData?.posts);
|
const entrypointPosts = getEntrypointPosts(apiData?.posts);
|
||||||
const openEntrypointHistory = () => {
|
const openEntrypointHistory = () => {
|
||||||
|
|||||||
@@ -1219,7 +1219,6 @@ function renderListContent({ screen, container, listState, navigate, refreshFeed
|
|||||||
|
|
||||||
const main = renderChannelMain(channel);
|
const main = renderChannelMain(channel);
|
||||||
|
|
||||||
const isGuest = !state.session.isAuthorized;
|
|
||||||
const controls = document.createElement('div');
|
const controls = document.createElement('div');
|
||||||
controls.className = 'channel-row-controls';
|
controls.className = 'channel-row-controls';
|
||||||
|
|
||||||
@@ -1230,38 +1229,11 @@ function renderListContent({ screen, container, listState, navigate, refreshFeed
|
|||||||
const count = document.createElement('span');
|
const count = document.createElement('span');
|
||||||
count.className = 'unread channel-row-count';
|
count.className = 'unread channel-row-count';
|
||||||
const unreadCount = Number(channel.unreadCount || 0);
|
const unreadCount = Number(channel.unreadCount || 0);
|
||||||
count.textContent = unreadCount > 0 ? String(unreadCount) : '';
|
if (unreadCount > 0) {
|
||||||
count.classList.toggle('is-empty', unreadCount <= 0);
|
count.textContent = unreadCount > 99 ? '99+' : String(unreadCount);
|
||||||
|
controls.append(count);
|
||||||
if (!isGuest) {
|
|
||||||
const menuButton = document.createElement('button');
|
|
||||||
menuButton.type = 'button';
|
|
||||||
menuButton.className = 'channel-menu-trigger';
|
|
||||||
menuButton.textContent = '…';
|
|
||||||
menuButton.addEventListener('click', (event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
animatePress(menuButton);
|
|
||||||
listState.revealedCounters.add(channel.id);
|
|
||||||
|
|
||||||
if (listState.openMenuId === channel.id) {
|
|
||||||
closeChannelMenu(listState);
|
|
||||||
rerenderList();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
controls.append(time);
|
||||||
listState.openMenuId = channel.id;
|
|
||||||
openChannelMenu({
|
|
||||||
listState,
|
|
||||||
channel,
|
|
||||||
anchorEl: menuButton,
|
|
||||||
refreshFeed: async () => loadFeedAndRender({ screen, listState, contentEl: container, navigate }),
|
|
||||||
rerenderList,
|
|
||||||
});
|
|
||||||
rerenderList();
|
|
||||||
});
|
|
||||||
controls.append(menuButton);
|
|
||||||
}
|
|
||||||
controls.append(time, count);
|
|
||||||
|
|
||||||
row.append(avatar, main, controls);
|
row.append(avatar, main, controls);
|
||||||
row.addEventListener('click', () => {
|
row.addEventListener('click', () => {
|
||||||
@@ -1278,14 +1250,6 @@ function renderListContent({ screen, container, listState, navigate, refreshFeed
|
|||||||
container.append(list);
|
container.append(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateBottomCta({ button }) {
|
|
||||||
if (!button) return;
|
|
||||||
button.hidden = true;
|
|
||||||
button.textContent = '';
|
|
||||||
button.className = 'channels-bottom-action';
|
|
||||||
button.onclick = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadFeedAndRender({ screen, listState, contentEl, navigate }) {
|
async function loadFeedAndRender({ screen, listState, contentEl, navigate }) {
|
||||||
closeChannelMenu(listState);
|
closeChannelMenu(listState);
|
||||||
renderSkeletonList(contentEl, 5);
|
renderSkeletonList(contentEl, 5);
|
||||||
@@ -1431,9 +1395,6 @@ export function render({ navigate, route, chrome }) {
|
|||||||
topBarRight.append(findChannelBtn, createInMyBtn, topMenuBtn);
|
topBarRight.append(findChannelBtn, createInMyBtn, topMenuBtn);
|
||||||
topBarEl.append(topBarLeft, topBarRight);
|
topBarEl.append(topBarLeft, topBarRight);
|
||||||
|
|
||||||
const bottomCta = document.createElement('button');
|
|
||||||
bottomCta.type = 'button';
|
|
||||||
|
|
||||||
const reloadFeed = async () => loadFeedAndRender({ screen, listState, contentEl, navigate });
|
const reloadFeed = async () => loadFeedAndRender({ screen, listState, contentEl, navigate });
|
||||||
|
|
||||||
const rerenderList = () => {
|
const rerenderList = () => {
|
||||||
@@ -1454,19 +1415,15 @@ export function render({ navigate, route, chrome }) {
|
|||||||
createInMyBtn.style.display = '';
|
createInMyBtn.style.display = '';
|
||||||
topMenuBtn.style.display = '';
|
topMenuBtn.style.display = '';
|
||||||
if (topTitle.parentElement !== topBarLeft) topBarLeft.append(topTitle);
|
if (topTitle.parentElement !== topBarLeft) topBarLeft.append(topTitle);
|
||||||
|
|
||||||
updateBottomCta({ button: bottomCta });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
chrome?.setTopbar(topBarEl);
|
chrome?.setTopbar(topBarEl);
|
||||||
screen.append(contentEl, bottomCta);
|
screen.append(contentEl);
|
||||||
|
|
||||||
if (createSuccessFlash) {
|
if (createSuccessFlash) {
|
||||||
showToast(createSuccessFlash);
|
showToast(createSuccessFlash);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBottomCta({ button: bottomCta });
|
|
||||||
|
|
||||||
// Применяем корректное состояние хедера сразу на первом рендере,
|
// Применяем корректное состояние хедера сразу на первом рендере,
|
||||||
// чтобы не показывать лишние кнопки до первой перерисовки.
|
// чтобы не показывать лишние кнопки до первой перерисовки.
|
||||||
rerenderList();
|
rerenderList();
|
||||||
|
|||||||
@@ -1,21 +1,28 @@
|
|||||||
import { directMessages } from '../mock-data.js';
|
|
||||||
import {
|
import {
|
||||||
getChatMessages,
|
authService,
|
||||||
isSessionInvalidError,
|
isSessionInvalidError,
|
||||||
normalizeDmChatId,
|
normalizeDmChatId,
|
||||||
setContacts,
|
setContacts,
|
||||||
state,
|
state,
|
||||||
terminateCurrentSession,
|
terminateCurrentSession,
|
||||||
} from '../state.js';
|
} from '../state.js';
|
||||||
import { loadCurrentRelations } from '../services/user-connections.js';
|
|
||||||
import { renderUserAvatar } from '../components/avatar-image.js';
|
import { renderUserAvatar } from '../components/avatar-image.js';
|
||||||
import { loadProfileSnapshot } from '../services/user-profile-params.js';
|
import { loadProfileSnapshot } from '../services/user-profile-params.js';
|
||||||
import { parseDmTechBlocks } from '../services/dm-tech-blocks.js';
|
import { parseDmTechBlocks } from '../services/dm-tech-blocks.js';
|
||||||
|
|
||||||
export const pageMeta = { id: 'messages-list', title: 'Личные сообщения' };
|
export const pageMeta = { id: 'messages-list', title: 'Личные сообщения' };
|
||||||
|
const PREVIEW_MAX_LEN = 200;
|
||||||
|
const DM_BLOB_PREVIEW_CACHE = new Map();
|
||||||
|
const DM_BLOB_PREVIEW_PENDING = new Map();
|
||||||
const dmAvatarSnapshotCache = new Map();
|
const dmAvatarSnapshotCache = new Map();
|
||||||
const dmAvatarPendingByLogin = new Map();
|
const dmAvatarPendingByLogin = new Map();
|
||||||
|
|
||||||
|
const RELATION_ORDER = new Map([
|
||||||
|
['close_friend', 0],
|
||||||
|
['contact', 1],
|
||||||
|
['none', 2],
|
||||||
|
]);
|
||||||
|
|
||||||
async function loadDmAvatarSnapshot(login) {
|
async function loadDmAvatarSnapshot(login) {
|
||||||
const cleanLogin = String(login || '').trim();
|
const cleanLogin = String(login || '').trim();
|
||||||
if (!cleanLogin) return null;
|
if (!cleanLogin) return null;
|
||||||
@@ -65,10 +72,72 @@ function createDmAvatar(login) {
|
|||||||
return avatarEl;
|
return avatarEl;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveLastMessagePreview(text = '') {
|
function normalizeRelationFlag(value) {
|
||||||
const parsed = parseDmTechBlocks(String(text || ''));
|
const clean = String(value || '').trim().toLowerCase();
|
||||||
const display = String(parsed.displayText || '').trim();
|
if (clean === 'close_friend' || clean === 'contact') return clean;
|
||||||
return display || '';
|
return 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
function relationOrder(flag) {
|
||||||
|
return RELATION_ORDER.get(normalizeRelationFlag(flag)) ?? 99;
|
||||||
|
}
|
||||||
|
|
||||||
|
function relationLabel(flag) {
|
||||||
|
switch (normalizeRelationFlag(flag)) {
|
||||||
|
case 'close_friend':
|
||||||
|
return 'близкий друг';
|
||||||
|
case 'contact':
|
||||||
|
return 'контакт';
|
||||||
|
default:
|
||||||
|
return 'не в контактах';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clipPreviewText(text, maxLen = PREVIEW_MAX_LEN) {
|
||||||
|
const normalized = String(text || '').replace(/\s+/g, ' ').trim();
|
||||||
|
if (!normalized) return '';
|
||||||
|
if (normalized.length <= maxLen) return normalized;
|
||||||
|
return `${normalized.slice(0, maxLen - 1)}…`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resolveDialogPreview(dialog) {
|
||||||
|
const blobB64 = String(dialog?.lastMessageBlobB64 || '').trim();
|
||||||
|
if (!blobB64) return 'Диалог пока пуст.';
|
||||||
|
|
||||||
|
const cacheKey = [
|
||||||
|
blobB64,
|
||||||
|
String(state.session.login || '').trim().toLowerCase(),
|
||||||
|
String(state.session.storagePwdInMemory || '').trim(),
|
||||||
|
].join('|');
|
||||||
|
|
||||||
|
if (DM_BLOB_PREVIEW_CACHE.has(cacheKey)) return DM_BLOB_PREVIEW_CACHE.get(cacheKey);
|
||||||
|
if (DM_BLOB_PREVIEW_PENDING.has(cacheKey)) return DM_BLOB_PREVIEW_PENDING.get(cacheKey);
|
||||||
|
|
||||||
|
const pending = (async () => {
|
||||||
|
try {
|
||||||
|
const parsed = authService.parseSignedMessageBlob(blobB64);
|
||||||
|
const decrypted = await authService.decryptSignedMessageContent({
|
||||||
|
parsed,
|
||||||
|
blobB64,
|
||||||
|
login: state.session.login,
|
||||||
|
storagePwd: state.session.storagePwdInMemory,
|
||||||
|
});
|
||||||
|
const parsedText = parseDmTechBlocks(String(decrypted?.text || ''));
|
||||||
|
const display = clipPreviewText(String(parsedText.displayText || '').trim());
|
||||||
|
const result = display || 'Сообщение';
|
||||||
|
DM_BLOB_PREVIEW_CACHE.set(cacheKey, result);
|
||||||
|
return result;
|
||||||
|
} catch {
|
||||||
|
const fallback = 'Сообщение недоступно';
|
||||||
|
DM_BLOB_PREVIEW_CACHE.set(cacheKey, fallback);
|
||||||
|
return fallback;
|
||||||
|
} finally {
|
||||||
|
DM_BLOB_PREVIEW_PENDING.delete(cacheKey);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
DM_BLOB_PREVIEW_PENDING.set(cacheKey, pending);
|
||||||
|
return pending;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatChatRowTime(ts) {
|
function formatChatRowTime(ts) {
|
||||||
@@ -83,11 +152,11 @@ function formatChatRowTime(ts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function compareChatRows(a, b) {
|
function compareChatRows(a, b) {
|
||||||
const timeA = Number(a?.lastTimeMs || 0);
|
const timeA = Number(a?.lastMessageTimeMs || 0);
|
||||||
const timeB = Number(b?.lastTimeMs || 0);
|
const timeB = Number(b?.lastMessageTimeMs || 0);
|
||||||
if (timeA !== timeB) return timeB - timeA;
|
if (timeA !== timeB) return timeB - timeA;
|
||||||
const nameA = String(a?.name || '').toLowerCase();
|
const nameA = String(a?.peerLogin || '').toLowerCase();
|
||||||
const nameB = String(b?.name || '').toLowerCase();
|
const nameB = String(b?.peerLogin || '').toLowerCase();
|
||||||
return nameA.localeCompare(nameB, 'ru');
|
return nameA.localeCompare(nameB, 'ru');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,9 +176,9 @@ export function render({ navigate, chrome }) {
|
|||||||
<span class="dm-head-name"></span>
|
<span class="dm-head-name"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h1 class="dm-head-title">Контакты</h1>
|
<h1 class="dm-head-title">Чаты</h1>
|
||||||
<div class="dm-head-menu-wrap">
|
<div class="dm-head-menu-wrap">
|
||||||
<button type="button" class="dm-head-menu-btn" aria-label="Меню контактов" aria-haspopup="menu" aria-expanded="false">
|
<button type="button" class="dm-head-menu-btn" aria-label="Меню чатов" aria-haspopup="menu" aria-expanded="false">
|
||||||
<span class="dm-head-menu-dots" aria-hidden="true"><i></i><i></i><i></i></span>
|
<span class="dm-head-menu-dots" aria-hidden="true"><i></i><i></i><i></i></span>
|
||||||
</button>
|
</button>
|
||||||
<div class="dm-head-menu" role="menu" hidden>
|
<div class="dm-head-menu" role="menu" hidden>
|
||||||
@@ -118,7 +187,7 @@ export function render({ navigate, chrome }) {
|
|||||||
<circle cx="11" cy="11" r="6.5"></circle>
|
<circle cx="11" cy="11" r="6.5"></circle>
|
||||||
<path d="M16 16l4 4"></path>
|
<path d="M16 16l4 4"></path>
|
||||||
</svg>
|
</svg>
|
||||||
<span>Поиск контактов</span>
|
<span>Поиск пользователей</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -164,7 +233,7 @@ export function render({ navigate, chrome }) {
|
|||||||
<circle cx="11" cy="11" r="6.5"></circle>
|
<circle cx="11" cy="11" r="6.5"></circle>
|
||||||
<path d="M16 16l4 4"></path>
|
<path d="M16 16l4 4"></path>
|
||||||
</svg>
|
</svg>
|
||||||
<span>Поиск контактов</span>
|
<span>Поиск пользователей</span>
|
||||||
</button>
|
</button>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -206,16 +275,17 @@ export function render({ navigate, chrome }) {
|
|||||||
window.addEventListener('resize', onMenuViewportChange, { passive: true });
|
window.addEventListener('resize', onMenuViewportChange, { passive: true });
|
||||||
window.addEventListener('scroll', onMenuViewportChange, { passive: true, capture: true });
|
window.addEventListener('scroll', onMenuViewportChange, { passive: true, capture: true });
|
||||||
|
|
||||||
const divider = document.createElement('div');
|
|
||||||
divider.className = 'dm-divider';
|
|
||||||
|
|
||||||
const list = document.createElement('div');
|
const list = document.createElement('div');
|
||||||
list.className = 'stack dm-list';
|
list.className = 'stack dm-list';
|
||||||
|
|
||||||
function renderRow(item) {
|
function renderRow(item) {
|
||||||
const row = document.createElement('article');
|
const row = document.createElement('article');
|
||||||
row.className = 'list-item dm-dialog-card';
|
row.className = 'list-item dm-dialog-card';
|
||||||
const avatarEl = createDmAvatar(item.id);
|
const relationFlag = normalizeRelationFlag(item.relationFlag);
|
||||||
|
const relationBadge = relationFlag === 'none'
|
||||||
|
? 'не в контактах'
|
||||||
|
: relationLabel(relationFlag);
|
||||||
|
const avatarEl = createDmAvatar(item.peerLogin);
|
||||||
avatarEl.classList.add('avatar');
|
avatarEl.classList.add('avatar');
|
||||||
const avatarWrap = document.createElement('div');
|
const avatarWrap = document.createElement('div');
|
||||||
avatarWrap.className = 'dm-av dm-av--default';
|
avatarWrap.className = 'dm-av dm-av--default';
|
||||||
@@ -224,14 +294,14 @@ export function render({ navigate, chrome }) {
|
|||||||
<div class="dm-row-main">
|
<div class="dm-row-main">
|
||||||
<div class="dm-row-titleline dm-row-titlewrap">
|
<div class="dm-row-titleline dm-row-titlewrap">
|
||||||
<strong class="dm-row-title"></strong>
|
<strong class="dm-row-title"></strong>
|
||||||
${item.notInContacts ? '<span class="dm-contact-note">не в контактах</span>' : ''}
|
<span class="dm-contact-note">${relationBadge}</span>
|
||||||
</div>
|
</div>
|
||||||
<p class="dm-row-last-message"></p>
|
<p class="dm-row-last-message"></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="dm-row-meta-col">
|
<div class="dm-row-meta-col">
|
||||||
${item.unread ? `<span class="dm-unread-badge">${item.unread > 99 ? '99+' : item.unread}</span>` : '<span class="dm-row-meta-spacer" aria-hidden="true"></span>'}
|
${item.unreadCount ? `<span class="dm-unread-badge">${item.unreadCount > 99 ? '99+' : item.unreadCount}</span>` : '<span class="dm-row-meta-spacer" aria-hidden="true"></span>'}
|
||||||
<div class="dm-row-meta-line">
|
<div class="dm-row-meta-line">
|
||||||
${item.time ? '<span class="dm-row-time"></span>' : '<span class="dm-row-time dm-row-time--empty"></span>'}
|
${item.lastMessageTimeMs ? '<span class="dm-row-time"></span>' : '<span class="dm-row-time dm-row-time--empty"></span>'}
|
||||||
<span class="dm-chevron">${SVG_CHEVRON}</span>
|
<span class="dm-chevron">${SVG_CHEVRON}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -239,11 +309,15 @@ export function render({ navigate, chrome }) {
|
|||||||
const titleEl = row.querySelector('.dm-row-title');
|
const titleEl = row.querySelector('.dm-row-title');
|
||||||
const previewEl = row.querySelector('.dm-row-last-message');
|
const previewEl = row.querySelector('.dm-row-last-message');
|
||||||
const timeEl = row.querySelector('.dm-row-time');
|
const timeEl = row.querySelector('.dm-row-time');
|
||||||
if (titleEl) titleEl.textContent = String(item.name || '');
|
if (titleEl) titleEl.textContent = String(item.peerLogin || '');
|
||||||
if (previewEl) previewEl.textContent = resolveLastMessagePreview(item.lastMessage) || 'Диалог пока пуст.';
|
if (previewEl) previewEl.textContent = 'Загрузка…';
|
||||||
if (timeEl) timeEl.textContent = String(item.time || '');
|
if (timeEl) timeEl.textContent = formatChatRowTime(item.lastMessageTimeMs);
|
||||||
row.prepend(avatarWrap);
|
row.prepend(avatarWrap);
|
||||||
row.addEventListener('click', () => navigate(`chat/${encodeURIComponent(normalizeDmChatId(item.id))}`));
|
void resolveDialogPreview(item).then((text) => {
|
||||||
|
if (!previewEl?.isConnected) return;
|
||||||
|
previewEl.textContent = String(text || '').trim() || 'Диалог пока пуст.';
|
||||||
|
});
|
||||||
|
row.addEventListener('click', () => navigate(`chat/${encodeURIComponent(normalizeDmChatId(item.peerLogin))}`));
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,62 +331,64 @@ export function render({ navigate, chrome }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const relations = await loadCurrentRelations();
|
const payload = await authService.listContacts();
|
||||||
const contacts = relations.outContacts || [];
|
const dialogs = Array.isArray(payload?.dialogs) ? payload.dialogs : [];
|
||||||
|
const contacts = Array.isArray(payload?.contacts) ? payload.contacts : [];
|
||||||
setContacts(contacts);
|
setContacts(contacts);
|
||||||
list.innerHTML = '';
|
list.innerHTML = '';
|
||||||
|
|
||||||
const contactRows = contacts.map((login) => {
|
const byPeer = new Map();
|
||||||
const preview = directMessages.find((item) => item.id.toLowerCase() === login.toLowerCase());
|
dialogs.forEach((dialog) => {
|
||||||
const canonicalLogin = normalizeDmChatId(login);
|
const peerLogin = String(dialog?.peerLogin || '').trim();
|
||||||
const chat = getChatMessages(canonicalLogin);
|
if (!peerLogin) return;
|
||||||
const lastChat = chat[chat.length - 1];
|
const key = peerLogin.toLowerCase();
|
||||||
const unread = chat.filter((m) => m?.from === 'in' && m?.unread).length;
|
const relationFlag = normalizeRelationFlag(dialog?.relationFlag);
|
||||||
const lastTimeMs = Number(lastChat?.createdAtMs || 0);
|
const next = {
|
||||||
return {
|
id: peerLogin,
|
||||||
id: canonicalLogin,
|
peerLogin,
|
||||||
name: preview?.name || login,
|
relationFlag,
|
||||||
lastMessage: lastChat?.text || preview?.lastMessage || 'Диалог пока пуст.',
|
lastMessageBlobB64: String(dialog?.lastMessageBlobB64 || ''),
|
||||||
time: formatChatRowTime(lastTimeMs),
|
lastMessageTimeMs: Number(dialog?.lastMessageTimeMs || 0),
|
||||||
unread,
|
unreadCount: Number(dialog?.unreadCount || 0),
|
||||||
notInContacts: false,
|
hasDialog: Boolean(dialog?.hasDialog),
|
||||||
lastTimeMs,
|
|
||||||
};
|
};
|
||||||
|
const current = byPeer.get(key);
|
||||||
|
if (!current) {
|
||||||
|
byPeer.set(key, next);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const currentRank = relationOrder(current.relationFlag);
|
||||||
|
const nextRank = relationOrder(relationFlag);
|
||||||
|
if (nextRank < currentRank || (nextRank === currentRank && next.lastMessageTimeMs > current.lastMessageTimeMs)) {
|
||||||
|
byPeer.set(key, next);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const allChatIds = Object.keys(state.chats || {})
|
const rows = Array.from(byPeer.values()).sort((a, b) => {
|
||||||
.filter((id) => id && id.toLowerCase() !== String(state.session.login || '').toLowerCase())
|
const orderA = relationOrder(a.relationFlag);
|
||||||
.filter((id) => (getChatMessages(id) || []).length > 0);
|
const orderB = relationOrder(b.relationFlag);
|
||||||
|
if (orderA !== orderB) return orderA - orderB;
|
||||||
const contactKeys = new Set(contacts.map((x) => String(x || '').toLowerCase()));
|
return compareChatRows(a, b);
|
||||||
const extraRows = allChatIds
|
|
||||||
.filter((login) => !contactKeys.has(String(login || '').toLowerCase()))
|
|
||||||
.map((login) => {
|
|
||||||
const chat = getChatMessages(login);
|
|
||||||
const lastChat = chat[chat.length - 1];
|
|
||||||
const unread = chat.filter((m) => m?.from === 'in' && m?.unread).length;
|
|
||||||
const lastTimeMs = Number(lastChat?.createdAtMs || 0);
|
|
||||||
return {
|
|
||||||
id: login,
|
|
||||||
name: login,
|
|
||||||
lastMessage: lastChat?.text || 'Диалог пока пуст.',
|
|
||||||
time: formatChatRowTime(lastTimeMs),
|
|
||||||
unread,
|
|
||||||
notInContacts: true,
|
|
||||||
lastTimeMs,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const rows = [...contactRows, ...extraRows].sort(compareChatRows);
|
|
||||||
if (!rows.length) {
|
if (!rows.length) {
|
||||||
const empty = document.createElement('div');
|
const empty = document.createElement('div');
|
||||||
empty.className = 'card meta-muted';
|
empty.className = 'card meta-muted';
|
||||||
empty.textContent = 'Пока нет ни контактов, ни сообщений';
|
empty.textContent = 'Пока нет диалогов';
|
||||||
list.append(empty);
|
list.append(empty);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rows.forEach((item) => list.append(renderRow(item)));
|
let dividerInserted = false;
|
||||||
|
rows.forEach((item) => {
|
||||||
|
if (!dividerInserted && normalizeRelationFlag(item.relationFlag) === 'none' && list.childNodes.length > 0) {
|
||||||
|
const divider = document.createElement('div');
|
||||||
|
divider.className = 'dm-divider';
|
||||||
|
list.append(divider);
|
||||||
|
dividerInserted = true;
|
||||||
|
}
|
||||||
|
list.append(renderRow(item));
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (isSessionInvalidError(error)) {
|
if (isSessionInvalidError(error)) {
|
||||||
list.innerHTML = '';
|
list.innerHTML = '';
|
||||||
@@ -352,7 +428,7 @@ export function render({ navigate, chrome }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
chrome?.setTopbar(head);
|
chrome?.setTopbar(head);
|
||||||
screen.append(divider, list);
|
screen.append(list);
|
||||||
loadList();
|
loadList();
|
||||||
|
|
||||||
screen.cleanup = () => {
|
screen.cleanup = () => {
|
||||||
|
|||||||
@@ -1,304 +1,32 @@
|
|||||||
import { renderHeader } from '../components/header.js';
|
import { renderHeader } from '../components/header.js';
|
||||||
import { renderUserAvatar } from '../components/avatar-image.js';
|
import { state } from '../state.js';
|
||||||
import { authService, state } from '../state.js';
|
|
||||||
import { loadProfileSnapshot } from '../services/user-profile-params.js';
|
|
||||||
import { makeProfileRoute, makeShineMessageRoute } from '../services/shine-routes.js';
|
|
||||||
|
|
||||||
const CONNECTION_CLOSE_FRIEND = 10;
|
|
||||||
const profileSnapshotCache = new Map();
|
|
||||||
const profileSnapshotPending = new Map();
|
|
||||||
|
|
||||||
function connectionTypeLabel(typeCode) {
|
|
||||||
switch (Number(typeCode)) {
|
|
||||||
case CONNECTION_CLOSE_FRIEND:
|
|
||||||
return 'близкие друзья';
|
|
||||||
default:
|
|
||||||
return 'новую связь';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const pageMeta = { id: 'notifications-view', title: 'Уведомления' };
|
export const pageMeta = { id: 'notifications-view', title: 'Уведомления' };
|
||||||
|
|
||||||
function normalizeItem(item) {
|
function renderList(container) {
|
||||||
return {
|
const active = state.notificationsTab;
|
||||||
kind: String(item?.kind || ''),
|
container.innerHTML = '';
|
||||||
createdAtMs: Number(item?.createdAtMs || 0),
|
|
||||||
sourceLogin: String(item?.sourceLogin || ''),
|
|
||||||
sourceBlockchainName: String(item?.sourceBlockchainName || ''),
|
|
||||||
sourceBlockNumber: Number(item?.sourceBlockNumber || 0),
|
|
||||||
sourceBlockHash: String(item?.sourceBlockHash || ''),
|
|
||||||
sourceMsgSubType: item?.sourceMsgSubType == null ? null : Number(item.sourceMsgSubType),
|
|
||||||
sourceText: String(item?.sourceText || ''),
|
|
||||||
connectionTypeCode: item?.connectionTypeCode == null ? null : Number(item.connectionTypeCode),
|
|
||||||
targetLogin: String(item?.targetLogin || ''),
|
|
||||||
targetBlockchainName: String(item?.targetBlockchainName || ''),
|
|
||||||
targetBlockNumber: item?.targetBlockNumber == null ? null : Number(item.targetBlockNumber),
|
|
||||||
targetBlockHash: String(item?.targetBlockHash || ''),
|
|
||||||
profile: null,
|
|
||||||
engagement: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatRelativeTime(value) {
|
|
||||||
const ts = Number(value || 0);
|
|
||||||
if (!Number.isFinite(ts) || ts <= 0) return '';
|
|
||||||
|
|
||||||
const diffMs = Math.max(0, Date.now() - ts);
|
|
||||||
const minute = 60 * 1000;
|
|
||||||
const hour = 60 * minute;
|
|
||||||
const day = 24 * hour;
|
|
||||||
const week = 7 * day;
|
|
||||||
|
|
||||||
if (diffMs < minute) return 'сейчас';
|
|
||||||
if (diffMs < hour) return `${Math.max(1, Math.floor(diffMs / minute))} мин.`;
|
|
||||||
if (diffMs < day) return `${Math.max(1, Math.floor(diffMs / hour))} ч.`;
|
|
||||||
if (diffMs < week) return `${Math.max(1, Math.floor(diffMs / day))} дн.`;
|
|
||||||
return `${Math.max(1, Math.floor(diffMs / week))} нед.`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function profileField(snapshot, key) {
|
|
||||||
const row = (Array.isArray(snapshot?.fields) ? snapshot.fields : [])
|
|
||||||
.find((field) => String(field?.key || '') === key);
|
|
||||||
return String(row?.value || '').trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadCachedProfileSnapshot(login) {
|
|
||||||
const cleanLogin = String(login || '').trim();
|
|
||||||
if (!cleanLogin) return null;
|
|
||||||
const key = cleanLogin.toLowerCase();
|
|
||||||
if (profileSnapshotCache.has(key)) return profileSnapshotCache.get(key);
|
|
||||||
if (profileSnapshotPending.has(key)) return profileSnapshotPending.get(key);
|
|
||||||
|
|
||||||
const pending = loadProfileSnapshot(cleanLogin)
|
|
||||||
.then((snapshot) => {
|
|
||||||
profileSnapshotCache.set(key, snapshot || null);
|
|
||||||
profileSnapshotPending.delete(key);
|
|
||||||
return snapshot || null;
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
profileSnapshotCache.set(key, null);
|
|
||||||
profileSnapshotPending.delete(key);
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
profileSnapshotPending.set(key, pending);
|
|
||||||
return pending;
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeEngagement(source) {
|
|
||||||
if (!source || typeof source !== 'object') return null;
|
|
||||||
const likesCount = Math.max(0, Number(source.likesCount || 0));
|
|
||||||
const repliesCount = Math.max(0, Number(source.repliesCount || 0));
|
|
||||||
const ratingsCount = Math.max(0, Number(source.ratingsCount || 0));
|
|
||||||
const repostsCount = Math.max(0, Number(source.repostsCount ?? source.repostCount ?? 0));
|
|
||||||
const sharesCount = Math.max(0, Number(source.sharesCount ?? source.shareCount ?? 0));
|
|
||||||
|
|
||||||
const result = {
|
|
||||||
likesCount: Number.isFinite(likesCount) ? likesCount : 0,
|
|
||||||
repliesCount: Number.isFinite(repliesCount) ? repliesCount : 0,
|
|
||||||
ratingsCount: Number.isFinite(ratingsCount) ? ratingsCount : 0,
|
|
||||||
repostsCount: Number.isFinite(repostsCount) ? repostsCount : 0,
|
|
||||||
sharesCount: Number.isFinite(sharesCount) ? sharesCount : 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
return Object.values(result).some((count) => count > 0) ? result : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadSourceEngagement(item) {
|
|
||||||
const blockchainName = String(item?.sourceBlockchainName || '').trim();
|
|
||||||
const blockNumber = Number(item?.sourceBlockNumber);
|
|
||||||
const blockHash = String(item?.sourceBlockHash || '').trim();
|
|
||||||
if (!blockchainName || !Number.isFinite(blockNumber) || blockNumber < 0 || !blockHash) return null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const payload = await authService.getMessageThread(
|
|
||||||
{ blockchainName, blockNumber, blockHash },
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
String(state.session.login || '').trim(),
|
|
||||||
);
|
|
||||||
return normalizeEngagement(payload?.focus);
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function enrichItem(item, activeTab) {
|
|
||||||
const [profile, engagement] = await Promise.all([
|
|
||||||
loadCachedProfileSnapshot(item.sourceLogin),
|
|
||||||
activeTab === 'replies' ? loadSourceEngagement(item) : Promise.resolve(null),
|
|
||||||
]);
|
|
||||||
return { ...item, profile, engagement };
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderEmpty(activeTab) {
|
|
||||||
const card = document.createElement('article');
|
const card = document.createElement('article');
|
||||||
card.className = 'card stack';
|
card.className = 'card stack';
|
||||||
|
|
||||||
const title = document.createElement('strong');
|
const title = document.createElement('strong');
|
||||||
title.textContent = activeTab === 'events' ? 'Пока нет событий' : 'Пока нет ответов';
|
title.textContent = active === 'events' ? 'События в разработке' : 'Ответы в разработке';
|
||||||
const text = document.createElement('p');
|
|
||||||
text.className = 'meta-muted';
|
const description = document.createElement('p');
|
||||||
text.textContent = activeTab === 'events'
|
description.className = 'meta-muted';
|
||||||
? 'Когда кто-то добавит новую связь с вами, событие появится здесь.'
|
description.textContent = active === 'events'
|
||||||
: 'Когда кто-то ответит на ваше сообщение в канале или треде, ответ появится здесь.';
|
? 'Здесь будут отображаться события: кто подписался на вас, куда вас добавили, кто поставил лайк и другие действия.'
|
||||||
card.append(title, text);
|
: 'Здесь будут отображаться ответы и комментарии на ваши сообщения в публичных каналах.';
|
||||||
return card;
|
|
||||||
|
const note = document.createElement('p');
|
||||||
|
note.className = 'meta-muted';
|
||||||
|
note.textContent = 'Раздел находится в разработке. Функционал будет добавлен в следующих обновлениях.';
|
||||||
|
|
||||||
|
card.append(title, description, note);
|
||||||
|
container.append(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderIdentity(item) {
|
export function render({ chrome } = {}) {
|
||||||
const profile = item.profile;
|
|
||||||
const firstName = profileField(profile, 'first_name');
|
|
||||||
const lastName = profileField(profile, 'last_name');
|
|
||||||
const fullName = [firstName, lastName].filter(Boolean).join(' ') || item.sourceLogin || 'Пользователь';
|
|
||||||
const avatar = profile?.avatar?.txId
|
|
||||||
? {
|
|
||||||
ar: String(profile.avatar.txId || '').trim(),
|
|
||||||
sha256Hex: String(profile.avatar.sha256Hex || '').trim().toLowerCase(),
|
|
||||||
}
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const header = document.createElement('div');
|
|
||||||
header.className = 'notification-identity';
|
|
||||||
header.append(renderUserAvatar({
|
|
||||||
login: item.sourceLogin || 'unknown',
|
|
||||||
firstName,
|
|
||||||
lastName,
|
|
||||||
avatar,
|
|
||||||
size: 'small',
|
|
||||||
className: 'notification-avatar',
|
|
||||||
}));
|
|
||||||
|
|
||||||
const text = document.createElement('div');
|
|
||||||
text.className = 'notification-identity-text';
|
|
||||||
|
|
||||||
const primary = document.createElement('div');
|
|
||||||
primary.className = 'notification-identity-primary';
|
|
||||||
const name = document.createElement('strong');
|
|
||||||
name.className = 'notification-person-name';
|
|
||||||
name.textContent = fullName;
|
|
||||||
primary.append(name);
|
|
||||||
|
|
||||||
const login = String(item.sourceLogin || '').trim();
|
|
||||||
if (login) {
|
|
||||||
const loginEl = document.createElement('span');
|
|
||||||
loginEl.className = 'notification-login';
|
|
||||||
loginEl.textContent = `@${login}`;
|
|
||||||
primary.append(loginEl);
|
|
||||||
}
|
|
||||||
|
|
||||||
const relative = formatRelativeTime(item.createdAtMs);
|
|
||||||
if (relative) {
|
|
||||||
const separator = document.createElement('span');
|
|
||||||
separator.className = 'notification-time-separator';
|
|
||||||
separator.textContent = '·';
|
|
||||||
const time = document.createElement('span');
|
|
||||||
time.className = 'notification-time';
|
|
||||||
time.textContent = relative;
|
|
||||||
primary.append(separator, time);
|
|
||||||
}
|
|
||||||
|
|
||||||
text.append(primary);
|
|
||||||
header.append(text);
|
|
||||||
return header;
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderEngagement(engagement) {
|
|
||||||
if (!engagement) return null;
|
|
||||||
|
|
||||||
const stats = [
|
|
||||||
{ key: 'likesCount', icon: '♥', label: 'Лайки' },
|
|
||||||
{ key: 'repliesCount', icon: '💬', label: 'Ответы' },
|
|
||||||
{ key: 'ratingsCount', icon: '★', label: 'Оценки' },
|
|
||||||
{ key: 'repostsCount', icon: '↻', label: 'Репосты' },
|
|
||||||
{ key: 'sharesCount', icon: '↗', label: 'Отправки' },
|
|
||||||
].filter(({ key }) => Number(engagement[key] || 0) > 0);
|
|
||||||
|
|
||||||
if (!stats.length) return null;
|
|
||||||
|
|
||||||
const row = document.createElement('div');
|
|
||||||
row.className = 'notification-engagement';
|
|
||||||
stats.forEach(({ key, icon, label }) => {
|
|
||||||
const stat = document.createElement('span');
|
|
||||||
stat.className = 'notification-engagement-item';
|
|
||||||
stat.title = label;
|
|
||||||
|
|
||||||
const iconEl = document.createElement('span');
|
|
||||||
iconEl.className = 'notification-engagement-icon';
|
|
||||||
iconEl.setAttribute('aria-hidden', 'true');
|
|
||||||
iconEl.textContent = icon;
|
|
||||||
|
|
||||||
const countEl = document.createElement('span');
|
|
||||||
countEl.className = 'notification-engagement-count';
|
|
||||||
countEl.textContent = String(engagement[key]);
|
|
||||||
stat.append(iconEl, countEl);
|
|
||||||
row.append(stat);
|
|
||||||
});
|
|
||||||
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
function notificationRoute(item, activeTab) {
|
|
||||||
if (activeTab === 'events') {
|
|
||||||
const login = String(item?.sourceLogin || '').trim();
|
|
||||||
return login ? makeProfileRoute(login) : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
const blockchainName = String(item?.sourceBlockchainName || '').trim();
|
|
||||||
const blockNumber = Number(item?.sourceBlockNumber);
|
|
||||||
if (!blockchainName || !Number.isFinite(blockNumber) || blockNumber < 0) return '';
|
|
||||||
|
|
||||||
return makeShineMessageRoute({
|
|
||||||
messageBlockchainName: blockchainName,
|
|
||||||
messageBlockNumber: blockNumber,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function bindNotificationNavigation(row, routePath, navigate) {
|
|
||||||
if (!routePath || typeof navigate !== 'function') return;
|
|
||||||
|
|
||||||
row.classList.add('notification-card--clickable');
|
|
||||||
row.tabIndex = 0;
|
|
||||||
row.setAttribute('role', 'link');
|
|
||||||
|
|
||||||
const open = () => navigate(routePath);
|
|
||||||
row.addEventListener('click', open);
|
|
||||||
row.addEventListener('keydown', (event) => {
|
|
||||||
if (event.key !== 'Enter' && event.key !== ' ') return;
|
|
||||||
event.preventDefault();
|
|
||||||
open();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderItem(item, activeTab, navigate) {
|
|
||||||
const row = document.createElement('article');
|
|
||||||
row.className = 'card stack notification-card';
|
|
||||||
bindNotificationNavigation(row, notificationRoute(item, activeTab), navigate);
|
|
||||||
row.append(renderIdentity(item));
|
|
||||||
|
|
||||||
const action = document.createElement('p');
|
|
||||||
action.className = 'notification-action';
|
|
||||||
if (activeTab === 'events') {
|
|
||||||
action.textContent = `Добавил(а) вас в ${connectionTypeLabel(item.connectionTypeCode)}.`;
|
|
||||||
} else {
|
|
||||||
action.textContent = 'Ответил(а) на ваше сообщение.';
|
|
||||||
}
|
|
||||||
row.append(action);
|
|
||||||
|
|
||||||
if (activeTab === 'replies') {
|
|
||||||
const body = document.createElement('p');
|
|
||||||
body.className = 'notification-content';
|
|
||||||
body.textContent = item.sourceText || 'Ответ без текста.';
|
|
||||||
row.append(body);
|
|
||||||
|
|
||||||
const engagement = renderEngagement(item.engagement);
|
|
||||||
if (engagement) row.append(engagement);
|
|
||||||
}
|
|
||||||
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function render({ navigate, chrome } = {}) {
|
|
||||||
const screen = document.createElement('section');
|
const screen = document.createElement('section');
|
||||||
screen.className = 'stack notifications-screen';
|
screen.className = 'stack notifications-screen';
|
||||||
chrome?.setTopbar(renderHeader({ title: 'Уведомления' }));
|
chrome?.setTopbar(renderHeader({ title: 'Уведомления' }));
|
||||||
@@ -312,53 +40,17 @@ export function render({ navigate, chrome } = {}) {
|
|||||||
|
|
||||||
const list = document.createElement('div');
|
const list = document.createElement('div');
|
||||||
list.className = 'stack notifications-list';
|
list.className = 'stack notifications-list';
|
||||||
|
renderList(list);
|
||||||
let requestSeq = 0;
|
|
||||||
|
|
||||||
async function load() {
|
|
||||||
const seq = ++requestSeq;
|
|
||||||
const activeTab = state.notificationsTab;
|
|
||||||
list.replaceChildren(renderEmpty(activeTab));
|
|
||||||
|
|
||||||
try {
|
|
||||||
const payload = await authService.getNotifications(50);
|
|
||||||
if (seq !== requestSeq) return;
|
|
||||||
const baseItems = (activeTab === 'events' ? payload.events : payload.replies)
|
|
||||||
.map(normalizeItem);
|
|
||||||
if (!baseItems.length) {
|
|
||||||
list.replaceChildren(renderEmpty(activeTab));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const items = await Promise.all(baseItems.map((item) => enrichItem(item, activeTab)));
|
|
||||||
if (seq !== requestSeq) return;
|
|
||||||
list.replaceChildren(...items.map((item) => renderItem(item, activeTab, navigate)));
|
|
||||||
} catch (error) {
|
|
||||||
if (seq !== requestSeq) return;
|
|
||||||
const card = document.createElement('article');
|
|
||||||
card.className = 'card stack';
|
|
||||||
const title = document.createElement('strong');
|
|
||||||
title.textContent = 'Не удалось загрузить уведомления';
|
|
||||||
const text = document.createElement('p');
|
|
||||||
text.className = 'meta-muted';
|
|
||||||
text.textContent = error?.message || 'Ошибка запроса к серверу';
|
|
||||||
card.append(title, text);
|
|
||||||
list.replaceChildren(card);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tabs.querySelectorAll('.tab-btn').forEach((btn) => {
|
tabs.querySelectorAll('.tab-btn').forEach((btn) => {
|
||||||
btn.addEventListener('click', () => {
|
btn.addEventListener('click', () => {
|
||||||
const nextTab = String(btn.dataset.tab || 'replies');
|
state.notificationsTab = btn.dataset.tab;
|
||||||
if (state.notificationsTab === nextTab) return;
|
|
||||||
state.notificationsTab = nextTab;
|
|
||||||
tabs.querySelectorAll('.tab-btn').forEach((node) => node.classList.remove('active'));
|
tabs.querySelectorAll('.tab-btn').forEach((node) => node.classList.remove('active'));
|
||||||
btn.classList.add('active');
|
btn.classList.add('active');
|
||||||
void load();
|
renderList(list);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
screen.append(tabs, list);
|
screen.append(tabs, list);
|
||||||
void load();
|
|
||||||
return screen;
|
return screen;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { renderHeader } from '../components/header.js';
|
import { renderHeader } from '../components/header.js';
|
||||||
import { authService, clearAuthMessages, state } from '../state.js';
|
import { authService, clearAuthMessages, resetRegistrationFlow, state } from '../state.js';
|
||||||
import { toUserMessage } from '../services/ui-error-texts.js';
|
import { toUserMessage } from '../services/ui-error-texts.js';
|
||||||
import {
|
import {
|
||||||
checkLoginExistsOnSolana,
|
checkLoginExistsOnSolana,
|
||||||
@@ -426,7 +426,13 @@ export function render({ navigate }) {
|
|||||||
screen.append(
|
screen.append(
|
||||||
renderHeader({
|
renderHeader({
|
||||||
title: 'Зарегистрироваться',
|
title: 'Зарегистрироваться',
|
||||||
leftAction: { label: '←', onClick: () => navigate('start-view') },
|
leftAction: {
|
||||||
|
label: '←',
|
||||||
|
onClick: () => {
|
||||||
|
resetRegistrationFlow();
|
||||||
|
navigate('start-view');
|
||||||
|
},
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
form,
|
form,
|
||||||
actions,
|
actions,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
authService,
|
authService,
|
||||||
authorizeSession,
|
authorizeSession,
|
||||||
refreshSessions,
|
refreshSessions,
|
||||||
|
resetRegistrationFlow,
|
||||||
setAuthError,
|
setAuthError,
|
||||||
setAuthInfo,
|
setAuthInfo,
|
||||||
state,
|
state,
|
||||||
@@ -102,7 +103,10 @@ export function render({ navigate }) {
|
|||||||
cancelButton.className = 'ghost-btn';
|
cancelButton.className = 'ghost-btn';
|
||||||
cancelButton.type = 'button';
|
cancelButton.type = 'button';
|
||||||
cancelButton.textContent = 'Отмена';
|
cancelButton.textContent = 'Отмена';
|
||||||
cancelButton.addEventListener('click', () => navigate('start-view'));
|
cancelButton.addEventListener('click', () => {
|
||||||
|
resetRegistrationFlow();
|
||||||
|
navigate('start-view');
|
||||||
|
});
|
||||||
|
|
||||||
const okButton = document.createElement('button');
|
const okButton = document.createElement('button');
|
||||||
okButton.className = 'primary-btn';
|
okButton.className = 'primary-btn';
|
||||||
@@ -190,7 +194,13 @@ export function render({ navigate }) {
|
|||||||
screen.append(
|
screen.append(
|
||||||
renderHeader({
|
renderHeader({
|
||||||
title: 'Сохранение ключей',
|
title: 'Сохранение ключей',
|
||||||
leftAction: { label: '←', onClick: () => navigate('start-view') },
|
leftAction: {
|
||||||
|
label: '←',
|
||||||
|
onClick: () => {
|
||||||
|
resetRegistrationFlow();
|
||||||
|
navigate('start-view');
|
||||||
|
},
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
card,
|
card,
|
||||||
actions,
|
actions,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
authService,
|
authService,
|
||||||
authorizeSession,
|
authorizeSession,
|
||||||
refreshSessions,
|
refreshSessions,
|
||||||
|
resetRegistrationFlow,
|
||||||
setAuthError,
|
setAuthError,
|
||||||
setAuthInfo,
|
setAuthInfo,
|
||||||
state,
|
state,
|
||||||
@@ -553,6 +554,7 @@ function renderSolanaRegistrationStage({ navigate, status, keyBundle, registrati
|
|||||||
replacement.addEventListener('click', () => {
|
replacement.addEventListener('click', () => {
|
||||||
stageClosed = true;
|
stageClosed = true;
|
||||||
stopTimers();
|
stopTimers();
|
||||||
|
resetRegistrationFlow();
|
||||||
navigate('start-view');
|
navigate('start-view');
|
||||||
});
|
});
|
||||||
headerBackButton.replaceWith(replacement);
|
headerBackButton.replaceWith(replacement);
|
||||||
@@ -657,6 +659,7 @@ function renderSolanaDoneStage({ navigate, status, keyBundle, registrationTxId =
|
|||||||
replacement.addEventListener('click', () => {
|
replacement.addEventListener('click', () => {
|
||||||
loginCompleted = true;
|
loginCompleted = true;
|
||||||
stopAutoLogin();
|
stopAutoLogin();
|
||||||
|
resetRegistrationFlow();
|
||||||
navigate('start-view');
|
navigate('start-view');
|
||||||
});
|
});
|
||||||
headerBackButton.replaceWith(replacement);
|
headerBackButton.replaceWith(replacement);
|
||||||
|
|||||||
@@ -509,6 +509,22 @@ function parseSignedMessageBlockBytes(bytes) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractContactsFromDialogs(dialogs) {
|
||||||
|
const seen = new Set();
|
||||||
|
const out = [];
|
||||||
|
(Array.isArray(dialogs) ? dialogs : []).forEach((dialog) => {
|
||||||
|
const relationFlag = String(dialog?.relationFlag || '').trim().toLowerCase();
|
||||||
|
if (relationFlag !== 'contact' && relationFlag !== 'close_friend') return;
|
||||||
|
const login = String(dialog?.peerLogin || '').trim();
|
||||||
|
if (!login) return;
|
||||||
|
const key = login.toLowerCase();
|
||||||
|
if (seen.has(key)) return;
|
||||||
|
seen.add(key);
|
||||||
|
out.push(login);
|
||||||
|
});
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
function makeUserParamBodyBytes({ lineCode, prevLineNumber, prevLineHashHex, thisLineNumber, key, value }) {
|
function makeUserParamBodyBytes({ lineCode, prevLineNumber, prevLineHashHex, thisLineNumber, key, value }) {
|
||||||
const keyBytes = utf8Bytes(String(key || ''));
|
const keyBytes = utf8Bytes(String(key || ''));
|
||||||
const valueBytes = utf8Bytes(String(value || ''));
|
const valueBytes = utf8Bytes(String(value || ''));
|
||||||
@@ -2852,7 +2868,11 @@ export class AuthService {
|
|||||||
async listContacts() {
|
async listContacts() {
|
||||||
const response = await this.ws.request('ListContacts', {});
|
const response = await this.ws.request('ListContacts', {});
|
||||||
if (response.status !== 200) throw opError('ListContacts', response);
|
if (response.status !== 200) throw opError('ListContacts', response);
|
||||||
return response.payload || {};
|
const payload = response.payload || {};
|
||||||
|
if (Array.isArray(payload.dialogs) && !Array.isArray(payload.contacts)) {
|
||||||
|
payload.contacts = extractContactsFromDialogs(payload.dialogs);
|
||||||
|
}
|
||||||
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2862,14 +2882,6 @@ export class AuthService {
|
|||||||
return response.payload || {};
|
return response.payload || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getNotifications(limit = 50) {
|
|
||||||
const payload = {};
|
|
||||||
if (Number.isFinite(Number(limit))) payload.limit = Math.max(1, Math.min(200, Number(limit)));
|
|
||||||
const response = await this.ws.request('GetNotifications', payload);
|
|
||||||
if (response.status !== 200) throw opError('GetNotifications', response);
|
|
||||||
return response.payload || {};
|
|
||||||
}
|
|
||||||
|
|
||||||
async getUserConnectionsGraph(login) {
|
async getUserConnectionsGraph(login) {
|
||||||
const response = await this.ws.request('GetUserConnectionsGraph', { login });
|
const response = await this.ws.request('GetUserConnectionsGraph', { login });
|
||||||
if (response.status !== 200) throw opError('GetUserConnectionsGraph', response);
|
if (response.status !== 200) throw opError('GetUserConnectionsGraph', response);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ let transport = null;
|
|||||||
let transportDepth = 0;
|
let transportDepth = 0;
|
||||||
const recentFingerprints = new Map();
|
const recentFingerprints = new Map();
|
||||||
let notifySent = null;
|
let notifySent = null;
|
||||||
|
let lastCapturedPayload = null;
|
||||||
|
|
||||||
function nowTs() {
|
function nowTs() {
|
||||||
return Date.now();
|
return Date.now();
|
||||||
@@ -85,6 +86,11 @@ export function setClientErrorSentNotifier(fn) {
|
|||||||
notifySent = typeof fn === 'function' ? fn : null;
|
notifySent = typeof fn === 'function' ? fn : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getLastClientErrorPayload() {
|
||||||
|
if (!lastCapturedPayload) return null;
|
||||||
|
return { ...lastCapturedPayload };
|
||||||
|
}
|
||||||
|
|
||||||
export function isClientErrorReportingEnabled() {
|
export function isClientErrorReportingEnabled() {
|
||||||
try {
|
try {
|
||||||
return localStorage.getItem(UI_ERROR_REPORTING_KEY) === '1';
|
return localStorage.getItem(UI_ERROR_REPORTING_KEY) === '1';
|
||||||
@@ -104,6 +110,7 @@ export function setClientErrorReportingEnabled(enabled) {
|
|||||||
export async function captureClientError(details = {}) {
|
export async function captureClientError(details = {}) {
|
||||||
const payload = buildPayload(details);
|
const payload = buildPayload(details);
|
||||||
if (!payload.message) return false;
|
if (!payload.message) return false;
|
||||||
|
lastCapturedPayload = payload;
|
||||||
|
|
||||||
const fingerprint = details.dedupeKey || makeFingerprint(payload);
|
const fingerprint = details.dedupeKey || makeFingerprint(payload);
|
||||||
if (isDuplicate(fingerprint)) return false;
|
if (isDuplicate(fingerprint)) return false;
|
||||||
|
|||||||
@@ -925,6 +925,14 @@ export async function refreshSessions() {
|
|||||||
return state.sessions;
|
return state.sessions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function resetRegistrationFlow() {
|
||||||
|
const next = createInitialState();
|
||||||
|
state.registrationDraft = next.registrationDraft;
|
||||||
|
state.registrationHelp = next.registrationHelp;
|
||||||
|
state.registrationPayment = next.registrationPayment;
|
||||||
|
state.keyStorage = next.keyStorage;
|
||||||
|
}
|
||||||
|
|
||||||
function resetStateForSignedOut() {
|
function resetStateForSignedOut() {
|
||||||
const next = createInitialState({ withStoredSession: false });
|
const next = createInitialState({ withStoredSession: false });
|
||||||
state.chats = next.chats;
|
state.chats = next.chats;
|
||||||
|
|||||||
@@ -3324,6 +3324,10 @@ textarea.input {
|
|||||||
z-index: 24;
|
z-index: 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.boot-error-menu-shell {
|
||||||
|
z-index: 1000000;
|
||||||
|
}
|
||||||
|
|
||||||
.modal-backdrop {
|
.modal-backdrop {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
inset: 0;
|
inset: 0;
|
||||||
@@ -3341,6 +3345,16 @@ textarea.input {
|
|||||||
box-shadow: var(--shadow);
|
box-shadow: var(--shadow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.boot-error-menu-card {
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.boot-error-menu-message {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
.network-board {
|
.network-board {
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 290px;
|
height: 290px;
|
||||||
@@ -4248,6 +4262,36 @@ textarea.input {
|
|||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.channel-unread-line {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
margin: 10px 0 12px;
|
||||||
|
padding: 10px 14px;
|
||||||
|
border-radius: 999px;
|
||||||
|
border: 1px solid rgba(244, 202, 102, 0.46);
|
||||||
|
background:
|
||||||
|
linear-gradient(180deg, rgba(50, 39, 14, 0.9), rgba(22, 25, 39, 0.9));
|
||||||
|
color: #ffe6a7;
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 800;
|
||||||
|
letter-spacing: 0.08em;
|
||||||
|
line-height: 1;
|
||||||
|
text-transform: uppercase;
|
||||||
|
text-align: center;
|
||||||
|
justify-content: center;
|
||||||
|
box-shadow: 0 0 0 1px rgba(255, 226, 155, 0.08), 0 10px 24px rgba(6, 10, 20, 0.35);
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-unread-line::before,
|
||||||
|
.channel-unread-line::after {
|
||||||
|
content: '';
|
||||||
|
flex: 1 1 0;
|
||||||
|
height: 1px;
|
||||||
|
min-width: 18px;
|
||||||
|
background: linear-gradient(90deg, transparent, rgba(244, 202, 102, 0.8), transparent);
|
||||||
|
}
|
||||||
|
|
||||||
.channels-screen--channel .channel-feed {
|
.channels-screen--channel .channel-feed {
|
||||||
gap: 2px;
|
gap: 2px;
|
||||||
margin-left: -7px;
|
margin-left: -7px;
|
||||||
@@ -8042,102 +8086,3 @@ html, body { overflow-x: hidden; }
|
|||||||
pointer-events: auto;
|
pointer-events: auto;
|
||||||
isolation: isolate;
|
isolation: isolate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===== Notifications: social event cards ===== */
|
|
||||||
.notifications-screen .notification-card {
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notification-identity {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10px;
|
|
||||||
min-width: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notification-avatar {
|
|
||||||
flex: 0 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notification-identity-text {
|
|
||||||
min-width: 0;
|
|
||||||
flex: 1 1 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notification-identity-primary {
|
|
||||||
display: flex;
|
|
||||||
align-items: baseline;
|
|
||||||
gap: 6px;
|
|
||||||
min-width: 0;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notification-person-name {
|
|
||||||
color: rgba(255, 255, 255, 0.96);
|
|
||||||
font-weight: 700;
|
|
||||||
overflow-wrap: anywhere;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notification-login,
|
|
||||||
.notification-time-separator,
|
|
||||||
.notification-time {
|
|
||||||
color: rgba(255, 255, 255, 0.5);
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notification-action,
|
|
||||||
.notification-content {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notification-action {
|
|
||||||
color: rgba(255, 255, 255, 0.66);
|
|
||||||
font-size: 13px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notification-content {
|
|
||||||
color: rgba(255, 255, 255, 0.94);
|
|
||||||
font-size: 15px;
|
|
||||||
line-height: 1.45;
|
|
||||||
white-space: pre-wrap;
|
|
||||||
overflow-wrap: anywhere;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notification-engagement {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 18px;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
padding-top: 2px;
|
|
||||||
color: rgba(255, 255, 255, 0.58);
|
|
||||||
}
|
|
||||||
|
|
||||||
.notification-engagement-item {
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 5px;
|
|
||||||
min-width: 24px;
|
|
||||||
font-size: 12px;
|
|
||||||
line-height: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notification-engagement-icon {
|
|
||||||
font-size: 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.notifications-screen .notification-card--clickable {
|
|
||||||
cursor: pointer;
|
|
||||||
transition: transform 120ms ease, border-color 120ms ease, background-color 120ms ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notifications-screen .notification-card--clickable:hover,
|
|
||||||
.notifications-screen .notification-card--clickable:focus-visible {
|
|
||||||
border-color: rgba(255, 255, 255, 0.2);
|
|
||||||
background: rgba(255, 255, 255, 0.055);
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notifications-screen .notification-card--clickable:active {
|
|
||||||
transform: scale(0.99);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user