SHA256
Доработать согласия и статусы профиля
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { appendShineMessageLinks } from '../services/shine-message-links.js';
|
||||
import { confirmDialog } from '../components/confirm-dialog.js';
|
||||
import { confirmLikeAction } from '../components/like-action-sheet.js';
|
||||
import { iconHtml } from '../components/ui-icon.js';
|
||||
import { createOverflowDots } from '../components/overflow-dots.js';
|
||||
import { rememberChannelPosition, readChannelPosition, requestReplyEditorOnOpen, restoreChannelPosition } from '../services/channel-view-state.js';
|
||||
@@ -1695,18 +1696,6 @@ function renderChannelMetaEventCard(event, dayLabel = '') {
|
||||
}
|
||||
|
||||
|
||||
function likeCategoryCounts(post) {
|
||||
const total = Math.max(0, Number(post?.likesCount || 0));
|
||||
const official = Math.max(0, Math.min(total, Number(post?.primaryLikesCount || 0)));
|
||||
const shining = Math.max(0, Math.min(official, Number(post?.shiningLikesCount || 0)));
|
||||
return {
|
||||
shining,
|
||||
official,
|
||||
all: total,
|
||||
total,
|
||||
};
|
||||
}
|
||||
|
||||
function openMessageLikesListModal({ navigate, messageRef, initialTab = 'shining' }) {
|
||||
const overlay = document.createElement('div');
|
||||
overlay.className = 'channel-likes-modal-overlay';
|
||||
@@ -1817,52 +1806,6 @@ function openMessageLikesListModal({ navigate, messageRef, initialTab = 'shining
|
||||
})();
|
||||
}
|
||||
|
||||
function openMessageLikePopup({ anchor, post, navigate, onToggleLike }) {
|
||||
document.querySelectorAll('.channel-like-popup-layer').forEach((el) => el.remove());
|
||||
const counts = likeCategoryCounts(post);
|
||||
const layer = document.createElement('div');
|
||||
layer.className = 'channel-like-popup-layer';
|
||||
layer.innerHTML = `
|
||||
<section class="channel-like-popup" role="dialog" aria-label="Лайки сообщения">
|
||||
<div class="channel-like-popup__title">Лайки</div>
|
||||
<div class="channel-like-popup__counts">
|
||||
<button type="button" class="ui-button channel-like-count" data-like-list="shining"><b>${counts.shining}</b><span>Сияющие</span></button>
|
||||
<button type="button" class="ui-button channel-like-count" data-like-list="official"><b>${counts.official}</b><span>Официальные</span></button>
|
||||
<button type="button" class="ui-button channel-like-count" data-like-list="all"><b>${counts.all}</b><span>Все</span></button>
|
||||
</div>
|
||||
<button type="button" class="ui-button channel-like-popup__action">${post.reactionState === 'liked' ? 'Убрать свой лайк' : 'Добавить свой лайк'}</button>
|
||||
<button type="button" class="ui-button channel-like-popup__close">Закрыть</button>
|
||||
</section>
|
||||
`;
|
||||
document.body.append(layer);
|
||||
const popup = layer.querySelector('.channel-like-popup');
|
||||
const width = Math.min(330, Math.max(270, window.innerWidth - 24));
|
||||
popup.style.width = `${width}px`;
|
||||
|
||||
const close = () => layer.remove();
|
||||
layer.addEventListener('click', (event) => { if (event.target === layer) close(); });
|
||||
popup.addEventListener('click', (event) => event.stopPropagation());
|
||||
layer.querySelector('.channel-like-popup__close')?.addEventListener('click', close);
|
||||
layer.querySelectorAll('[data-like-list]').forEach((button) => {
|
||||
button.addEventListener('click', () => {
|
||||
const initialTab = button.dataset.likeList;
|
||||
close();
|
||||
openMessageLikesListModal({ navigate, messageRef: post.messageRef, initialTab });
|
||||
});
|
||||
});
|
||||
layer.querySelector('.channel-like-popup__action')?.addEventListener('click', async (event) => {
|
||||
const button = event.currentTarget;
|
||||
button.disabled = true;
|
||||
try {
|
||||
await onToggleLike(post.messageRef, post.reactionState === 'liked' ? 'unlike' : 'like');
|
||||
close();
|
||||
} catch (error) {
|
||||
button.disabled = false;
|
||||
showToast(toUserMessage(error, 'Не удалось изменить лайк.'), { kind: 'error' });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function renderPostCard(post, {
|
||||
navigate,
|
||||
selector,
|
||||
@@ -2081,7 +2024,7 @@ function renderPostCard(post, {
|
||||
if (isPending) return;
|
||||
likeButton.disabled = true;
|
||||
try {
|
||||
await onToggleLike(post.messageRef, isLiked ? 'unlike' : 'like');
|
||||
await onToggleLike(post.messageRef, isLiked ? 'unlike' : 'like', post);
|
||||
} catch (error) {
|
||||
showToast(toUserMessage(error, 'Не удалось изменить лайк.'), { kind: 'error' });
|
||||
} finally {
|
||||
@@ -2761,13 +2704,21 @@ export function render({ navigate, route, chrome }) {
|
||||
}
|
||||
};
|
||||
|
||||
const onToggleLike = async (messageRef, action) => {
|
||||
const onToggleLike = async (messageRef, action, post = {}) => {
|
||||
const actionKey = makeReactionActionKey(messageRef);
|
||||
if (!actionKey) {
|
||||
throw new Error('Некорректная ссылка на сообщение для реакции.');
|
||||
}
|
||||
if (pendingReactionActions.has(actionKey)) return;
|
||||
|
||||
requireSigningSession();
|
||||
const accepted = await confirmLikeAction({
|
||||
liked: action === 'unlike',
|
||||
counts: post,
|
||||
onViewList: (tab) => openMessageLikesListModal({ navigate, messageRef, initialTab: tab }),
|
||||
});
|
||||
if (!accepted || disposed) return;
|
||||
if (pendingReactionActions.has(actionKey)) return;
|
||||
const previousReaction = getMessageReactionState(messageRef);
|
||||
const nextReaction = action === 'unlike' ? 'unliked' : 'liked';
|
||||
pendingReactionActions.add(actionKey);
|
||||
@@ -3114,9 +3065,9 @@ export function render({ navigate, route, chrome }) {
|
||||
},
|
||||
});
|
||||
},
|
||||
onToggleLike: async (messageRef, action) => {
|
||||
onToggleLike: async (messageRef, action, post) => {
|
||||
try {
|
||||
await onToggleLike(messageRef, action);
|
||||
await onToggleLike(messageRef, action, post);
|
||||
showStatus('');
|
||||
} catch (error) {
|
||||
showStatus(toUserMessage(error, action === 'unlike' ? 'Не удалось убрать лайк.' : 'Не удалось поставить лайк.'));
|
||||
|
||||
Reference in New Issue
Block a user