Made StoryDataType sourceDevice required
This commit is contained in:
@@ -95,6 +95,25 @@ export function getStoryDataFromMessageAttributes(
|
||||
attachment = getPropsForAttachment(attachment);
|
||||
}
|
||||
|
||||
// for a story, the message should always include the sourceDevice
|
||||
// but some messages got saved without one in the past (sync-sent)
|
||||
// we default those to some reasonable values that won't break the app
|
||||
let sourceDevice: number;
|
||||
if (message.sourceDevice !== undefined) {
|
||||
sourceDevice = message.sourceDevice;
|
||||
} else {
|
||||
log.error('getStoryDataFromMessageAttributes: undefined sourceDevice');
|
||||
// storage user.getDevice() should always produce a value after registration
|
||||
const ourDeviceId = window.storage.user.getDeviceId() ?? -1;
|
||||
if (message.type === 'outgoing') {
|
||||
sourceDevice = ourDeviceId;
|
||||
} else if (message.type === 'incoming') {
|
||||
sourceDevice = 1;
|
||||
} else {
|
||||
sourceDevice = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
attachment,
|
||||
messageId: message.id,
|
||||
@@ -114,6 +133,7 @@ export function getStoryDataFromMessageAttributes(
|
||||
'timestamp',
|
||||
'type',
|
||||
]),
|
||||
sourceDevice,
|
||||
expireTimer: message.expireTimer,
|
||||
expirationStartTimestamp: dropNull(message.expirationStartTimestamp),
|
||||
};
|
||||
|
@@ -74,7 +74,6 @@ export type StoryDataType = {
|
||||
| 'sendStateByConversationId'
|
||||
| 'source'
|
||||
| 'sourceUuid'
|
||||
| 'sourceDevice'
|
||||
| 'storyDistributionListId'
|
||||
| 'timestamp'
|
||||
| 'type'
|
||||
@@ -82,6 +81,7 @@ export type StoryDataType = {
|
||||
// don't want the fields to be optional as in MessageAttributesType
|
||||
expireTimer: DurationInSeconds | undefined;
|
||||
expirationStartTimestamp: number | undefined;
|
||||
sourceDevice: number;
|
||||
};
|
||||
|
||||
export type SelectedStoryDataType = {
|
||||
@@ -1378,6 +1378,7 @@ export function reducer(
|
||||
'sendStateByConversationId',
|
||||
'source',
|
||||
'sourceUuid',
|
||||
'sourceDevice',
|
||||
'storyDistributionListId',
|
||||
'timestamp',
|
||||
'type',
|
||||
|
@@ -79,6 +79,7 @@ describe('both/state/ducks/stories', () => {
|
||||
readStatus: ReadStatus.Unread,
|
||||
timestamp: now - timestampDelta,
|
||||
type: 'story',
|
||||
sourceDevice: 1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -545,6 +546,7 @@ describe('both/state/ducks/stories', () => {
|
||||
storyDistributionListId,
|
||||
timestamp: now - timestampDelta,
|
||||
type: 'story',
|
||||
sourceDevice: 1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -930,6 +932,7 @@ describe('both/state/ducks/stories', () => {
|
||||
stories: [
|
||||
{
|
||||
...messageAttributes,
|
||||
sourceDevice: 1,
|
||||
attachment: messageAttributes.attachments[0],
|
||||
messageId: messageAttributes.id,
|
||||
expireTimer: messageAttributes.expireTimer,
|
||||
@@ -984,6 +987,7 @@ describe('both/state/ducks/stories', () => {
|
||||
stories: [
|
||||
{
|
||||
...messageAttributes,
|
||||
sourceDevice: 1,
|
||||
attachment: messageAttributes.attachments[0],
|
||||
messageId: messageAttributes.id,
|
||||
expireTimer: messageAttributes.expireTimer,
|
||||
|
@@ -2138,6 +2138,7 @@ export default class MessageReceiver
|
||||
destinationUuid: envelope.destinationUuid.toString(),
|
||||
timestamp: envelope.timestamp,
|
||||
serverTimestamp: envelope.serverTimestamp,
|
||||
device: envelope.sourceDevice,
|
||||
unidentifiedStatus: Array.from(sentToUuids).map(
|
||||
destinationUuid => ({
|
||||
destinationUuid,
|
||||
|
@@ -184,7 +184,7 @@ export type SentEventData = Readonly<{
|
||||
destinationUuid?: string;
|
||||
timestamp?: number;
|
||||
serverTimestamp?: number;
|
||||
device?: number;
|
||||
device: number | undefined;
|
||||
unidentifiedStatus: ProcessedSent['unidentifiedStatus'];
|
||||
message: ProcessedDataMessage;
|
||||
isRecipientUpdate: boolean;
|
||||
|
Reference in New Issue
Block a user