background.ts: Introduce types for redux initialState
This commit is contained in:
parent
3673b6d101
commit
4763831d3e
42 changed files with 315 additions and 238 deletions
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2020-2021 Signal Messenger, LLC
|
||||
// Copyright 2020-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { createSelector } from 'reselect';
|
||||
|
@ -62,7 +62,12 @@ export const getIncomingCall = createSelector(
|
|||
getUserUuid,
|
||||
(
|
||||
callsByConversation: CallsByConversationType,
|
||||
ourUuid: UUIDStringType
|
||||
): undefined | DirectCallStateType | GroupCallStateType =>
|
||||
getIncomingCallHelper(callsByConversation, ourUuid)
|
||||
ourUuid: UUIDStringType | undefined
|
||||
): undefined | DirectCallStateType | GroupCallStateType => {
|
||||
if (!ourUuid) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return getIncomingCallHelper(callsByConversation, ourUuid);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -365,9 +365,13 @@ export const getMe = createSelector(
|
|||
[getConversationLookup, getUserConversationId],
|
||||
(
|
||||
lookup: ConversationLookupType,
|
||||
ourConversationId: string
|
||||
ourConversationId: string | undefined
|
||||
): ConversationType => {
|
||||
return lookup[ourConversationId];
|
||||
if (!ourConversationId) {
|
||||
return getPlaceholderContact();
|
||||
}
|
||||
|
||||
return lookup[ourConversationId] || getPlaceholderContact();
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -654,8 +658,6 @@ export const getConversationSelector = createSelector(
|
|||
): GetConversationByIdType => {
|
||||
return (id?: string) => {
|
||||
if (!id) {
|
||||
log.warn(`getConversationSelector: Called with a falsey id ${id}`);
|
||||
// This will return a placeholder contact
|
||||
return selector(undefined);
|
||||
}
|
||||
|
||||
|
@ -714,10 +716,10 @@ const getCachedConversationMemberColorsSelector = createSelector(
|
|||
getUserConversationId,
|
||||
(
|
||||
conversationSelector: GetConversationByIdType,
|
||||
ourConversationId: string
|
||||
ourConversationId: string | undefined
|
||||
) => {
|
||||
return memoizee(
|
||||
(conversationId: string) => {
|
||||
(conversationId: string | undefined) => {
|
||||
const contactNameColors: Map<string, ContactNameColorType> = new Map();
|
||||
const {
|
||||
sortedGroupMembers = [],
|
||||
|
@ -726,7 +728,9 @@ const getCachedConversationMemberColorsSelector = createSelector(
|
|||
} = conversationSelector(conversationId);
|
||||
|
||||
if (type === 'direct') {
|
||||
contactNameColors.set(ourConversationId, ContactNameColors[0]);
|
||||
if (ourConversationId) {
|
||||
contactNameColors.set(ourConversationId, ContactNameColors[0]);
|
||||
}
|
||||
contactNameColors.set(theirId, ContactNameColors[0]);
|
||||
return contactNameColors;
|
||||
}
|
||||
|
@ -751,7 +755,7 @@ const getCachedConversationMemberColorsSelector = createSelector(
|
|||
|
||||
export type ContactNameColorSelectorType = (
|
||||
conversationId: string,
|
||||
contactId: string
|
||||
contactId: string | undefined
|
||||
) => ContactNameColorType;
|
||||
|
||||
export const getContactNameColorSelector = createSelector(
|
||||
|
@ -759,8 +763,13 @@ export const getContactNameColorSelector = createSelector(
|
|||
conversationMemberColorsSelector => {
|
||||
return (
|
||||
conversationId: string,
|
||||
contactId: string
|
||||
contactId: string | undefined
|
||||
): ContactNameColorType => {
|
||||
if (!contactId) {
|
||||
log.warn('No color generated for missing contactId');
|
||||
return ContactNameColors[0];
|
||||
}
|
||||
|
||||
const contactNameColors =
|
||||
conversationMemberColorsSelector(conversationId);
|
||||
const color = contactNameColors.get(contactId);
|
||||
|
@ -792,10 +801,10 @@ export const getMessageSelector = createSelector(
|
|||
messageLookup: MessageLookupType,
|
||||
selectedMessage: SelectedMessageType | undefined,
|
||||
conversationSelector: GetConversationByIdType,
|
||||
regionCode: string,
|
||||
ourNumber: string,
|
||||
ourUuid: UUIDStringType,
|
||||
ourConversationId: string,
|
||||
regionCode: string | undefined,
|
||||
ourNumber: string | undefined,
|
||||
ourUuid: UUIDStringType | undefined,
|
||||
ourConversationId: string | undefined,
|
||||
callSelector: CallSelectorType,
|
||||
activeCall: undefined | CallStateType,
|
||||
accountSelector: AccountSelectorType,
|
||||
|
|
|
@ -104,12 +104,12 @@ type PropsForUnsupportedMessage = {
|
|||
|
||||
export type GetPropsForBubbleOptions = Readonly<{
|
||||
conversationSelector: GetConversationByIdType;
|
||||
ourConversationId: string;
|
||||
ourConversationId?: string;
|
||||
ourNumber?: string;
|
||||
ourUuid: UUIDStringType;
|
||||
ourUuid?: UUIDStringType;
|
||||
selectedMessageId?: string;
|
||||
selectedMessageCounter?: number;
|
||||
regionCode: string;
|
||||
regionCode?: string;
|
||||
callSelector: CallSelectorType;
|
||||
activeCall?: CallStateType;
|
||||
accountSelector: AccountSelectorType;
|
||||
|
@ -195,7 +195,7 @@ export function getContactId(
|
|||
ourNumber,
|
||||
ourUuid,
|
||||
}: GetContactOptions
|
||||
): string {
|
||||
): string | undefined {
|
||||
const source = getSource(message, ourNumber);
|
||||
const sourceUuid = getSourceUuid(message, ourUuid);
|
||||
|
||||
|
@ -1286,7 +1286,7 @@ export function getMessagePropStatus(
|
|||
MessageWithUIFieldsType,
|
||||
'type' | 'errors' | 'sendStateByConversationId'
|
||||
>,
|
||||
ourConversationId: string
|
||||
ourConversationId: string | undefined
|
||||
): LastMessageStatus | undefined {
|
||||
if (!isOutgoing(message)) {
|
||||
return undefined;
|
||||
|
@ -1298,7 +1298,10 @@ export function getMessagePropStatus(
|
|||
|
||||
const { sendStateByConversationId = {} } = message;
|
||||
|
||||
if (isMessageJustForMe(sendStateByConversationId, ourConversationId)) {
|
||||
if (
|
||||
ourConversationId &&
|
||||
isMessageJustForMe(sendStateByConversationId, ourConversationId)
|
||||
) {
|
||||
const status =
|
||||
sendStateByConversationId[ourConversationId]?.status ??
|
||||
SendStatus.Pending;
|
||||
|
@ -1313,7 +1316,9 @@ export function getMessagePropStatus(
|
|||
}
|
||||
|
||||
const sendStates = Object.values(
|
||||
omit(sendStateByConversationId, ourConversationId)
|
||||
ourConversationId
|
||||
? omit(sendStateByConversationId, ourConversationId)
|
||||
: sendStateByConversationId
|
||||
);
|
||||
const highestSuccessfulStatus = sendStates.reduce(
|
||||
(result: SendStatus, { status }) => maxStatus(result, status),
|
||||
|
@ -1343,7 +1348,7 @@ export function getMessagePropStatus(
|
|||
|
||||
export function getPropsForEmbeddedContact(
|
||||
message: MessageWithUIFieldsType,
|
||||
regionCode: string,
|
||||
regionCode: string | undefined,
|
||||
accountSelector: (identifier?: string) => boolean
|
||||
): EmbeddedContactType | undefined {
|
||||
const contacts = message.contact;
|
||||
|
@ -1427,7 +1432,7 @@ function canReplyOrReact(
|
|||
MessageWithUIFieldsType,
|
||||
'deletedForEveryone' | 'sendStateByConversationId' | 'type'
|
||||
>,
|
||||
ourConversationId: string,
|
||||
ourConversationId: string | undefined,
|
||||
conversation: undefined | Readonly<ConversationType>
|
||||
): boolean {
|
||||
const { deletedForEveryone, sendStateByConversationId } = message;
|
||||
|
@ -1455,7 +1460,12 @@ function canReplyOrReact(
|
|||
if (isOutgoing(message)) {
|
||||
return (
|
||||
isMessageJustForMe(sendStateByConversationId, ourConversationId) ||
|
||||
someSendStatus(omit(sendStateByConversationId, ourConversationId), isSent)
|
||||
someSendStatus(
|
||||
ourConversationId
|
||||
? omit(sendStateByConversationId, ourConversationId)
|
||||
: sendStateByConversationId,
|
||||
isSent
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1475,7 +1485,7 @@ export function canReply(
|
|||
| 'sendStateByConversationId'
|
||||
| 'type'
|
||||
>,
|
||||
ourConversationId: string,
|
||||
ourConversationId: string | undefined,
|
||||
conversationSelector: GetConversationByIdType
|
||||
): boolean {
|
||||
const conversation = getConversation(message, conversationSelector);
|
||||
|
@ -1496,7 +1506,7 @@ export function canReact(
|
|||
| 'sendStateByConversationId'
|
||||
| 'type'
|
||||
>,
|
||||
ourConversationId: string,
|
||||
ourConversationId: string | undefined,
|
||||
conversationSelector: GetConversationByIdType
|
||||
): boolean {
|
||||
const conversation = getConversation(message, conversationSelector);
|
||||
|
|
|
@ -211,7 +211,7 @@ export const getMessageSearchResultSelector = createSelector(
|
|||
selectedMessageId: string | undefined,
|
||||
conversationSelector: GetConversationByIdType,
|
||||
searchConversationId: string | undefined,
|
||||
ourConversationId: string
|
||||
ourConversationId: string | undefined
|
||||
): GetMessageSearchResultByIdType => {
|
||||
return (id: string) => {
|
||||
const message = messageSearchResultLookup[id];
|
||||
|
|
|
@ -15,27 +15,27 @@ export const getUser = (state: StateType): UserStateType => state.user;
|
|||
|
||||
export const getUserNumber = createSelector(
|
||||
getUser,
|
||||
(state: UserStateType): string => state.ourNumber
|
||||
(state: UserStateType): string | undefined => state.ourNumber
|
||||
);
|
||||
|
||||
export const getUserDeviceId = createSelector(
|
||||
getUser,
|
||||
(state: UserStateType): number => state.ourDeviceId
|
||||
(state: UserStateType): number | undefined => state.ourDeviceId
|
||||
);
|
||||
|
||||
export const getRegionCode = createSelector(
|
||||
getUser,
|
||||
(state: UserStateType): string => state.regionCode
|
||||
(state: UserStateType): string | undefined => state.regionCode
|
||||
);
|
||||
|
||||
export const getUserConversationId = createSelector(
|
||||
getUser,
|
||||
(state: UserStateType): string => state.ourConversationId
|
||||
(state: UserStateType): string | undefined => state.ourConversationId
|
||||
);
|
||||
|
||||
export const getUserUuid = createSelector(
|
||||
getUser,
|
||||
(state: UserStateType): UUIDStringType => state.ourUuid
|
||||
(state: UserStateType): UUIDStringType | undefined => state.ourUuid
|
||||
);
|
||||
|
||||
export const getIntl = createSelector(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue