Allow first DM to any user and show real login in profile

This commit is contained in:
ai5590 2026-04-05 12:12:46 +03:00
parent 32c046233b
commit 91ed444c90
3 changed files with 6 additions and 23 deletions

View File

@ -38,7 +38,7 @@ export function render({ navigate, route }) {
if (!isContact) { if (!isContact) {
const warning = document.createElement('div'); const warning = document.createElement('div');
warning.className = 'card stack'; warning.className = 'card stack';
warning.innerHTML = '<p class="meta-muted">Пользователь не в контактах. Можно отвечать, если он уже писал вам.</p>'; warning.innerHTML = '<p class="meta-muted">Пользователь не в контактах. Можно писать ему сразу (MVP).</p>';
const btn = document.createElement('button'); const btn = document.createElement('button');
btn.className = 'primary-btn'; btn.className = 'primary-btn';
btn.type = 'button'; btn.type = 'button';

View File

@ -1,5 +1,6 @@
import { renderHeader } from '../components/header.js?v=20260403081123'; import { renderHeader } from '../components/header.js?v=20260403081123';
import { profile } from '../mock-data.js?v=20260403081123'; import { profile } from '../mock-data.js?v=20260403081123';
import { state } from '../state.js?v=20260403081123';
export const pageMeta = { id: 'profile-view', title: 'Профиль' }; export const pageMeta = { id: 'profile-view', title: 'Профиль' };
@ -40,7 +41,7 @@ export function render({ navigate }) {
</div> </div>
<div> <div>
<h2 style="font-size:22px; margin-bottom:2px;">${profile.name}</h2> <h2 style="font-size:22px; margin-bottom:2px;">${profile.name}</h2>
<p class="meta-muted">${profile.login}</p> <p class="meta-muted">${state.session.login || profile.login}</p>
</div> </div>
<div class="stack" style="gap:8px;"> <div class="stack" style="gap:8px;">
<div class="card" style="padding:10px;"><span class="meta-muted">Телефон:</span> ${profile.phone}</div> <div class="card" style="padding:10px;"><span class="meta-muted">Телефон:</span> ${profile.phone}</div>

View File

@ -2,8 +2,6 @@ package server.logic.ws_protocol.JSON.messages;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.logic.ws_protocol.JSON.ActiveConnectionsRegistry; import server.logic.ws_protocol.JSON.ActiveConnectionsRegistry;
import server.logic.ws_protocol.JSON.ConnectionContext; import server.logic.ws_protocol.JSON.ConnectionContext;
import server.logic.ws_protocol.JSON.entyties.Net_Request; import server.logic.ws_protocol.JSON.entyties.Net_Request;
@ -16,14 +14,11 @@ import server.logic.ws_protocol.JSON.push.WsEventSender;
import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory; import server.logic.ws_protocol.JSON.utils.NetExceptionResponseFactory;
import server.logic.ws_protocol.JSON.utils.NetIdGenerator; import server.logic.ws_protocol.JSON.utils.NetIdGenerator;
import server.logic.ws_protocol.WireCodes; import server.logic.ws_protocol.WireCodes;
import shine.db.MsgSubType;
import shine.db.dao.ConnectionsStateDAO;
import shine.db.dao.DirectMessagesDAO; import shine.db.dao.DirectMessagesDAO;
import shine.db.dao.PushTokensDAO; import shine.db.dao.PushTokensDAO;
import shine.db.entities.DirectMessageEntry; import shine.db.entities.DirectMessageEntry;
import shine.db.entities.PushTokenEntry; import shine.db.entities.PushTokenEntry;
import java.sql.Connection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -31,7 +26,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class Net_SendDirectMessage_Handler implements JsonMessageHandler { public class Net_SendDirectMessage_Handler implements JsonMessageHandler {
private static final Logger log = LoggerFactory.getLogger(Net_SendDirectMessage_Handler.class);
private static final ObjectMapper MAPPER = new ObjectMapper(); private static final ObjectMapper MAPPER = new ObjectMapper();
@Override @Override
@ -122,20 +116,8 @@ public class Net_SendDirectMessage_Handler implements JsonMessageHandler {
return resp; return resp;
} }
private boolean canSend(String from, String to) throws Exception { private boolean canSend(String from, String to) {
if (from.equalsIgnoreCase(to)) return true; return from != null && !from.isBlank() && to != null && !to.isBlank();
try (Connection c = shine.db.SqliteDbController.getInstance().getConnection()) {
List<String> contacts = ConnectionsStateDAO.getInstance().listOutgoingByRelTypeCanonical(c, from, MsgSubType.CONNECTION_CONTACT);
if (contacts.stream().anyMatch(v -> v.equalsIgnoreCase(to))) {
return true;
}
if (DirectMessagesDAO.getInstance().existsFromTo(to, from)) {
return true;
}
return false;
} catch (Exception e) {
log.warn("canSend fallback false due error", e);
return false;
}
} }
} }