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