markStoryRead: More logging in unusual cases

This commit is contained in:
Alvaro 2022-10-03 17:10:20 -06:00 committed by GitHub
parent b65890b07d
commit 44db76531e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 9 deletions

View file

@ -53,6 +53,7 @@ SomeonesStory.args = {
hasReplies: true, hasReplies: true,
isUnread: true, isUnread: true,
messageId: '123', messageId: '123',
messageIdForLogging: 'for logging 123',
sender: getDefaultConversation(), sender: getDefaultConversation(),
timestamp: Date.now(), timestamp: Date.now(),
expirationTimestamp: undefined, expirationTimestamp: undefined,

View file

@ -145,8 +145,15 @@ export const StoryViewer = ({
StoryViewType | undefined StoryViewType | undefined
>(); >();
const { attachment, canReply, isHidden, messageId, sendState, timestamp } = const {
story; attachment,
canReply,
isHidden,
messageId,
messageIdForLogging,
sendState,
timestamp,
} = story;
const { const {
acceptedMessageRequest, acceptedMessageRequest,
avatarPath, avatarPath,
@ -323,8 +330,8 @@ export const StoryViewer = ({
useEffect(() => { useEffect(() => {
markStoryRead(messageId); markStoryRead(messageId);
log.info('stories.markStoryRead', { messageId }); log.info('stories.markStoryRead', { message: messageIdForLogging });
}, [markStoryRead, messageId]); }, [markStoryRead, messageId, messageIdForLogging]);
const canFreelyNavigateStories = const canFreelyNavigateStories =
storyViewMode === StoryViewModeType.All || storyViewMode === StoryViewModeType.All ||

View file

@ -72,7 +72,9 @@ export function getContact(
return window.ConversationController.get(id); return window.ConversationController.get(id);
} }
export function getSource(message: MessageAttributesType): string | undefined { export function getSource(
message: Pick<MessageAttributesType, 'type' | 'source'>
): string | undefined {
if (isIncoming(message) || isStory(message)) { if (isIncoming(message) || isStory(message)) {
return message.source; return message.source;
} }
@ -84,7 +86,7 @@ export function getSource(message: MessageAttributesType): string | undefined {
} }
export function getSourceDevice( export function getSourceDevice(
message: MessageAttributesType message: Pick<MessageAttributesType, 'type' | 'sourceDevice'>
): string | number | undefined { ): string | number | undefined {
const { sourceDevice } = message; const { sourceDevice } = message;
@ -101,7 +103,7 @@ export function getSourceDevice(
} }
export function getSourceUuid( export function getSourceUuid(
message: MessageAttributesType message: Pick<MessageAttributesType, 'type' | 'sourceUuid'>
): UUIDStringType | undefined { ): UUIDStringType | undefined {
if (isIncoming(message) || isStory(message)) { if (isIncoming(message) || isStory(message)) {
return message.sourceUuid; return message.sourceUuid;

View file

@ -72,6 +72,7 @@ export type StoryDataType = {
| 'sendStateByConversationId' | 'sendStateByConversationId'
| 'source' | 'source'
| 'sourceUuid' | 'sourceUuid'
| 'sourceDevice'
| 'storyDistributionListId' | 'storyDistributionListId'
| 'timestamp' | 'timestamp'
| 'type' | 'type'
@ -426,16 +427,27 @@ function markStoryRead(
!isDownloaded(matchingStory.attachment) && !isDownloaded(matchingStory.attachment) &&
!hasFailed(matchingStory.attachment) !hasFailed(matchingStory.attachment)
) { ) {
log.warn(
`markStoryRead: not downloaded: ${messageId} ${
matchingStory.attachment?.error
? `error: ${matchingStory.attachment?.error}`
: ''
}`
);
return; return;
} }
if (matchingStory.readStatus !== ReadStatus.Unread) { if (matchingStory.readStatus !== ReadStatus.Unread) {
log.warn(
`markStoryRead: not unread, ${messageId} read status: ${matchingStory.readStatus}`
);
return; return;
} }
const message = await getMessageById(messageId); const message = await getMessageById(messageId);
if (!message) { if (!message) {
log.warn(`markStoryRead: no message found ${messageId}`);
return; return;
} }

View file

@ -35,6 +35,7 @@ import { getUserConversationId } from './user';
import { getDistributionListSelector } from './storyDistributionLists'; import { getDistributionListSelector } from './storyDistributionLists';
import { getStoriesEnabled } from './items'; import { getStoriesEnabled } from './items';
import { calculateExpirationTimestamp } from '../../util/expirationTimer'; import { calculateExpirationTimestamp } from '../../util/expirationTimer';
import { getMessageIdForLogging } from '../../util/idForLogging';
export const getStoriesState = (state: StateType): StoriesStateType => export const getStoriesState = (state: StateType): StoriesStateType =>
state.stories; state.stories;
@ -191,12 +192,18 @@ export function getStoryView(
views = innerViews; views = innerViews;
} }
const messageIdForLogging = getMessageIdForLogging({
...pick(story, 'type', 'sourceUuid', 'sourceDevice'),
sent_at: story.timestamp,
});
return { return {
attachment, attachment,
canReply: canReply(story, ourConversationId, conversationSelector), canReply: canReply(story, ourConversationId, conversationSelector),
isHidden: Boolean(sender.hideStory), isHidden: Boolean(sender.hideStory),
isUnread: story.readStatus === ReadStatus.Unread, isUnread: story.readStatus === ReadStatus.Unread,
messageId: story.messageId, messageId: story.messageId,
messageIdForLogging,
readAt, readAt,
sender, sender,
sendState, sendState,

View file

@ -43,13 +43,16 @@ export function getFakeStoryView(
): StoryViewType { ): StoryViewType {
const sender = getDefaultConversation(); const sender = getDefaultConversation();
const messageId = UUID.generate().toString();
return { return {
attachment: getAttachmentWithThumbnail( attachment: getAttachmentWithThumbnail(
attachmentUrl || '/fixtures/tina-rolf-269345-unsplash.jpg' attachmentUrl || '/fixtures/tina-rolf-269345-unsplash.jpg'
), ),
hasReplies: Boolean(casual.coin_flip), hasReplies: Boolean(casual.coin_flip),
isUnread: Boolean(casual.coin_flip), isUnread: Boolean(casual.coin_flip),
messageId: UUID.generate().toString(), messageId,
messageIdForLogging: `${messageId} (for logging)`,
sender, sender,
timestamp: timestamp || Date.now() - 2 * durations.MINUTE, timestamp: timestamp || Date.now() - 2 * durations.MINUTE,
expirationTimestamp: undefined, expirationTimestamp: undefined,

View file

@ -73,6 +73,7 @@ export type StoryViewType = {
isHidden?: boolean; isHidden?: boolean;
isUnread?: boolean; isUnread?: boolean;
messageId: string; messageId: string;
messageIdForLogging: string;
readAt?: number; readAt?: number;
sender: Pick< sender: Pick<
ConversationType, ConversationType,

View file

@ -8,7 +8,12 @@ import type {
import { getSource, getSourceDevice, getSourceUuid } from '../messages/helpers'; import { getSource, getSourceDevice, getSourceUuid } from '../messages/helpers';
import { isDirectConversation, isGroupV2 } from './whatTypeOfConversation'; import { isDirectConversation, isGroupV2 } from './whatTypeOfConversation';
export function getMessageIdForLogging(message: MessageAttributesType): string { export function getMessageIdForLogging(
message: Pick<
MessageAttributesType,
'type' | 'sourceUuid' | 'sourceDevice' | 'sent_at'
>
): string {
const account = getSourceUuid(message) || getSource(message); const account = getSourceUuid(message) || getSource(message);
const device = getSourceDevice(message); const device = getSourceDevice(message);
const timestamp = message.sent_at; const timestamp = message.sent_at;