fix: use 999+ for convo unread count, but 99+ for global one

pull/2996/head
Audric Ackermann 1 year ago
parent 9ee3286f7a
commit 444e60ce89

@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { Constants } from '../../session';
type Props = { type Props = {
overflowingAt: number; overflowingAt: number;
@ -57,9 +58,21 @@ const NotificationOrUnreadCount = ({ centeredOnTop, overflowingAt, count }: Prop
}; };
export const SessionNotificationCount = (props: Pick<Props, 'count'>) => { export const SessionNotificationCount = (props: Pick<Props, 'count'>) => {
return <NotificationOrUnreadCount centeredOnTop={false} overflowingAt={99} count={props.count} />; return (
<NotificationOrUnreadCount
centeredOnTop={false}
overflowingAt={Constants.CONVERSATION.MAX_GLOBAL_UNREAD_COUNT}
count={props.count}
/>
);
}; };
export const SessionUnreadCount = (props: Pick<Props, 'count'>) => { export const SessionUnreadCount = (props: Pick<Props, 'count'>) => {
return <NotificationOrUnreadCount centeredOnTop={true} overflowingAt={999} count={props.count} />; return (
<NotificationOrUnreadCount
centeredOnTop={true}
overflowingAt={Constants.CONVERSATION.MAX_CONVO_UNREAD_COUNT}
count={props.count}
/>
);
}; };

@ -12,6 +12,7 @@ import {
useMentionedUs, useMentionedUs,
useUnreadCount, useUnreadCount,
} from '../../../hooks/useParamSelector'; } from '../../../hooks/useParamSelector';
import { Constants } from '../../../session';
import { import {
openConversationToSpecificMessage, openConversationToSpecificMessage,
openConversationWithMessages, openConversationWithMessages,
@ -160,8 +161,14 @@ const UnreadCount = ({ convoId }: { convoId: string }) => {
const unreadMsgCount = useUnreadCount(convoId); const unreadMsgCount = useUnreadCount(convoId);
const forcedUnread = useIsForcedUnreadWithoutUnreadMsg(convoId); const forcedUnread = useIsForcedUnreadWithoutUnreadMsg(convoId);
const unreadWithOverflow =
unreadMsgCount > Constants.CONVERSATION.MAX_CONVO_UNREAD_COUNT
? `${Constants.CONVERSATION.MAX_CONVO_UNREAD_COUNT}+`
: unreadMsgCount || ' ';
// TODO would be good to merge the style of this with SessionNotificationCount or SessionUnreadCount at some point.
return unreadMsgCount > 0 || forcedUnread ? ( return unreadMsgCount > 0 || forcedUnread ? (
<p className="module-conversation-list-item__unread-count">{unreadMsgCount || ' '}</p> <p className="module-conversation-list-item__unread-count">{unreadWithOverflow}</p>
) : null; ) : null;
}; };

@ -7,7 +7,6 @@ import {
hasValidOutgoingRequestValues, hasValidOutgoingRequestValues,
} from '../models/conversation'; } from '../models/conversation';
import { isUsAnySogsFromCache } from '../session/apis/open_group_api/sogsv3/knownBlindedkeys'; import { isUsAnySogsFromCache } from '../session/apis/open_group_api/sogsv3/knownBlindedkeys';
import { CONVERSATION } from '../session/constants';
import { TimerOptions, TimerOptionsArray } from '../session/disappearing_messages/timerOptions'; import { TimerOptions, TimerOptionsArray } from '../session/disappearing_messages/timerOptions';
import { PubKey } from '../session/types'; import { PubKey } from '../session/types';
import { UserUtils } from '../session/utils'; import { UserUtils } from '../session/utils';
@ -241,12 +240,11 @@ export function useMessageReactsPropsById(messageId?: string) {
/** /**
* Returns the unread count of that conversation, or 0 if none are found. * Returns the unread count of that conversation, or 0 if none are found.
* Note: returned value is capped at a max of CONVERSATION.MAX_UNREAD_COUNT * Note: returned value is capped at a max of CONVERSATION.MAX_CONVO_UNREAD_COUNT
*/ */
export function useUnreadCount(conversationId?: string): number { export function useUnreadCount(conversationId?: string): number {
const convoProps = useConversationPropsById(conversationId); const convoProps = useConversationPropsById(conversationId);
const convoUnreadCount = convoProps?.unreadCount || 0; return convoProps?.unreadCount || 0;
return Math.min(CONVERSATION.MAX_UNREAD_COUNT, convoUnreadCount);
} }
export function useHasUnread(conversationId?: string): boolean { export function useHasUnread(conversationId?: string): boolean {

@ -51,8 +51,9 @@ export const CONVERSATION = {
// Maximum voice message duraton of 5 minutes // Maximum voice message duraton of 5 minutes
// which equates to 1.97 MB // which equates to 1.97 MB
MAX_VOICE_MESSAGE_DURATION: 300, MAX_VOICE_MESSAGE_DURATION: 300,
MAX_UNREAD_COUNT: 999, MAX_CONVO_UNREAD_COUNT: 999,
}; MAX_GLOBAL_UNREAD_COUNT: 99, // the global one does not look good with 4 digits (999+) so we have a smaller one for it
} as const;
/** /**
* The file server and onion request max upload size is 10MB precisely. * The file server and onion request max upload size is 10MB precisely.

@ -336,7 +336,6 @@ const _getGlobalUnreadCount = (sortedConversations: Array<ReduxConversationType>
} }
if ( if (
globalUnreadCount < 100 &&
isNumber(conversation.unreadCount) && isNumber(conversation.unreadCount) &&
isFinite(conversation.unreadCount) && isFinite(conversation.unreadCount) &&
conversation.unreadCount > 0 && conversation.unreadCount > 0 &&
@ -345,7 +344,6 @@ const _getGlobalUnreadCount = (sortedConversations: Array<ReduxConversationType>
globalUnreadCount += conversation.unreadCount; globalUnreadCount += conversation.unreadCount;
} }
} }
return globalUnreadCount; return globalUnreadCount;
}; };

@ -1,5 +1,6 @@
import { isString } from 'lodash'; import { isString } from 'lodash';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { useUnreadCount } from '../../hooks/useParamSelector';
import { ConversationTypeEnum, isOpenOrClosedGroup } from '../../models/conversationAttributes'; import { ConversationTypeEnum, isOpenOrClosedGroup } from '../../models/conversationAttributes';
import { import {
DisappearingMessageConversationModeType, DisappearingMessageConversationModeType,
@ -60,10 +61,6 @@ const getIsSelectedActive = (state: StateType): boolean => {
return Boolean(getSelectedConversation(state)?.activeAt) || false; return Boolean(getSelectedConversation(state)?.activeAt) || false;
}; };
const getSelectedUnreadCount = (state: StateType) => {
return getSelectedConversation(state)?.unreadCount || 0;
};
const getIsSelectedNoteToSelf = (state: StateType): boolean => { const getIsSelectedNoteToSelf = (state: StateType): boolean => {
return getSelectedConversation(state)?.isMe || false; return getSelectedConversation(state)?.isMe || false;
}; };
@ -307,7 +304,8 @@ export function useSelectedIsActive() {
} }
export function useSelectedUnreadCount() { export function useSelectedUnreadCount() {
return useSelector(getSelectedUnreadCount); const selectedConversation = useSelectedConversationKey();
return useUnreadCount(selectedConversation);
} }
export function useSelectedIsNoteToSelf() { export function useSelectedIsNoteToSelf() {

Loading…
Cancel
Save