From e1114c8ce7f8b5ca8708518283bb1532ef061ad3 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 5 Mar 2021 09:24:25 +1100 Subject: [PATCH] add some types to Data.ts calls --- ts/components/session/SessionInboxView.tsx | 3 +- ts/data/data.ts | 33 ++++++++++++++++++---- ts/models/conversation.ts | 8 ++++-- ts/receiver/cache.ts | 3 +- ts/receiver/queuedJob.ts | 3 ++ 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/ts/components/session/SessionInboxView.tsx b/ts/components/session/SessionInboxView.tsx index 923821458..a046ee0fe 100644 --- a/ts/components/session/SessionInboxView.tsx +++ b/ts/components/session/SessionInboxView.tsx @@ -2,6 +2,7 @@ import React from 'react'; import { Provider } from 'react-redux'; import { bindActionCreators } from 'redux'; import { getMessageById } from '../../data/data'; +import { ConversationModel } from '../../models/conversation'; import { MessageModel } from '../../models/message'; import { getMessageQueue } from '../../session'; import { ConversationController } from '../../session/conversations'; @@ -116,7 +117,7 @@ export class SessionInboxView extends React.Component { // Here we set up a full redux store with initial state for our LeftPane Root const convoCollection = ConversationController.getInstance().getConversations(); const conversations = convoCollection.map( - (conversation: any) => conversation.cachedProps + (conversation: ConversationModel) => conversation.getProps() ); const filledConversations = conversations.map((conv: any) => { diff --git a/ts/data/data.ts b/ts/data/data.ts index 48be92f28..ede8fffdb 100644 --- a/ts/data/data.ts +++ b/ts/data/data.ts @@ -9,6 +9,7 @@ import { ConversationModel, } from '../models/conversation'; import { MessageCollection, MessageModel } from '../models/message'; +import { MessageAttributes } from '../models/messageType'; import { HexKeyPair } from '../receiver/keypairs'; import { PubKey } from '../session/types'; import { @@ -671,23 +672,32 @@ export async function cleanLastHashes(): Promise { } // TODO: Strictly type the following -export async function saveSeenMessageHashes(data: any): Promise { +export async function saveSeenMessageHashes( + data: Array<{ + expiresAt: number; + hash: string; + }> +): Promise { await channels.saveSeenMessageHashes(_cleanData(data)); } -export async function updateLastHash(data: any): Promise { +export async function updateLastHash(data: { + convoId: string; + snode: string; + hash: string; + expiresAt: number; +}): Promise { await channels.updateLastHash(_cleanData(data)); } -export async function saveMessage(data: MessageModel): Promise { +export async function saveMessage(data: MessageAttributes): Promise { const id = await channels.saveMessage(_cleanData(data)); window.Whisper.ExpiringMessagesListener.update(); return id; } export async function saveMessages( - arrayOfMessages: any, - options?: { forceSave: boolean } + arrayOfMessages: Array ): Promise { await channels.saveMessages(_cleanData(arrayOfMessages)); } @@ -860,7 +870,18 @@ export async function getUnprocessedById(id: string): Promise { return channels.getUnprocessedById(id); } -export async function saveUnprocessed(data: any): Promise { +export type UnprocessedParameter = { + id: string; + version: number; + envelope: string; + timestamp: number; + attempts: number; + senderIdentity?: string; +}; + +export async function saveUnprocessed( + data: UnprocessedParameter +): Promise { const id = await channels.saveUnprocessed(_cleanData(data)); return id; } diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index c4393348a..c789a0b02 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -28,6 +28,7 @@ import { getUnreadCountByConversation, removeAllMessagesInConversation, removeMessage as dataRemoveMessage, + saveMessages, updateConversation, } from '../../ts/data/data'; import { @@ -481,7 +482,7 @@ export class ConversationModel extends Backbone.Model { await this.commit(); } - public async onReadMessage(message: any, readAt: any) { + public async onReadMessage(message: MessageModel, readAt: number) { // We mark as read everything older than this message - to clean up old stuff // still marked unread in the database. If the user generally doesn't read in // the desktop app, so the desktop app only gets read syncs, we can very @@ -1021,7 +1022,10 @@ export class ConversationModel extends Backbone.Model { } } - public async markRead(newestUnreadDate: any, providedOptions: any = {}) { + public async markReadBouncy( + newestUnreadDate: number, + providedOptions: any = {} + ) { const options = providedOptions || {}; _.defaults(options, { sendReadReceipts: true }); diff --git a/ts/receiver/cache.ts b/ts/receiver/cache.ts index 7e055a196..bce0cddee 100644 --- a/ts/receiver/cache.ts +++ b/ts/receiver/cache.ts @@ -8,6 +8,7 @@ import { removeAllUnprocessed, removeUnprocessed, saveUnprocessed, + UnprocessedParameter, updateUnprocessedAttempts, updateUnprocessedWithData, } from '../data/data'; @@ -27,7 +28,7 @@ export async function addToCache( window.log.info(`adding to cache envelope: ${id}`); const encodedEnvelope = StringUtils.decode(plaintext, 'base64'); - const data: any = { + const data: UnprocessedParameter = { id, version: 2, envelope: encodedEnvelope, diff --git a/ts/receiver/queuedJob.ts b/ts/receiver/queuedJob.ts index 900b600ab..784e28516 100644 --- a/ts/receiver/queuedJob.ts +++ b/ts/receiver/queuedJob.ts @@ -529,6 +529,9 @@ export async function handleMessageJob( const id = await message.commit(); message.set({ id }); + // this updates the redux store. + // if the convo on which this message should become visible, + // it will be shown to the user, and might as well be read right away window.Whisper.events.trigger('messageAdded', { conversationKey: conversation.id, messageModel: message,