No Backbone in data layer; server/client interfaces are now similar
This commit is contained in:
parent
064bbfe97a
commit
34fd945f83
31 changed files with 573 additions and 1021 deletions
|
@ -196,9 +196,7 @@ async function _runJob(job?: AttachmentDownloadJobType): Promise<void> {
|
|||
|
||||
const found =
|
||||
window.MessageController.getById(messageId) ||
|
||||
(await getMessageById(messageId, {
|
||||
Message: window.Whisper.Message,
|
||||
}));
|
||||
(await getMessageById(messageId));
|
||||
if (!found) {
|
||||
logger.error('_runJob: Source message not found, deleting job');
|
||||
await _finishJob(null, id);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import { Collection, Model } from 'backbone';
|
||||
import type { MessageModel } from '../models/messages';
|
||||
import { getContactId } from '../messages/helpers';
|
||||
import * as log from '../logging/log';
|
||||
|
||||
type DeleteAttributesType = {
|
||||
|
@ -30,7 +31,7 @@ export class Deletes extends Collection<DeleteModel> {
|
|||
const matchingDeletes = this.filter(item => {
|
||||
return (
|
||||
item.get('targetSentTimestamp') === message.get('sent_at') &&
|
||||
item.get('fromId') === message.getContactId()
|
||||
item.get('fromId') === getContactId(message.attributes)
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -68,14 +69,11 @@ export class Deletes extends Collection<DeleteModel> {
|
|||
log.info('Handling DOE for', del.get('targetSentTimestamp'));
|
||||
|
||||
const messages = await window.Signal.Data.getMessagesBySentAt(
|
||||
del.get('targetSentTimestamp'),
|
||||
{
|
||||
MessageCollection: window.Whisper.MessageCollection,
|
||||
}
|
||||
del.get('targetSentTimestamp')
|
||||
);
|
||||
|
||||
const targetMessage = messages.find(
|
||||
m => del.get('fromId') === m.getContactId()
|
||||
m => del.get('fromId') === getContactId(m)
|
||||
);
|
||||
|
||||
if (!targetMessage) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import { Collection, Model } from 'backbone';
|
|||
|
||||
import type { ConversationModel } from '../models/conversations';
|
||||
import type { MessageModel } from '../models/messages';
|
||||
import type { MessageModelCollectionType } from '../model-types.d';
|
||||
import type { MessageAttributesType } from '../model-types.d';
|
||||
import { isOutgoing } from '../state/selectors/message';
|
||||
import { isDirectConversation } from '../util/whatTypeOfConversation';
|
||||
import { getOwn } from '../util/getOwn';
|
||||
|
@ -60,32 +60,25 @@ const deleteSentProtoBatcher = createWaitBatcher({
|
|||
async function getTargetMessage(
|
||||
sourceId: string,
|
||||
sourceUuid: UUIDStringType,
|
||||
messages: MessageModelCollectionType
|
||||
messages: ReadonlyArray<MessageAttributesType>
|
||||
): Promise<MessageModel | null> {
|
||||
if (messages.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const message = messages.find(
|
||||
item =>
|
||||
isOutgoing(item.attributes) && sourceId === item.get('conversationId')
|
||||
item => isOutgoing(item) && sourceId === item.conversationId
|
||||
);
|
||||
if (message) {
|
||||
return window.MessageController.register(message.id, message);
|
||||
}
|
||||
|
||||
const groups = await window.Signal.Data.getAllGroupsInvolvingUuid(
|
||||
sourceUuid,
|
||||
{
|
||||
ConversationCollection: window.Whisper.ConversationCollection,
|
||||
}
|
||||
);
|
||||
const groups = await window.Signal.Data.getAllGroupsInvolvingUuid(sourceUuid);
|
||||
|
||||
const ids = groups.pluck('id');
|
||||
const ids = groups.map(item => item.id);
|
||||
ids.push(sourceId);
|
||||
|
||||
const target = messages.find(
|
||||
item =>
|
||||
isOutgoing(item.attributes) && ids.includes(item.get('conversationId'))
|
||||
item => isOutgoing(item) && ids.includes(item.conversationId)
|
||||
);
|
||||
if (!target) {
|
||||
return null;
|
||||
|
@ -147,10 +140,7 @@ export class MessageReceipts extends Collection<MessageReceiptModel> {
|
|||
|
||||
try {
|
||||
const messages = await window.Signal.Data.getMessagesBySentAt(
|
||||
messageSentAt,
|
||||
{
|
||||
MessageCollection: window.Whisper.MessageCollection,
|
||||
}
|
||||
messageSentAt
|
||||
);
|
||||
|
||||
const message = await getTargetMessage(
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import { Collection, Model } from 'backbone';
|
||||
import type { MessageModel } from '../models/messages';
|
||||
import { getContactId, getContact } from '../messages/helpers';
|
||||
import { isOutgoing } from '../state/selectors/message';
|
||||
import type { ReactionAttributesType } from '../model-types.d';
|
||||
import * as log from '../logging/log';
|
||||
|
@ -35,7 +36,7 @@ export class Reactions extends Collection<ReactionModel> {
|
|||
}
|
||||
}
|
||||
|
||||
const senderId = message.getContactId();
|
||||
const senderId = getContactId(message.attributes);
|
||||
const sentAt = message.get('sent_at');
|
||||
const reactionsBySource = this.filter(re => {
|
||||
const targetSenderId = window.ConversationController.ensureContactIds({
|
||||
|
@ -87,15 +88,12 @@ export class Reactions extends Collection<ReactionModel> {
|
|||
log.info('Handling reaction for', reaction.get('targetTimestamp'));
|
||||
|
||||
const messages = await window.Signal.Data.getMessagesBySentAt(
|
||||
reaction.get('targetTimestamp'),
|
||||
{
|
||||
MessageCollection: window.Whisper.MessageCollection,
|
||||
}
|
||||
reaction.get('targetTimestamp')
|
||||
);
|
||||
// Message is fetched inside the conversation queue so we have the
|
||||
// most recent data
|
||||
const targetMessage = messages.find(m => {
|
||||
const contact = m.getContact();
|
||||
const contact = getContact(m);
|
||||
|
||||
if (!contact) {
|
||||
return false;
|
||||
|
|
|
@ -80,19 +80,16 @@ export class ReadSyncs extends Collection {
|
|||
async onSync(sync: ReadSyncModel): Promise<void> {
|
||||
try {
|
||||
const messages = await window.Signal.Data.getMessagesBySentAt(
|
||||
sync.get('timestamp'),
|
||||
{
|
||||
MessageCollection: window.Whisper.MessageCollection,
|
||||
}
|
||||
sync.get('timestamp')
|
||||
);
|
||||
|
||||
const found = messages.find(item => {
|
||||
const senderId = window.ConversationController.ensureContactIds({
|
||||
e164: item.get('source'),
|
||||
uuid: item.get('sourceUuid'),
|
||||
e164: item.source,
|
||||
uuid: item.sourceUuid,
|
||||
});
|
||||
|
||||
return isIncoming(item.attributes) && senderId === sync.get('senderId');
|
||||
return isIncoming(item) && senderId === sync.get('senderId');
|
||||
});
|
||||
|
||||
if (!found) {
|
||||
|
|
|
@ -57,16 +57,13 @@ export class ViewOnceOpenSyncs extends Collection<ViewOnceOpenSyncModel> {
|
|||
async onSync(sync: ViewOnceOpenSyncModel): Promise<void> {
|
||||
try {
|
||||
const messages = await window.Signal.Data.getMessagesBySentAt(
|
||||
sync.get('timestamp'),
|
||||
{
|
||||
MessageCollection: window.Whisper.MessageCollection,
|
||||
}
|
||||
sync.get('timestamp')
|
||||
);
|
||||
|
||||
const found = messages.find(item => {
|
||||
const itemSourceUuid = item.get('sourceUuid');
|
||||
const itemSourceUuid = item.sourceUuid;
|
||||
const syncSourceUuid = sync.get('sourceUuid');
|
||||
const itemSource = item.get('source');
|
||||
const itemSource = item.source;
|
||||
const syncSource = sync.get('source');
|
||||
|
||||
return Boolean(
|
||||
|
|
|
@ -58,19 +58,16 @@ export class ViewSyncs extends Collection {
|
|||
async onSync(sync: ViewSyncModel): Promise<void> {
|
||||
try {
|
||||
const messages = await window.Signal.Data.getMessagesBySentAt(
|
||||
sync.get('timestamp'),
|
||||
{
|
||||
MessageCollection: window.Whisper.MessageCollection,
|
||||
}
|
||||
sync.get('timestamp')
|
||||
);
|
||||
|
||||
const found = messages.find(item => {
|
||||
const senderId = window.ConversationController.ensureContactIds({
|
||||
e164: item.get('source'),
|
||||
uuid: item.get('sourceUuid'),
|
||||
e164: item.source,
|
||||
uuid: item.sourceUuid,
|
||||
});
|
||||
|
||||
return isIncoming(item.attributes) && senderId === sync.get('senderId');
|
||||
return isIncoming(item) && senderId === sync.get('senderId');
|
||||
});
|
||||
|
||||
if (!found) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue