Stories: Be resilient to a missing conversation
This commit is contained in:
@@ -74,6 +74,7 @@ export type ConversationWithStoriesType = ConversationType & {
|
||||
};
|
||||
|
||||
let placeholderContact: ConversationType;
|
||||
export const PLACEHOLDER_CONTACT_ID = 'placeholder-contact';
|
||||
export const getPlaceholderContact = (): ConversationType => {
|
||||
if (placeholderContact) {
|
||||
return placeholderContact;
|
||||
@@ -82,7 +83,7 @@ export const getPlaceholderContact = (): ConversationType => {
|
||||
placeholderContact = {
|
||||
acceptedMessageRequest: false,
|
||||
badges: [],
|
||||
id: 'placeholder-contact',
|
||||
id: PLACEHOLDER_CONTACT_ID,
|
||||
type: 'direct',
|
||||
title: window.i18n('icu:unknownContact'),
|
||||
isMe: false,
|
||||
|
@@ -31,6 +31,7 @@ import {
|
||||
getConversationSelector,
|
||||
getHideStoryConversationIds,
|
||||
getMe,
|
||||
PLACEHOLDER_CONTACT_ID,
|
||||
} from './conversations';
|
||||
import { getUserConversationId } from './user';
|
||||
import { getDistributionListSelector } from './storyDistributionLists';
|
||||
@@ -189,6 +190,7 @@ export function getStoryView(
|
||||
readAt,
|
||||
timestamp,
|
||||
} = story;
|
||||
const logId = `getStoryView/${timestamp}`;
|
||||
|
||||
const { sendStateByConversationId } = story;
|
||||
let sendState: Array<StorySendStateType> | undefined;
|
||||
@@ -200,8 +202,21 @@ export function getStoryView(
|
||||
|
||||
Object.keys(sendStateByConversationId).forEach(recipientId => {
|
||||
const recipient = conversationSelector(recipientId);
|
||||
if (recipient.id === PLACEHOLDER_CONTACT_ID) {
|
||||
log.warn(
|
||||
`${logId}: Found only placeholder contact for conversation ${recipientId}, skipping`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const recipientSendState = sendStateByConversationId[recipient.id];
|
||||
if (!recipientSendState) {
|
||||
log.warn(
|
||||
`${logId}: No recipientSendState found for ${recipient.serviceId}, skipping.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (recipientSendState.status === SendStatus.Viewed) {
|
||||
innerViews += 1;
|
||||
}
|
||||
|
@@ -2,12 +2,13 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { ConversationType } from '../state/ducks/conversations';
|
||||
import { PLACEHOLDER_CONTACT_ID } from '../state/selectors/conversations';
|
||||
import { format, isValidNumber } from '../types/PhoneNumber';
|
||||
|
||||
const PLACEHOLDER_CONTACT: ConversationType = {
|
||||
acceptedMessageRequest: false,
|
||||
badges: [],
|
||||
id: 'placeholder-contact',
|
||||
id: PLACEHOLDER_CONTACT_ID,
|
||||
isMe: false,
|
||||
sharedGroupNames: [],
|
||||
title: window.i18n('icu:unknownContact'),
|
||||
|
Reference in New Issue
Block a user