29 01 25
Удалил старые черновики тест весь проходит
This commit is contained in:
parent
4cee326a25
commit
0b2bee0a3d
@ -43,8 +43,6 @@ import server.logic.ws_protocol.JSON.handlers.userParams.entyties.Net_ListUserPa
|
|||||||
import server.logic.ws_protocol.JSON.handlers.userParams.entyties.Net_UpsertUserParam_Request;
|
import server.logic.ws_protocol.JSON.handlers.userParams.entyties.Net_UpsertUserParam_Request;
|
||||||
|
|
||||||
// --- subscriptions ---
|
// --- subscriptions ---
|
||||||
//import server.logic.ws_protocol.JSON.handlers.subscriptions.Net_GetSubscribedChannels_Handler;
|
|
||||||
import server.logic.ws_protocol.JSON.handlers.subscriptions.entyties.Net_GetSubscribedChannels_Request;
|
|
||||||
|
|
||||||
// --- NEW: connections friends lists ---
|
// --- NEW: connections friends lists ---
|
||||||
import server.logic.ws_protocol.JSON.handlers.connections.Net_GetFriendsLists_Handler;
|
import server.logic.ws_protocol.JSON.handlers.connections.Net_GetFriendsLists_Handler;
|
||||||
@ -111,8 +109,6 @@ public final class JsonHandlerRegistry {
|
|||||||
Map.entry("GetUserParam", Net_GetUserParam_Request.class),
|
Map.entry("GetUserParam", Net_GetUserParam_Request.class),
|
||||||
Map.entry("ListUserParams", Net_ListUserParams_Request.class),
|
Map.entry("ListUserParams", Net_ListUserParams_Request.class),
|
||||||
|
|
||||||
// --- subscriptions ---
|
|
||||||
Map.entry("ListSubscribedChannels", Net_GetSubscribedChannels_Request.class),
|
|
||||||
|
|
||||||
// --- connections ---
|
// --- connections ---
|
||||||
Map.entry("GetFriendsLists", Net_GetFriendsLists_Request.class)
|
Map.entry("GetFriendsLists", Net_GetFriendsLists_Request.class)
|
||||||
|
|||||||
@ -1,147 +0,0 @@
|
|||||||
//package server.logic.ws_protocol.JSON.handlers.subscriptions;
|
|
||||||
//
|
|
||||||
//import blockchain.BchBlockEntry;
|
|
||||||
//import blockchain.body.TextBody;
|
|
||||||
//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.subscriptions.entyties.Net_GetSubscribedChannels_Request;
|
|
||||||
//import server.logic.ws_protocol.JSON.handlers.subscriptions.entyties.Net_GetSubscribedChannels_Response;
|
|
||||||
//import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
|
|
||||||
//import server.logic.ws_protocol.WireCodes;
|
|
||||||
//import shine.db.SqliteDbController;
|
|
||||||
//import shine.db.dao.SubscriptionsDAO;
|
|
||||||
//
|
|
||||||
//import java.sql.Connection;
|
|
||||||
//import java.sql.SQLException;
|
|
||||||
//import java.util.ArrayList;
|
|
||||||
//import java.util.List;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * Handler: GetSubscribedChannels
|
|
||||||
// *
|
|
||||||
// * Логика:
|
|
||||||
// * - DAO возвращает last publication orig bytes (+ edit bytes если есть)
|
|
||||||
// * - Handler парсит FULL bytes блока:
|
|
||||||
// * timestamp берём из ОРИГИНАЛА (publication)
|
|
||||||
// * текст берём из EDIT (если есть) иначе из оригинала
|
|
||||||
// * - формируем превью первых 50 символов
|
|
||||||
// */
|
|
||||||
//public class Net_GetSubscribedChannels_Handler implements JsonMessageHandler {
|
|
||||||
//
|
|
||||||
// private static final Logger log = LoggerFactory.getLogger(Net_GetSubscribedChannels_Handler.class);
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public Net_Response handle(Net_Request baseRequest, ConnectionContext ctx) {
|
|
||||||
// Net_GetSubscribedChannels_Request req = (Net_GetSubscribedChannels_Request) baseRequest;
|
|
||||||
//
|
|
||||||
// if (req.getLogin() == null || req.getLogin().isBlank()) {
|
|
||||||
// return NetExceptionResponseFactory.error(
|
|
||||||
// req,
|
|
||||||
// WireCodes.Status.BAD_REQUEST,
|
|
||||||
// "BAD_FIELDS",
|
|
||||||
// "Некорректное поле: login"
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // Если хочешь жёстче:
|
|
||||||
// // if (!req.getLogin().matches("^[A-Za-z0-9_]+$")) ...
|
|
||||||
//
|
|
||||||
// SubscriptionsDAO dao = SubscriptionsDAO.getInstance();
|
|
||||||
// SqliteDbController db = SqliteDbController.getInstance();
|
|
||||||
//
|
|
||||||
// try (Connection c = db.getConnection()) {
|
|
||||||
//
|
|
||||||
// List<SubscriptionsDAO.ChannelRow> rows = dao.getSubscribedChannels(c, req.getLogin());
|
|
||||||
// List<Net_GetSubscribedChannels_Response.ChannelInfo> out = new ArrayList<>(rows.size());
|
|
||||||
//
|
|
||||||
// for (SubscriptionsDAO.ChannelRow r : rows) {
|
|
||||||
// Net_GetSubscribedChannels_Response.ChannelInfo dto =
|
|
||||||
// new Net_GetSubscribedChannels_Response.ChannelInfo();
|
|
||||||
//
|
|
||||||
// dto.setChannelLogin(r.getChannelLogin());
|
|
||||||
// dto.setChannelBchName(r.getChannelBchName());
|
|
||||||
// dto.setPublicationsCount(r.getPublicationsCount());
|
|
||||||
//
|
|
||||||
// byte[] pubBytes = r.getLastPublicationBlockBytes();
|
|
||||||
// byte[] editBytes = r.getLastEditBlockBytes();
|
|
||||||
//
|
|
||||||
// if (pubBytes == null || pubBytes.length == 0) {
|
|
||||||
// dto.setLastPublicationTimestampSec(null);
|
|
||||||
// dto.setLastTextPreview(null);
|
|
||||||
// out.add(dto);
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // 1) timestamp берём из ОРИГИНАЛЬНОЙ публикации
|
|
||||||
// BchBlockEntry pubBlock = new BchBlockEntry(pubBytes);
|
|
||||||
// dto.setLastPublicationTimestampSec(pubBlock.timestamp);
|
|
||||||
//
|
|
||||||
// // 2) текст — из EDIT (если есть) иначе из оригинала
|
|
||||||
// byte[] actualBytes = (editBytes != null && editBytes.length > 0) ? editBytes : pubBytes;
|
|
||||||
// BchBlockEntry actualBlock = new BchBlockEntry(actualBytes);
|
|
||||||
//
|
|
||||||
// if (!(actualBlock.body instanceof TextBody)) {
|
|
||||||
// // Это уже нарушение данных: last publication должен быть текстовым блоком.
|
|
||||||
// throw new IllegalStateException("Last publication is not TextBody: type="
|
|
||||||
// + (actualBlock.body == null ? "null" : (actualBlock.body.type() & 0xFFFF)));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// String msg = ((TextBody) actualBlock.body).message;
|
|
||||||
// dto.setLastTextPreview(firstNCharsSafe(msg, 50));
|
|
||||||
//
|
|
||||||
// out.add(dto);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Net_GetSubscribedChannels_Response resp = new Net_GetSubscribedChannels_Response();
|
|
||||||
// resp.setOp(req.getOp());
|
|
||||||
// resp.setRequestId(req.getRequestId());
|
|
||||||
// resp.setStatus(WireCodes.Status.OK);
|
|
||||||
// resp.setChannels(out);
|
|
||||||
//
|
|
||||||
// return resp;
|
|
||||||
//
|
|
||||||
// } catch (SQLException e) {
|
|
||||||
// log.error("❌ DB error GetSubscribedChannels", e);
|
|
||||||
// return NetExceptionResponseFactory.error(
|
|
||||||
// req,
|
|
||||||
// WireCodes.Status.SERVER_DATA_ERROR,
|
|
||||||
// "DB_ERROR",
|
|
||||||
// "Ошибка БД"
|
|
||||||
// );
|
|
||||||
// } catch (IllegalArgumentException e) {
|
|
||||||
// // сюда попадёт, например, если BchBlockEntry не смог распарсить block_byte
|
|
||||||
// log.error("❌ Bad block bytes in DB (cannot parse BchBlockEntry)", e);
|
|
||||||
// return NetExceptionResponseFactory.error(
|
|
||||||
// req,
|
|
||||||
// WireCodes.Status.SERVER_DATA_ERROR,
|
|
||||||
// "BAD_BLOCK_BYTES",
|
|
||||||
// "В БД обнаружен повреждённый блок"
|
|
||||||
// );
|
|
||||||
// } catch (Exception e) {
|
|
||||||
// log.error("❌ Internal error GetSubscribedChannels", e);
|
|
||||||
// return NetExceptionResponseFactory.error(
|
|
||||||
// req,
|
|
||||||
// WireCodes.Status.INTERNAL_ERROR,
|
|
||||||
// "INTERNAL_ERROR",
|
|
||||||
// "Внутренняя ошибка сервера"
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Берём первые N "символов" безопасно для emoji/суррогатных пар:
|
|
||||||
// * режем по code points.
|
|
||||||
// */
|
|
||||||
// private static String firstNCharsSafe(String s, int n) {
|
|
||||||
// if (s == null) return null;
|
|
||||||
// if (n <= 0) return "";
|
|
||||||
// int cp = s.codePointCount(0, s.length());
|
|
||||||
// if (cp <= n) return s;
|
|
||||||
// int end = s.offsetByCodePoints(0, n);
|
|
||||||
// return s.substring(0, end);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
package server.logic.ws_protocol.JSON.handlers.subscriptions.entyties;
|
|
||||||
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.Net_Request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Запрос GetSubscribedChannels.
|
|
||||||
*
|
|
||||||
* Клиент отправляет:
|
|
||||||
* {
|
|
||||||
* "op": "GetSubscribedChannels",
|
|
||||||
* "requestId": "....",
|
|
||||||
* "payload": {
|
|
||||||
* "login": "anya"
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
public class Net_GetSubscribedChannels_Request extends Net_Request {
|
|
||||||
|
|
||||||
private String login;
|
|
||||||
|
|
||||||
public String getLogin() { return login; }
|
|
||||||
public void setLogin(String login) { this.login = login; }
|
|
||||||
}
|
|
||||||
@ -1,58 +0,0 @@
|
|||||||
package server.logic.ws_protocol.JSON.handlers.subscriptions.entyties;
|
|
||||||
|
|
||||||
import server.logic.ws_protocol.JSON.entyties.Net_Response;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ответ GetSubscribedChannels.
|
|
||||||
*
|
|
||||||
* payload:
|
|
||||||
* {
|
|
||||||
* "channels": [
|
|
||||||
* {
|
|
||||||
* "channelLogin": "dima",
|
|
||||||
* "channelBchName": "dima-001",
|
|
||||||
* "publicationsCount": 123,
|
|
||||||
* "lastPublicationTimestampSec": 1736371200,
|
|
||||||
* "lastTextPreview": "...."
|
|
||||||
* }
|
|
||||||
* ]
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
public class Net_GetSubscribedChannels_Response extends Net_Response {
|
|
||||||
|
|
||||||
private List<ChannelInfo> channels;
|
|
||||||
|
|
||||||
public List<ChannelInfo> getChannels() { return channels; }
|
|
||||||
public void setChannels(List<ChannelInfo> channels) { this.channels = channels; }
|
|
||||||
|
|
||||||
public static class ChannelInfo {
|
|
||||||
|
|
||||||
private String channelLogin;
|
|
||||||
private String channelBchName;
|
|
||||||
|
|
||||||
private Integer publicationsCount;
|
|
||||||
|
|
||||||
/** Unix seconds времени ПУБЛИКАЦИИ (оригинального TEXT_NEW). Nullable, если публикаций нет. */
|
|
||||||
private Long lastPublicationTimestampSec;
|
|
||||||
|
|
||||||
/** Первые 50 символов актуального текста (edit или orig). Nullable, если публикаций нет. */
|
|
||||||
private String lastTextPreview;
|
|
||||||
|
|
||||||
public String getChannelLogin() { return channelLogin; }
|
|
||||||
public void setChannelLogin(String channelLogin) { this.channelLogin = channelLogin; }
|
|
||||||
|
|
||||||
public String getChannelBchName() { return channelBchName; }
|
|
||||||
public void setChannelBchName(String channelBchName) { this.channelBchName = channelBchName; }
|
|
||||||
|
|
||||||
public Integer getPublicationsCount() { return publicationsCount; }
|
|
||||||
public void setPublicationsCount(Integer publicationsCount) { this.publicationsCount = publicationsCount; }
|
|
||||||
|
|
||||||
public Long getLastPublicationTimestampSec() { return lastPublicationTimestampSec; }
|
|
||||||
public void setLastPublicationTimestampSec(Long lastPublicationTimestampSec) { this.lastPublicationTimestampSec = lastPublicationTimestampSec; }
|
|
||||||
|
|
||||||
public String getLastTextPreview() { return lastTextPreview; }
|
|
||||||
public void setLastTextPreview(String lastTextPreview) { this.lastTextPreview = lastTextPreview; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user