Уведомления: «Дружить в ответ» прямо в уведомлении

В уведомлении «Добавил(а) вас в друзья», если вы ещё не ответили, – кнопка «Дружить в ответ»:
одно нажатие ставит дружбу и превращается в «Вы друзья ✓». Кто уже в друзьях – по одному
запросу своего графа связей; одна кнопка на человека (у самого свежего уведомления).
This commit is contained in:
q
2026-10-13 04:08:36 +03:00
parent b3f9e1fe21
commit 7173f33d5f
4 changed files with 53 additions and 2 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
client.version=1.19.13
client.version=1.19.14
server.version=1.15.0
+1 -1
View File
@@ -39,7 +39,7 @@
}());
</script>
<script>
window.__SHINE_BUILD_HASH__ = '20261013073000';
window.__SHINE_BUILD_HASH__ = '20261013080000';
window.__SHINE_CLIENT_VERSION__ = '1.2.10';
</script>
<script>
+46
View File
@@ -409,12 +409,58 @@ export function render({ navigate, chrome } = {}) {
if(unread.length && old.length) nodes.push(groupTitle('Ранее'));
old.forEach(x=>{const n=renderItem(x,tab,navigate);rowByItem.set(x,n);nodes.push(n);}); list.replaceChildren(...nodes);
void enrichInBackground(items, tab, rowByItem, seq);
if (tab === 'connections') void offerFriendBack(items, rowByItem, seq);
if(unread.length && 'IntersectionObserver' in window){
observer=new IntersectionObserver(entries=>{ entries.forEach(e=>{ if(e.isIntersecting && e.intersectionRatio>=0.5){ const ts=Number(e.target.dataset.createdAtMs||0); if(ts>0){e.target.classList.remove('notification-card--new');scheduleSeen(tab,ts);} } }); },{threshold:[0.5]});
list.querySelectorAll('.notification-card--new').forEach(n=>observer.observe(n));
}
}
// «Добавил(а) вас в друзья», а вы ещё нет – кнопка «Дружить в ответ» прямо в уведомлении.
// Кто у вас уже в друзьях – из одного запроса своего графа связей.
async function offerFriendBack(items, rowByItem, seq) {
const self = String(state.session.login || '').trim();
const candidates = items.filter((x) => [CONNECTION_FRIEND, CONNECTION_CLOSE_FRIEND].includes(Number(x.connectionTypeCode ?? x.sourceMsgSubType)));
if (!self || !candidates.length) return;
let graph;
try { graph = await authService.getUserConnectionsGraph(self); } catch { return; }
if (seq !== renderSeq) return;
const mine = new Set([...(graph?.outFriends || []), ...(graph?.outCloseFriends || [])].map((login) => String(login).toLowerCase()));
const offered = new Set();
for (const item of candidates) {
const login = String(item.sourceLogin || '').trim();
const key = login.toLowerCase();
// Одна кнопка на человека – у самого свежего уведомления.
if (!login || mine.has(key) || offered.has(key)) continue;
offered.add(key);
const row = rowByItem.get(item);
const body = row?.querySelector('.notification-card__body');
if (!body) continue;
const button = document.createElement('button');
button.type = 'button';
button.className = 'secondary-btn notification-card__answer';
button.textContent = 'Дружить в ответ';
button.addEventListener('click', async (event) => {
event.stopPropagation();
button.disabled = true;
button.textContent = 'Сохраняю…';
try {
await authService.setUserRelation({ login: self, toLogin: login, kind: 'friend', enabled: true, storagePwd: state.session.storagePwdInMemory });
const done = document.createElement('span');
done.className = 'notification-card__answered';
done.innerHTML = `${iconHtml('check')}<span>Вы друзья</span>`;
button.replaceWith(done);
showToast('Теперь вы друзья');
} catch (error) {
button.disabled = false;
button.textContent = 'Дружить в ответ';
showToast(toUserMessage(error, 'Не удалось добавить в друзья.'), { kind: 'error' });
}
});
body.append(button);
}
}
async function enrichInBackground(items, tab, rowByItem, seq) {
let cursor = 0;
const worker = async () => {
@@ -86,3 +86,8 @@
.notification-empty-state { margin-top: var(--space-5); padding: var(--space-5) var(--space-4); text-align: center; justify-items: center; }
.notification-empty-state strong { color: var(--text-primary); font-size: var(--text-md); }
.notification-empty-state .meta-muted { max-width: 30ch; font-size: var(--text-sm); }
/* «Дружить в ответ» прямо в уведомлении о дружбе. */
.notification-card__answer { justify-self: start; min-height: 34px; margin-top: var(--space-2); padding: 0 14px; border-radius: var(--radius-pill); font-size: var(--text-sm); font-weight: var(--weight-bold); }
.notification-card__answered { display: inline-flex; align-items: center; gap: 6px; margin-top: var(--space-2); color: var(--success); font-size: var(--text-sm); font-weight: var(--weight-medium); }
.notification-card__answered svg { width: 16px; height: 16px; }