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

This commit is contained in:
AidarKC
2026-10-21 11:47:27 +03:00
parent aa5addb5d9
commit 7a6ab3b35a
22 changed files with 723 additions and 678 deletions
+5 -6
View File
@@ -12,11 +12,10 @@ function normKey(value) {
const FAMILY_ROLES = ['parent', 'child', 'spouse', 'sibling'];
export function relationTypeFromRelation(relation) {
const explicit = String(relation?.mark?.relationType || '').trim().toLowerCase();
if (explicit === 'close_friend' || explicit === 'friend' || explicit === 'contact') return explicit;
const role = relation?.role;
if (FAMILY_ROLES.includes(role)) return 'family';
if (role === 'friend') return 'friend';
// Тип отношения выбирает владелец рассматриваемого графа.
const ownType = String(relation?.relationType || '').trim().toLowerCase();
if (ownType === 'close_friend' || ownType === 'friend') return ownType;
if (relation?.role === 'friend') return 'friend';
return 'contact';
}
@@ -45,7 +44,7 @@ export function peopleFromGraphModel(graphModel) {
for (const relation of Array.isArray(graphModel?.relations) ? graphModel.relations : []) {
const login = normLogin(relation?.login);
const key = normKey(login);
if (!login || seen.has(key)) continue;
if (!login || seen.has(key) || !relation?.forward) continue;
seen.add(key);
const forward = Boolean(relation?.forward);
const backward = Boolean(relation?.backward);
+36 -6
View File
@@ -1604,6 +1604,20 @@ export function createGraphCanvas({ stage, onSelect, onNodeMoved, onGroupSelect,
return !edge.tie;
}
// Подотрезок квадратичной Безье по параметру t (направление: добавивший → добавленный).
function quadraticPart(g, from, to) {
const point = (t) => ({
x: (1 - t) ** 2 * g.x1 + 2 * t * (1 - t) * g.cx + t ** 2 * g.x2,
y: (1 - t) ** 2 * g.y1 + 2 * t * (1 - t) * g.cy + t ** 2 * g.y2,
});
const first = point(from);
const last = point(to);
const dx = 2 * ((1 - from) * (g.cx - g.x1) + from * (g.x2 - g.cx));
const dy = 2 * ((1 - from) * (g.cy - g.y1) + from * (g.y2 - g.cy));
const dt = (to - from) / 2;
return { first, ctrl: { x: first.x + dx * dt, y: first.y + dy * dt }, last };
}
// Нити рисуются пачками одного вида: сотни отдельных штрихов со сменой пунктира – это
// и была главная цена кадра на «друзьях друзей».
function drawEdges(inView, widthScale) {
@@ -1660,13 +1674,29 @@ export function createGraphCanvas({ stage, onSelect, onNodeMoved, onGroupSelect,
for (const batch of ordered) {
ctx.strokeStyle = rgba(colors.edge[batch.type], batch.alpha);
ctx.lineWidth = EDGE_WIDTH[batch.type] * widthScale * (batch.incident ? 1.5 : 1);
ctx.setLineDash(batch.mutual ? [] : [5 * widthScale, 4 * widthScale]);
ctx.beginPath();
for (const g of batch.list) {
ctx.moveTo(g.x1, g.y1);
ctx.quadraticCurveTo(g.cx, g.cy, g.x2, g.y2);
if (batch.mutual) {
ctx.setLineDash([]);
ctx.beginPath();
for (const g of batch.list) {
ctx.moveTo(g.x1, g.y1);
ctx.quadraticCurveTo(g.cx, g.cy, g.x2, g.y2);
}
ctx.stroke();
} else {
// От инициатора дружбы линия почти сплошная; возле адресата превращается в точки.
// Делим кривую, сохраняя геометрию и пакетную отрисовку внутри каждого сегмента.
const patterns = [[20, 3], [12, 4], [6, 4], [1, 5]];
patterns.forEach(([dash, gap], section) => {
ctx.setLineDash([dash * widthScale, gap * widthScale]);
ctx.beginPath();
for (const g of batch.list) {
const part = quadraticPart(g, section / 4, (section + 1) / 4);
ctx.moveTo(part.first.x, part.first.y);
ctx.quadraticCurveTo(part.ctrl.x, part.ctrl.y, part.last.x, part.last.y);
}
ctx.stroke();
});
}
ctx.stroke();
}
ctx.setLineDash([]);
}
+16 -1
View File
@@ -5,14 +5,29 @@
// Сервер не трогаем: знакомства – из графа связей каждого человека, подписки – из списка
// «Подписки» его профиля (публичные каналы), город – из параметра city его профиля.
import { state } from '../../state.js';
import { CONNECTIONS_GRAPH_CHANGED } from '../../services/connections-graph-cache.js';
const PREFIX = { ties: 'shine-network-ties-v1:', subs: 'shine-network-subs-v1:', cities: 'shine-network-cities-v1:' };
const PREFIX = { ties: 'shine-network-ties-v2:', subs: 'shine-network-subs-v1:', cities: 'shine-network-cities-v1:' };
export const PEOPLE_DATA_FRESH_MS = 12 * 60 * 60 * 1000; // старше – освежаются в фоне
const TYPE_CODE = { close_friend: 3, family: 3, friend: 2, contact: 1 };
const CODE_TYPE = { 3: 'close_friend', 2: 'friend', 1: 'contact' };
const memory = new Map(); // `${kind}|${owner}|${center}` → запись
let peopleGeneration = 0;
export function peopleDataGeneration() { return peopleGeneration; }
export function invalidatePeopleData() {
peopleGeneration += 1;
memory.clear();
const owner = ownerLogin();
if (!owner) return;
for (const prefix of Object.values(PREFIX)) {
try { localStorage.removeItem(prefix + owner); } catch { /* хранилище может быть недоступно */ }
}
}
if (typeof window !== 'undefined') window.addEventListener(CONNECTIONS_GRAPH_CHANGED, invalidatePeopleData);
function ownerLogin() {
return String(state.session?.login || '').trim().toLowerCase();
}