Use timestamp instead of full model for tap-to-view age outs
This commit is contained in:
parent
80da8bb47b
commit
f3e207d0b0
4 changed files with 15 additions and 30 deletions
|
@ -50,16 +50,11 @@
|
|||
const HOUR = 60 * MINUTE;
|
||||
const THIRTY_DAYS = 30 * 24 * HOUR;
|
||||
|
||||
const toAgeOut = await window.Signal.Data.getNextTapToViewMessageToAgeOut({
|
||||
Message: Whisper.Message,
|
||||
});
|
||||
|
||||
if (!toAgeOut) {
|
||||
const receivedAt = await window.Signal.Data.getNextTapToViewMessageTimestampToAgeOut();
|
||||
if (!receivedAt) {
|
||||
return;
|
||||
}
|
||||
|
||||
const receivedAt =
|
||||
toAgeOut.get('received_at_ms') || toAgeOut.get('received_at');
|
||||
const nextCheck = receivedAt + THIRTY_DAYS;
|
||||
|
||||
Whisper.TapToViewMessagesListener.nextCheck = nextCheck;
|
||||
|
|
|
@ -188,7 +188,7 @@ const dataInterface: ClientInterface = {
|
|||
getExpiredMessages,
|
||||
getOutgoingWithoutExpiresAt,
|
||||
getNextExpiringMessage,
|
||||
getNextTapToViewMessageToAgeOut,
|
||||
getNextTapToViewMessageTimestampToAgeOut,
|
||||
getTapToViewMessagesNeedingErase,
|
||||
getOlderMessagesByConversation,
|
||||
getNewerMessagesByConversation,
|
||||
|
@ -1324,17 +1324,8 @@ async function getNextExpiringMessage({
|
|||
return null;
|
||||
}
|
||||
|
||||
async function getNextTapToViewMessageToAgeOut({
|
||||
Message,
|
||||
}: {
|
||||
Message: typeof MessageModel;
|
||||
}) {
|
||||
const message = await channels.getNextTapToViewMessageToAgeOut();
|
||||
if (!message) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Message(message);
|
||||
async function getNextTapToViewMessageTimestampToAgeOut() {
|
||||
return channels.getNextTapToViewMessageTimestampToAgeOut();
|
||||
}
|
||||
async function getTapToViewMessagesNeedingErase({
|
||||
MessageCollection,
|
||||
|
|
|
@ -229,6 +229,7 @@ export type DataInterface = {
|
|||
obsoleteId: string,
|
||||
currentId: string
|
||||
) => Promise<void>;
|
||||
getNextTapToViewMessageTimestampToAgeOut: () => Promise<undefined | number>;
|
||||
|
||||
getUnprocessedCount: () => Promise<number>;
|
||||
getAllUnprocessed: () => Promise<Array<UnprocessedType>>;
|
||||
|
@ -359,7 +360,6 @@ export type ServerInterface = DataInterface & {
|
|||
ourConversationId: string;
|
||||
}) => Promise<MessageType | undefined>;
|
||||
getNextExpiringMessage: () => Promise<MessageType | undefined>;
|
||||
getNextTapToViewMessageToAgeOut: () => Promise<MessageType | undefined>;
|
||||
getOutgoingWithoutExpiresAt: () => Promise<Array<MessageType>>;
|
||||
getTapToViewMessagesNeedingErase: () => Promise<Array<MessageType>>;
|
||||
getUnreadCountForConversation: (conversationId: string) => Promise<number>;
|
||||
|
@ -497,9 +497,6 @@ export type ClientInterface = DataInterface & {
|
|||
getNextExpiringMessage: (options: {
|
||||
Message: typeof MessageModel;
|
||||
}) => Promise<MessageModel | null>;
|
||||
getNextTapToViewMessageToAgeOut: (options: {
|
||||
Message: typeof MessageModel;
|
||||
}) => Promise<MessageModel | null>;
|
||||
getOutgoingWithoutExpiresAt: (options: {
|
||||
MessageCollection: typeof MessageModelCollectionType;
|
||||
}) => Promise<MessageModelCollectionType>;
|
||||
|
|
|
@ -178,7 +178,7 @@ const dataInterface: ServerInterface = {
|
|||
getExpiredMessages,
|
||||
getOutgoingWithoutExpiresAt,
|
||||
getNextExpiringMessage,
|
||||
getNextTapToViewMessageToAgeOut,
|
||||
getNextTapToViewMessageTimestampToAgeOut,
|
||||
getTapToViewMessagesNeedingErase,
|
||||
getOlderMessagesByConversation,
|
||||
getNewerMessagesByConversation,
|
||||
|
@ -3924,11 +3924,11 @@ async function getNextExpiringMessage(): Promise<MessageType | undefined> {
|
|||
return jsonToObject(rows[0].json);
|
||||
}
|
||||
|
||||
async function getNextTapToViewMessageToAgeOut(): Promise<
|
||||
MessageType | undefined
|
||||
async function getNextTapToViewMessageTimestampToAgeOut(): Promise<
|
||||
undefined | number
|
||||
> {
|
||||
const db = getInstance();
|
||||
const rows = db
|
||||
const row = db
|
||||
.prepare<EmptyQuery>(
|
||||
`
|
||||
SELECT json FROM messages
|
||||
|
@ -3939,13 +3939,15 @@ async function getNextTapToViewMessageToAgeOut(): Promise<
|
|||
LIMIT 1;
|
||||
`
|
||||
)
|
||||
.all();
|
||||
.get();
|
||||
|
||||
if (!rows || rows.length < 1) {
|
||||
if (!row) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return jsonToObject(rows[0].json);
|
||||
const data = jsonToObject(row.json);
|
||||
const result = data.received_at_ms || data.received_at;
|
||||
return isNormalNumber(result) ? result : undefined;
|
||||
}
|
||||
|
||||
async function getTapToViewMessagesNeedingErase(): Promise<Array<MessageType>> {
|
||||
|
|
Loading…
Reference in a new issue