SHA256
Make unread divider visible in channel view
This commit is contained in:
@@ -255,6 +255,14 @@ function scrollRootBy(delta, smooth = false) {
|
||||
window.scrollBy({ top: delta, behavior });
|
||||
}
|
||||
|
||||
function getUnreadAnchorViewportFraction(unreadCount = 0) {
|
||||
const count = Math.max(0, Number(unreadCount || 0));
|
||||
if (count <= 1) return 0.68;
|
||||
if (count <= 3) return 0.56;
|
||||
if (count <= 7) return 0.48;
|
||||
return 0.42;
|
||||
}
|
||||
|
||||
function scrollElementToViewportFraction(element, fraction = 1 / 3, smooth = false) {
|
||||
if (!element) return false;
|
||||
const root = getChannelScrollRoot();
|
||||
@@ -267,8 +275,12 @@ function scrollElementToViewportFraction(element, fraction = 1 / 3, smooth = fal
|
||||
return true;
|
||||
}
|
||||
|
||||
function scrollChannelToUnreadLine(screen, smooth = false) {
|
||||
return scrollElementToViewportFraction(screen.querySelector('.channel-unread-line'), 0.42, smooth);
|
||||
function scrollChannelToUnreadLine(screen, unreadCount = 0, smooth = false) {
|
||||
return scrollElementToViewportFraction(
|
||||
screen.querySelector('.channel-unread-line'),
|
||||
getUnreadAnchorViewportFraction(unreadCount),
|
||||
smooth,
|
||||
);
|
||||
}
|
||||
|
||||
function createChannelReadTracker({
|
||||
@@ -285,6 +297,7 @@ function createChannelReadTracker({
|
||||
const safeMessagesCount = Math.max(0, Number(messagesCount || 0));
|
||||
const safeInitialSeenCount = Math.max(0, Math.min(Number(initialSeenCount || 0), safeMessagesCount));
|
||||
const unreadLine = unreadCount > 0 ? screen.querySelector('.channel-unread-line') : null;
|
||||
const unreadAnchorFraction = getUnreadAnchorViewportFraction(unreadCount);
|
||||
|
||||
let desiredSeenCount = safeInitialSeenCount;
|
||||
let persistedSeenCount = safeInitialSeenCount;
|
||||
@@ -344,7 +357,7 @@ function createChannelReadTracker({
|
||||
|
||||
const root = getChannelScrollRoot();
|
||||
const viewportHeight = root?.clientHeight || window.innerHeight || document.documentElement.clientHeight || 0;
|
||||
const thresholdTop = Math.max(0, Math.round(viewportHeight / 3));
|
||||
const thresholdTop = Math.max(0, Math.round(viewportHeight * unreadAnchorFraction));
|
||||
let seen = safeInitialSeenCount;
|
||||
for (const card of cards) {
|
||||
const localNumber = Number(card.dataset.localNumber || 0);
|
||||
@@ -2208,7 +2221,7 @@ function renderBody(screen, navigate, routeKey, channelData, handlers) {
|
||||
const hasPendingScrollTarget = pendingScrollByRoute.has(routeKey);
|
||||
applyPendingScroll(screen, routeKey, channelData.isOwnChannel || channelData.isDiary || unreadCount === 0);
|
||||
if (!hasPendingScrollTarget && unreadCount > 0 && !channelData.isOwnChannel && !channelData.isDiary) {
|
||||
window.setTimeout(() => scrollChannelToUnreadLine(screen, false), 40);
|
||||
window.setTimeout(() => scrollChannelToUnreadLine(screen, unreadCount, false), 40);
|
||||
}
|
||||
|
||||
const tracker = createChannelReadTracker({
|
||||
|
||||
Reference in New Issue
Block a user