SHA256
Add handoff task document for PWA, chats, and connections
This commit is contained in:
@@ -125,4 +125,32 @@ public final class ConnectionsStateDAO {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
public void upsertRelation(Connection c,
|
||||
String login,
|
||||
int relType,
|
||||
String toLogin,
|
||||
String toBchName,
|
||||
Integer toBlockNumber,
|
||||
byte[] toBlockHash) throws SQLException {
|
||||
String sql = """
|
||||
INSERT INTO connections_state (login, rel_type, to_login, to_bch_name, to_block_number, to_block_hash)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(login, rel_type, to_login) DO UPDATE SET
|
||||
to_bch_name=excluded.to_bch_name,
|
||||
to_block_number=excluded.to_block_number,
|
||||
to_block_hash=excluded.to_block_hash
|
||||
""";
|
||||
|
||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||
ps.setString(1, login);
|
||||
ps.setInt(2, relType);
|
||||
ps.setString(3, toLogin);
|
||||
ps.setString(4, toBchName);
|
||||
if (toBlockNumber == null) ps.setNull(5, java.sql.Types.INTEGER); else ps.setInt(5, toBlockNumber);
|
||||
ps.setBytes(6, toBlockHash);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package shine.db.dao;
|
||||
|
||||
import shine.db.SqliteDbController;
|
||||
import shine.db.entities.DirectMessageEntry;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public final class DirectMessagesDAO {
|
||||
private static volatile DirectMessagesDAO instance;
|
||||
private final SqliteDbController db = SqliteDbController.getInstance();
|
||||
|
||||
private DirectMessagesDAO() {}
|
||||
|
||||
public static DirectMessagesDAO getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (DirectMessagesDAO.class) {
|
||||
if (instance == null) instance = new DirectMessagesDAO();
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void insert(DirectMessageEntry entry) throws Exception {
|
||||
try (Connection c = db.getConnection()) {
|
||||
String sql = """
|
||||
INSERT INTO direct_messages (
|
||||
message_id, from_login, to_login, text, created_at_ms
|
||||
) VALUES (?, ?, ?, ?, ?)
|
||||
""";
|
||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||
ps.setString(1, entry.getMessageId());
|
||||
ps.setString(2, entry.getFromLogin());
|
||||
ps.setString(3, entry.getToLogin());
|
||||
ps.setString(4, entry.getText());
|
||||
ps.setLong(5, entry.getCreatedAtMs());
|
||||
ps.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean existsFromTo(String fromLogin, String toLogin) throws Exception {
|
||||
try (Connection c = db.getConnection()) {
|
||||
String sql = "SELECT 1 FROM direct_messages WHERE from_login = ? AND to_login = ? LIMIT 1";
|
||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||
ps.setString(1, fromLogin);
|
||||
ps.setString(2, toLogin);
|
||||
return ps.executeQuery().next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package shine.db.dao;
|
||||
|
||||
import shine.db.SqliteDbController;
|
||||
import shine.db.entities.PushTokenEntry;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class PushTokensDAO {
|
||||
private static volatile PushTokensDAO instance;
|
||||
private final SqliteDbController db = SqliteDbController.getInstance();
|
||||
|
||||
private PushTokensDAO() {}
|
||||
|
||||
public static PushTokensDAO getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (PushTokensDAO.class) {
|
||||
if (instance == null) instance = new PushTokensDAO();
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void upsert(PushTokenEntry entry) throws Exception {
|
||||
try (Connection c = db.getConnection()) {
|
||||
String sql = """
|
||||
INSERT INTO user_push_tokens (
|
||||
token_id, login, session_id, provider, token, platform, user_agent, updated_at_ms
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(token_id) DO UPDATE SET
|
||||
login=excluded.login,
|
||||
session_id=excluded.session_id,
|
||||
provider=excluded.provider,
|
||||
token=excluded.token,
|
||||
platform=excluded.platform,
|
||||
user_agent=excluded.user_agent,
|
||||
updated_at_ms=excluded.updated_at_ms
|
||||
""";
|
||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||
ps.setString(1, entry.getTokenId());
|
||||
ps.setString(2, entry.getLogin());
|
||||
ps.setString(3, entry.getSessionId());
|
||||
ps.setString(4, entry.getProvider());
|
||||
ps.setString(5, entry.getToken());
|
||||
ps.setString(6, entry.getPlatform());
|
||||
ps.setString(7, entry.getUserAgent());
|
||||
ps.setLong(8, entry.getUpdatedAtMs());
|
||||
ps.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<PushTokenEntry> listByLogin(String login) throws Exception {
|
||||
try (Connection c = db.getConnection()) {
|
||||
String sql = """
|
||||
SELECT token_id, login, session_id, provider, token, platform, user_agent, updated_at_ms
|
||||
FROM user_push_tokens
|
||||
WHERE login = ?
|
||||
ORDER BY updated_at_ms DESC
|
||||
""";
|
||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||
ps.setString(1, login);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
List<PushTokenEntry> out = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
PushTokenEntry e = new PushTokenEntry();
|
||||
e.setTokenId(rs.getString("token_id"));
|
||||
e.setLogin(rs.getString("login"));
|
||||
e.setSessionId(rs.getString("session_id"));
|
||||
e.setProvider(rs.getString("provider"));
|
||||
e.setToken(rs.getString("token"));
|
||||
e.setPlatform(rs.getString("platform"));
|
||||
e.setUserAgent(rs.getString("user_agent"));
|
||||
e.setUpdatedAtMs(rs.getLong("updated_at_ms"));
|
||||
out.add(e);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<PushTokenEntry> listByLoginAndSession(String login, String sessionId) throws Exception {
|
||||
try (Connection c = db.getConnection()) {
|
||||
String sql = """
|
||||
SELECT token_id, login, session_id, provider, token, platform, user_agent, updated_at_ms
|
||||
FROM user_push_tokens
|
||||
WHERE login = ? AND session_id = ?
|
||||
ORDER BY updated_at_ms DESC
|
||||
""";
|
||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||
ps.setString(1, login);
|
||||
ps.setString(2, sessionId);
|
||||
try (ResultSet rs = ps.executeQuery()) {
|
||||
List<PushTokenEntry> out = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
PushTokenEntry e = new PushTokenEntry();
|
||||
e.setTokenId(rs.getString("token_id"));
|
||||
e.setLogin(rs.getString("login"));
|
||||
e.setSessionId(rs.getString("session_id"));
|
||||
e.setProvider(rs.getString("provider"));
|
||||
e.setToken(rs.getString("token"));
|
||||
e.setPlatform(rs.getString("platform"));
|
||||
e.setUserAgent(rs.getString("user_agent"));
|
||||
e.setUpdatedAtMs(rs.getLong("updated_at_ms"));
|
||||
out.add(e);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user