Remove refs to MessageModel in conversations.ts
This commit is contained in:
parent
2550af9c91
commit
cc6ff0b554
17 changed files with 312 additions and 357 deletions
|
@ -4,8 +4,10 @@
|
|||
import { z } from 'zod';
|
||||
import { groupBy } from 'lodash';
|
||||
|
||||
import type { MessageModel } from '../models/messages';
|
||||
import type { MessageAttributesType } from '../model-types.d';
|
||||
import type {
|
||||
MessageAttributesType,
|
||||
ReadonlyMessageAttributesType,
|
||||
} from '../model-types.d';
|
||||
import type { SendStateByConversationId } from '../messages/MessageSendState';
|
||||
import { isOutgoing, isStory } from '../state/selectors/message';
|
||||
import { getOwn } from '../util/getOwn';
|
||||
|
@ -376,7 +378,7 @@ const wasDeliveredWithSealedSender = (
|
|||
|
||||
const shouldDropReceipt = (
|
||||
receipt: MessageReceiptAttributesType,
|
||||
message: MessageAttributesType
|
||||
message: ReadonlyMessageAttributesType
|
||||
): boolean => {
|
||||
const { type } = receipt.receiptSync;
|
||||
switch (type) {
|
||||
|
@ -395,25 +397,25 @@ const shouldDropReceipt = (
|
|||
};
|
||||
|
||||
export async function forMessage(
|
||||
message: MessageModel
|
||||
message: ReadonlyMessageAttributesType
|
||||
): Promise<Array<MessageReceiptAttributesType>> {
|
||||
if (!isOutgoing(message.attributes) && !isStory(message.attributes)) {
|
||||
if (!isOutgoing(message) && !isStory(message)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const logId = `MessageReceipts.forMessage(${getMessageIdForLogging(
|
||||
message.attributes
|
||||
message
|
||||
)})`;
|
||||
|
||||
const ourAci = window.textsecure.storage.user.getCheckedAci();
|
||||
const sourceServiceId = getSourceServiceId(message.attributes);
|
||||
const sourceServiceId = getSourceServiceId(message);
|
||||
if (ourAci !== sourceServiceId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const receiptValues = Array.from(cachedReceipts.values());
|
||||
|
||||
const sentAt = getMessageSentTimestamp(message.attributes, { log });
|
||||
const sentAt = getMessageSentTimestamp(message, { log });
|
||||
const result = receiptValues.filter(
|
||||
item => item.receiptSync.messageSentAt === sentAt
|
||||
);
|
||||
|
@ -427,7 +429,7 @@ export async function forMessage(
|
|||
}
|
||||
|
||||
return result.filter(receipt => {
|
||||
if (shouldDropReceipt(receipt, message.attributes)) {
|
||||
if (shouldDropReceipt(receipt, message)) {
|
||||
log.info(
|
||||
`${logId}: Dropping an early receipt ${receipt.receiptSync.type} for message ${sentAt}`
|
||||
);
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { AciString } from '../types/ServiceId';
|
||||
import type { MessageAttributesType } from '../model-types.d';
|
||||
import type {
|
||||
MessageAttributesType,
|
||||
ReadonlyMessageAttributesType,
|
||||
} from '../model-types.d';
|
||||
import type { MessageModel } from '../models/messages';
|
||||
import type { ReactionSource } from '../reactions/ReactionSource';
|
||||
import { DataReader } from '../sql/Client';
|
||||
|
@ -41,11 +44,11 @@ function remove(reaction: ReactionAttributesType): void {
|
|||
}
|
||||
|
||||
export function findReactionsForMessage(
|
||||
message: MessageModel
|
||||
message: ReadonlyMessageAttributesType
|
||||
): Array<ReactionAttributesType> {
|
||||
const matchingReactions = Array.from(reactions.values()).filter(reaction => {
|
||||
return isMessageAMatchForReaction({
|
||||
message: message.attributes,
|
||||
message,
|
||||
targetTimestamp: reaction.targetTimestamp,
|
||||
targetAuthorAci: reaction.targetAuthorAci,
|
||||
reactionSenderConversationId: reaction.fromId,
|
||||
|
@ -99,7 +102,7 @@ function isMessageAMatchForReaction({
|
|||
targetAuthorAci,
|
||||
reactionSenderConversationId,
|
||||
}: {
|
||||
message: MessageAttributesType;
|
||||
message: ReadonlyMessageAttributesType;
|
||||
targetTimestamp: number;
|
||||
targetAuthorAci: string;
|
||||
reactionSenderConversationId: string;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { MessageModel } from '../models/messages';
|
||||
import type { ReadonlyMessageAttributesType } from '../model-types.d';
|
||||
import * as Errors from '../types/errors';
|
||||
import * as log from '../logging/log';
|
||||
import { StartupQueue } from '../util/StartupQueue';
|
||||
|
@ -88,18 +88,16 @@ async function maybeItIsAReactionReadSync(
|
|||
}
|
||||
|
||||
export async function forMessage(
|
||||
message: MessageModel
|
||||
message: ReadonlyMessageAttributesType
|
||||
): Promise<ReadSyncAttributesType | null> {
|
||||
const logId = `ReadSyncs.forMessage(${getMessageIdForLogging(
|
||||
message.attributes
|
||||
)})`;
|
||||
const logId = `ReadSyncs.forMessage(${getMessageIdForLogging(message)})`;
|
||||
|
||||
const sender = window.ConversationController.lookupOrCreate({
|
||||
e164: message.get('source'),
|
||||
serviceId: message.get('sourceServiceId'),
|
||||
e164: message.source,
|
||||
serviceId: message.sourceServiceId,
|
||||
reason: logId,
|
||||
});
|
||||
const messageTimestamp = getMessageSentTimestamp(message.attributes, {
|
||||
const messageTimestamp = getMessageSentTimestamp(message, {
|
||||
log,
|
||||
});
|
||||
const readSyncValues = Array.from(readSyncs.values());
|
||||
|
@ -169,7 +167,9 @@ export async function onSync(sync: ReadSyncAttributesType): Promise<void> {
|
|||
// onReadMessage may result in messages older than this one being
|
||||
// marked read. We want those messages to have the same expire timer
|
||||
// start time as this one, so we pass the readAt value through.
|
||||
drop(conversation.onReadMessage(message, readAt, newestSentAt));
|
||||
drop(
|
||||
conversation.onReadMessage(message.attributes, readAt, newestSentAt)
|
||||
);
|
||||
};
|
||||
|
||||
// only available during initialization
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { AciString } from '../types/ServiceId';
|
||||
import type { MessageModel } from '../models/messages';
|
||||
import type { ReadonlyMessageAttributesType } from '../model-types.d';
|
||||
import { DataReader } from '../sql/Client';
|
||||
import * as Errors from '../types/errors';
|
||||
import * as log from '../logging/log';
|
||||
|
@ -23,18 +23,18 @@ function remove(sync: ViewOnceOpenSyncAttributesType): void {
|
|||
}
|
||||
|
||||
export function forMessage(
|
||||
message: MessageModel
|
||||
message: ReadonlyMessageAttributesType
|
||||
): ViewOnceOpenSyncAttributesType | null {
|
||||
const logId = `ViewOnceOpenSyncs.forMessage(${getMessageIdForLogging(
|
||||
message.attributes
|
||||
message
|
||||
)})`;
|
||||
|
||||
const viewOnceSyncValues = Array.from(viewOnceSyncs.values());
|
||||
|
||||
const syncBySourceServiceId = viewOnceSyncValues.find(item => {
|
||||
return (
|
||||
item.sourceAci === message.get('sourceServiceId') &&
|
||||
item.timestamp === message.get('sent_at')
|
||||
item.sourceAci === message.sourceServiceId &&
|
||||
item.timestamp === message.sent_at
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -45,10 +45,7 @@ export function forMessage(
|
|||
}
|
||||
|
||||
const syncBySource = viewOnceSyncValues.find(item => {
|
||||
return (
|
||||
item.source === message.get('source') &&
|
||||
item.timestamp === message.get('sent_at')
|
||||
);
|
||||
return item.source === message.source && item.timestamp === message.sent_at;
|
||||
});
|
||||
if (syncBySource) {
|
||||
log.info(`${logId}: Found early view once open sync for message`);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { MessageModel } from '../models/messages';
|
||||
import type { ReadonlyMessageAttributesType } from '../model-types.d';
|
||||
import * as Errors from '../types/errors';
|
||||
import * as log from '../logging/log';
|
||||
import { GiftBadgeStates } from '../components/conversation/Message';
|
||||
|
@ -44,18 +44,16 @@ async function remove(sync: ViewSyncAttributesType): Promise<void> {
|
|||
}
|
||||
|
||||
export async function forMessage(
|
||||
message: MessageModel
|
||||
message: ReadonlyMessageAttributesType
|
||||
): Promise<Array<ViewSyncAttributesType>> {
|
||||
const logId = `ViewSyncs.forMessage(${getMessageIdForLogging(
|
||||
message.attributes
|
||||
)})`;
|
||||
const logId = `ViewSyncs.forMessage(${getMessageIdForLogging(message)})`;
|
||||
|
||||
const sender = window.ConversationController.lookupOrCreate({
|
||||
e164: message.get('source'),
|
||||
serviceId: message.get('sourceServiceId'),
|
||||
e164: message.source,
|
||||
serviceId: message.sourceServiceId,
|
||||
reason: logId,
|
||||
});
|
||||
const messageTimestamp = getMessageSentTimestamp(message.attributes, {
|
||||
const messageTimestamp = getMessageSentTimestamp(message, {
|
||||
log,
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue