remove the forceSave option for unprocessed message too

pull/1495/head
Audric Ackermann 4 years ago
parent 8a800cf58c
commit bb3641b39a

@ -2141,50 +2141,28 @@ async function getNextExpiringMessage() {
} }
/* Unproccessed a received messages not yet processed */ /* Unproccessed a received messages not yet processed */
async function saveUnprocessed(data, { forceSave } = {}) { async function saveUnprocessed(data) {
const { id, timestamp, version, attempts, envelope, senderIdentity } = data; const { id, timestamp, version, attempts, envelope, senderIdentity } = data;
if (!id) { if (!id) {
throw new Error(`saveUnprocessed: id was falsey: ${id}`); throw new Error(`saveUnprocessed: id was falsey: ${id}`);
} }
if (forceSave) {
await db.run(
`INSERT INTO unprocessed (
id,
timestamp,
version,
attempts,
envelope,
senderIdentity
) values (
$id,
$timestamp,
$version,
$attempts,
$envelope,
$senderIdentity
);`,
{
$id: id,
$timestamp: timestamp,
$version: version,
$attempts: attempts,
$envelope: envelope,
$senderIdentity: senderIdentity,
}
);
return id;
}
await db.run( await db.run(
`UPDATE unprocessed SET `INSERT OR REPLACE INTO unprocessed (
timestamp = $timestamp, id,
version = $version, timestamp,
attempts = $attempts, version,
envelope = $envelope, attempts,
senderIdentity = $senderIdentity envelope,
WHERE id = $id;`, senderIdentity
) values (
$id,
$timestamp,
$version,
$attempts,
$envelope,
$senderIdentity
);`,
{ {
$id: id, $id: id,
$timestamp: timestamp, $timestamp: timestamp,

@ -982,9 +982,7 @@ async function saveAllMessages(rawMessages) {
const { conversationId } = messages[0]; const { conversationId } = messages[0];
await window.Signal.Data.saveMessages(messages, { await window.Signal.Data.saveMessages(messages);
forceSave: true,
});
window.log.info( window.log.info(
'Saved', 'Saved',

@ -699,9 +699,7 @@ export async function saveMessages(
arrayOfMessages: any, arrayOfMessages: any,
options?: { forceSave: boolean } options?: { forceSave: boolean }
): Promise<void> { ): Promise<void> {
await channels.saveMessages(_cleanData(arrayOfMessages), { await channels.saveMessages(_cleanData(arrayOfMessages));
forceSave: options?.forceSave,
});
} }
export async function removeMessage(id: string): Promise<void> { export async function removeMessage(id: string): Promise<void> {
@ -872,16 +870,8 @@ export async function getUnprocessedById(id: string): Promise<any> {
return channels.getUnprocessedById(id); return channels.getUnprocessedById(id);
} }
export async function saveUnprocessed( export async function saveUnprocessed(data: any): Promise<string> {
data: any, const id = await channels.saveUnprocessed(_cleanData(data));
options?: {
forceSave: boolean;
}
): Promise<string> {
const id = await channels.saveUnprocessed(
_cleanData(data),
options?.forceSave || false
);
return id; return id;
} }

@ -128,7 +128,7 @@ export interface MessageAttributesOptionals {
export const fillMessageAttributesWithDefaults = ( export const fillMessageAttributesWithDefaults = (
optAttributes: MessageAttributesOptionals optAttributes: MessageAttributesOptionals
): MessageAttributes => { ): MessageAttributes => {
//FIXME audric to do put the default //FIXME to do put the default
return _.defaults(optAttributes, { return _.defaults(optAttributes, {
expireTimer: 0, // disabled expireTimer: 0, // disabled
id: uuidv4(), id: uuidv4(),

@ -24,6 +24,7 @@ export async function addToCache(
plaintext: ArrayBuffer plaintext: ArrayBuffer
) { ) {
const { id } = envelope; const { id } = envelope;
window.log.info(`adding to cache envelope: ${id}`);
const encodedEnvelope = StringUtils.decode(plaintext, 'base64'); const encodedEnvelope = StringUtils.decode(plaintext, 'base64');
const data: any = { const data: any = {
@ -37,7 +38,7 @@ export async function addToCache(
if (envelope.senderIdentity) { if (envelope.senderIdentity) {
data.senderIdentity = envelope.senderIdentity; data.senderIdentity = envelope.senderIdentity;
} }
return saveUnprocessed(data, { forceSave: true }); return saveUnprocessed(data);
} }
async function fetchAllFromCache(): Promise<Array<any>> { async function fetchAllFromCache(): Promise<Array<any>> {

@ -456,7 +456,6 @@ export function initIncomingMessage(data: MessageCreationData): MessageModel {
serverTimestamp, serverTimestamp,
} = data; } = data;
const type = 'incoming';
const messageGroupId = message?.group?.id; const messageGroupId = message?.group?.id;
let groupId = let groupId =
messageGroupId && messageGroupId.length > 0 ? messageGroupId : null; messageGroupId && messageGroupId.length > 0 ? messageGroupId : null;
@ -473,7 +472,7 @@ export function initIncomingMessage(data: MessageCreationData): MessageModel {
serverTimestamp, serverTimestamp,
received_at: receivedAt || Date.now(), received_at: receivedAt || Date.now(),
conversationId: groupId ?? source, conversationId: groupId ?? source,
type, type: 'incoming',
direction: 'incoming', // + direction: 'incoming', // +
unread: 1, // + unread: 1, // +
isPublic, // + isPublic, // +
@ -484,7 +483,6 @@ export function initIncomingMessage(data: MessageCreationData): MessageModel {
function createSentMessage(data: MessageCreationData): MessageModel { function createSentMessage(data: MessageCreationData): MessageModel {
const now = Date.now(); const now = Date.now();
let sentTo = [];
const { const {
timestamp, timestamp,

@ -109,7 +109,6 @@ async function handleRequestDetail(
options: ReqOptions, options: ReqOptions,
lastPromise: Promise<any> lastPromise: Promise<any>
): Promise<void> { ): Promise<void> {
const { textsecure } = window;
const envelope: any = SignalService.Envelope.decode(plaintext); const envelope: any = SignalService.Envelope.decode(plaintext);
// After this point, decoding errors are not the server's // After this point, decoding errors are not the server's

Loading…
Cancel
Save