SHA256
Поправил пуши для личных сообщений
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { createTopBar } from '../../components/topbar.js';
|
||||
import { authService, state } from '../../state.js';
|
||||
import { getConnectionsGraphCached as loadSharedGraph, cachedConnectionsGraph as getCachedSharedGraph, CONNECTIONS_GRAPH_CHANGED, CONNECTIONS_GRAPH_TTL_MS } from '../../services/connections-graph-cache.js';
|
||||
import { makeProfileRoute } from '../../services/shine-routes.js';
|
||||
import { makeProfileLinksRoute } from '../../services/shine-routes.js';
|
||||
import { createForceGraph } from './force-graph.js';
|
||||
@@ -136,66 +137,29 @@ function getRelativeGenderMap(graph) {
|
||||
function buildGraphModel(graph, centerLogin) {
|
||||
const login = normalizeLogin(graph?.login || centerLogin || state.session.login);
|
||||
const outFriends = toSet(graph?.outFriends);
|
||||
const inFriends = toSet(graph?.inFriends);
|
||||
const outCloseFriends = toSet(graph?.outCloseFriends);
|
||||
const inFriends = toSet(graph?.inFriends);
|
||||
const inCloseFriends = toSet(graph?.inCloseFriends);
|
||||
const outParents = toSet(graph?.outParents);
|
||||
const inParents = toSet(graph?.inParents);
|
||||
const outChildren = toSet(graph?.outChildren);
|
||||
const inChildren = toSet(graph?.inChildren);
|
||||
const outSiblings = toSet(graph?.outSiblings);
|
||||
const inSiblings = toSet(graph?.inSiblings);
|
||||
const outSpouses = toSet(graph?.outSpouses);
|
||||
const inSpouses = toSet(graph?.inSpouses);
|
||||
// контакты/подписки/знакомые — для слоя «Все контакты» (Фаза 3)
|
||||
const outContacts = toSet(graph?.outContacts);
|
||||
const inContacts = toSet(graph?.inContacts);
|
||||
const outFollows = toSet(graph?.outFollows);
|
||||
const inFollows = toSet(graph?.inFollows);
|
||||
const outOfficial = toSet(graph?.outOfficialAccounts);
|
||||
const inOfficial = toSet(graph?.inOfficialAccounts);
|
||||
|
||||
const relativesGender = getRelativeGenderMap(graph);
|
||||
const allMarks = getMarkByLogin(graph?.allUsers);
|
||||
|
||||
// Граф показывает только тех, кого владелец сам выбрал другом.
|
||||
// Входящие друзья нужны лишь для проверки взаимности, контакты и подписки исключены.
|
||||
const allLogins = uniqueLogins([
|
||||
...(graph?.outFriends || []),
|
||||
...(graph?.inFriends || []),
|
||||
...(graph?.outCloseFriends || []),
|
||||
...(graph?.inCloseFriends || []),
|
||||
...(graph?.outContacts || []),
|
||||
...(graph?.inContacts || []),
|
||||
...(graph?.outFollows || []),
|
||||
...(graph?.inFollows || []),
|
||||
...(graph?.outOfficialAccounts || []),
|
||||
...(graph?.inOfficialAccounts || []),
|
||||
...(graph?.outFriends || []),
|
||||
]).filter((entry) => normKey(entry) !== normKey(login));
|
||||
|
||||
const relations = allLogins.map((targetLogin) => {
|
||||
const friendOut = hasLogin(outFriends, targetLogin);
|
||||
const friendIn = hasLogin(inFriends, targetLogin);
|
||||
const closeFriendOut = hasLogin(outCloseFriends, targetLogin);
|
||||
const closeFriendIn = hasLogin(inCloseFriends, targetLogin);
|
||||
const contactOut = hasLogin(outContacts, targetLogin) || hasLogin(outFollows, targetLogin) || hasLogin(outOfficial, targetLogin);
|
||||
const contactIn = hasLogin(inContacts, targetLogin) || hasLogin(inFollows, targetLogin) || hasLogin(inOfficial, targetLogin);
|
||||
|
||||
let role = 'contact';
|
||||
if (closeFriendOut || closeFriendIn || friendOut || friendIn) role = 'friend';
|
||||
|
||||
let forward = role === 'friend' ? (closeFriendOut || friendOut) : contactOut;
|
||||
let backward = role === 'friend' ? (closeFriendIn || friendIn) : contactIn;
|
||||
|
||||
return {
|
||||
login: targetLogin,
|
||||
key: normKey(targetLogin),
|
||||
role,
|
||||
isRelative: false,
|
||||
gender: normalizeGender(relativesGender.get(normKey(targetLogin))),
|
||||
forward: Boolean(forward),
|
||||
backward: Boolean(backward),
|
||||
mark: allMarks.get(normKey(targetLogin)) || null,
|
||||
};
|
||||
});
|
||||
const relations = allLogins.map((targetLogin) => ({
|
||||
login: targetLogin,
|
||||
key: normKey(targetLogin),
|
||||
role: 'friend',
|
||||
relationType: hasLogin(outCloseFriends, targetLogin) ? 'close_friend' : 'friend',
|
||||
isRelative: false,
|
||||
gender: GENDER_UNKNOWN,
|
||||
forward: true,
|
||||
backward: hasLogin(inCloseFriends, targetLogin) || hasLogin(inFriends, targetLogin),
|
||||
mark: allMarks.get(normKey(targetLogin)) || null,
|
||||
}));
|
||||
|
||||
return {
|
||||
centerLogin: login,
|
||||
@@ -296,6 +260,7 @@ function relationEdge(parentId, node) {
|
||||
return {
|
||||
id: normKey(parentId),
|
||||
relationType: String(node?.relationType || 'contact'),
|
||||
mutual: node?.mutual !== false,
|
||||
strength: Math.max(0, Math.min(1, Number(node?.strength) || 0.5)),
|
||||
};
|
||||
}
|
||||
@@ -412,48 +377,7 @@ async function buildSecondLevelEngineModel(baseModel, getGraph) {
|
||||
return { ...baseModel, nodes: [...byKey.values()] };
|
||||
}
|
||||
|
||||
const NETWORK_GRAPH_CACHE_TTL_MS = 2 * 60 * 1000;
|
||||
const NETWORK_GRAPH_CACHE_MAX = 240;
|
||||
const networkGraphCache = new Map();
|
||||
const networkGraphInflight = new Map();
|
||||
|
||||
async function getConnectionsGraphCached(login, { force = false, retries = 0 } = {}) {
|
||||
const clean = normalizeLogin(login);
|
||||
const key = normKey(clean);
|
||||
if (!key) throw new Error('LOGIN_REQUIRED');
|
||||
const now = Date.now();
|
||||
const cached = networkGraphCache.get(key);
|
||||
if (!force && cached && now - cached.savedAt < NETWORK_GRAPH_CACHE_TTL_MS) return cached.graph;
|
||||
if (!force && networkGraphInflight.has(key)) return networkGraphInflight.get(key);
|
||||
|
||||
const request = (async () => {
|
||||
let lastError = null;
|
||||
for (let attempt = 0; attempt <= Math.max(0, retries); attempt += 1) {
|
||||
try {
|
||||
const graph = await authService.getUserConnectionsGraph(clean);
|
||||
networkGraphCache.delete(key);
|
||||
networkGraphCache.set(key, { graph, savedAt: Date.now() });
|
||||
while (networkGraphCache.size > NETWORK_GRAPH_CACHE_MAX) {
|
||||
const oldestKey = networkGraphCache.keys().next().value;
|
||||
if (!oldestKey) break;
|
||||
networkGraphCache.delete(oldestKey);
|
||||
}
|
||||
return graph;
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
if (attempt < retries) await new Promise((resolve) => window.setTimeout(resolve, 120 * (attempt + 1)));
|
||||
}
|
||||
}
|
||||
throw lastError || new Error('GRAPH_LOAD_FAILED');
|
||||
})();
|
||||
|
||||
networkGraphInflight.set(key, request);
|
||||
try {
|
||||
return await request;
|
||||
} finally {
|
||||
if (networkGraphInflight.get(key) === request) networkGraphInflight.delete(key);
|
||||
}
|
||||
}
|
||||
const getConnectionsGraphCached = (login, options) => loadSharedGraph(authService, login, options);
|
||||
|
||||
function historyNodeClearance(node) {
|
||||
return (Number(node?.tier) || 1) >= 2 ? HISTORY_TIER2_CLEARANCE : HISTORY_NODE_CLEARANCE;
|
||||
@@ -738,6 +662,7 @@ function buildStableHistoryEngineModel(history, historyDepth = HISTORY_MAX_PREVI
|
||||
parent: parentKey,
|
||||
child: key,
|
||||
relationType: String(ref?.relationType || rawNode?.relationType || 'contact'),
|
||||
mutual: ref?.mutual !== false,
|
||||
strength: Math.max(0, Math.min(1, Number(ref?.strength) || Number(rawNode?.strength) || 0.5)),
|
||||
});
|
||||
});
|
||||
@@ -753,7 +678,7 @@ function buildStableHistoryEngineModel(history, historyDepth = HISTORY_MAX_PREVI
|
||||
if (!nodeMap.has(edge.parent) || !nodeMap.has(edge.child)) continue;
|
||||
const list = edgeParentsByChild.get(edge.child) || [];
|
||||
if (!list.some((row) => normKey(row?.id) === edge.parent)) {
|
||||
list.push({ id: edge.parent, relationType: edge.relationType, strength: edge.strength });
|
||||
list.push({ id: edge.parent, relationType: edge.relationType, mutual: edge.mutual, strength: edge.strength });
|
||||
}
|
||||
edgeParentsByChild.set(edge.child, list);
|
||||
}
|
||||
@@ -1302,8 +1227,21 @@ export function render({ navigate, route, chrome } = {}) {
|
||||
],
|
||||
});
|
||||
|
||||
function refreshConnectionsView() {
|
||||
if (!centerLogin) return;
|
||||
// После записи полностью пересобираем историю/X2 из общего кэша, сохраняя по возможности позиции.
|
||||
void load(centerLogin, { pushHistory: false });
|
||||
}
|
||||
window.addEventListener(CONNECTIONS_GRAPH_CHANGED, refreshConnectionsView);
|
||||
const graphRefreshTimer = window.setInterval(() => {
|
||||
if (engine && !document.hidden) refreshConnectionsView();
|
||||
}, CONNECTIONS_GRAPH_TTL_MS);
|
||||
|
||||
// Ресайз и перерисовку рёбер движок обрабатывает сам (window resize + ResizeObserver внутри).
|
||||
screen.cleanup = () => {
|
||||
window.removeEventListener(CONNECTIONS_GRAPH_CHANGED, refreshConnectionsView);
|
||||
window.clearInterval(graphRefreshTimer);
|
||||
loadSeq += 1;
|
||||
if (engine) engine.destroy();
|
||||
engine = null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user