add some types to Data.ts calls

pull/1530/head
Audric Ackermann 5 years ago
parent 7da69f63da
commit e1114c8ce7
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -2,6 +2,7 @@ import React from 'react';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { getMessageById } from '../../data/data'; import { getMessageById } from '../../data/data';
import { ConversationModel } from '../../models/conversation';
import { MessageModel } from '../../models/message'; import { MessageModel } from '../../models/message';
import { getMessageQueue } from '../../session'; import { getMessageQueue } from '../../session';
import { ConversationController } from '../../session/conversations'; import { ConversationController } from '../../session/conversations';
@ -116,7 +117,7 @@ export class SessionInboxView extends React.Component<Props, State> {
// Here we set up a full redux store with initial state for our LeftPane Root // Here we set up a full redux store with initial state for our LeftPane Root
const convoCollection = ConversationController.getInstance().getConversations(); const convoCollection = ConversationController.getInstance().getConversations();
const conversations = convoCollection.map( const conversations = convoCollection.map(
(conversation: any) => conversation.cachedProps (conversation: ConversationModel) => conversation.getProps()
); );
const filledConversations = conversations.map((conv: any) => { const filledConversations = conversations.map((conv: any) => {

@ -9,6 +9,7 @@ import {
ConversationModel, ConversationModel,
} from '../models/conversation'; } from '../models/conversation';
import { MessageCollection, MessageModel } from '../models/message'; import { MessageCollection, MessageModel } from '../models/message';
import { MessageAttributes } from '../models/messageType';
import { HexKeyPair } from '../receiver/keypairs'; import { HexKeyPair } from '../receiver/keypairs';
import { PubKey } from '../session/types'; import { PubKey } from '../session/types';
import { import {
@ -671,23 +672,32 @@ export async function cleanLastHashes(): Promise<void> {
} }
// TODO: Strictly type the following // TODO: Strictly type the following
export async function saveSeenMessageHashes(data: any): Promise<void> { export async function saveSeenMessageHashes(
data: Array<{
expiresAt: number;
hash: string;
}>
): Promise<void> {
await channels.saveSeenMessageHashes(_cleanData(data)); await channels.saveSeenMessageHashes(_cleanData(data));
} }
export async function updateLastHash(data: any): Promise<void> { export async function updateLastHash(data: {
convoId: string;
snode: string;
hash: string;
expiresAt: number;
}): Promise<void> {
await channels.updateLastHash(_cleanData(data)); await channels.updateLastHash(_cleanData(data));
} }
export async function saveMessage(data: MessageModel): Promise<string> { export async function saveMessage(data: MessageAttributes): Promise<string> {
const id = await channels.saveMessage(_cleanData(data)); const id = await channels.saveMessage(_cleanData(data));
window.Whisper.ExpiringMessagesListener.update(); window.Whisper.ExpiringMessagesListener.update();
return id; return id;
} }
export async function saveMessages( export async function saveMessages(
arrayOfMessages: any, arrayOfMessages: Array<MessageAttributes>
options?: { forceSave: boolean }
): Promise<void> { ): Promise<void> {
await channels.saveMessages(_cleanData(arrayOfMessages)); await channels.saveMessages(_cleanData(arrayOfMessages));
} }
@ -860,7 +870,18 @@ export async function getUnprocessedById(id: string): Promise<any> {
return channels.getUnprocessedById(id); return channels.getUnprocessedById(id);
} }
export async function saveUnprocessed(data: any): Promise<string> { export type UnprocessedParameter = {
id: string;
version: number;
envelope: string;
timestamp: number;
attempts: number;
senderIdentity?: string;
};
export async function saveUnprocessed(
data: UnprocessedParameter
): Promise<string> {
const id = await channels.saveUnprocessed(_cleanData(data)); const id = await channels.saveUnprocessed(_cleanData(data));
return id; return id;
} }

@ -28,6 +28,7 @@ import {
getUnreadCountByConversation, getUnreadCountByConversation,
removeAllMessagesInConversation, removeAllMessagesInConversation,
removeMessage as dataRemoveMessage, removeMessage as dataRemoveMessage,
saveMessages,
updateConversation, updateConversation,
} from '../../ts/data/data'; } from '../../ts/data/data';
import { import {
@ -481,7 +482,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
await this.commit(); 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 // 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 // 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 // the desktop app, so the desktop app only gets read syncs, we can very
@ -1021,7 +1022,10 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
} }
public async markRead(newestUnreadDate: any, providedOptions: any = {}) { public async markReadBouncy(
newestUnreadDate: number,
providedOptions: any = {}
) {
const options = providedOptions || {}; const options = providedOptions || {};
_.defaults(options, { sendReadReceipts: true }); _.defaults(options, { sendReadReceipts: true });

@ -8,6 +8,7 @@ import {
removeAllUnprocessed, removeAllUnprocessed,
removeUnprocessed, removeUnprocessed,
saveUnprocessed, saveUnprocessed,
UnprocessedParameter,
updateUnprocessedAttempts, updateUnprocessedAttempts,
updateUnprocessedWithData, updateUnprocessedWithData,
} from '../data/data'; } from '../data/data';
@ -27,7 +28,7 @@ export async function addToCache(
window.log.info(`adding to cache envelope: ${id}`); 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: UnprocessedParameter = {
id, id,
version: 2, version: 2,
envelope: encodedEnvelope, envelope: encodedEnvelope,

@ -529,6 +529,9 @@ export async function handleMessageJob(
const id = await message.commit(); const id = await message.commit();
message.set({ id }); 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', { window.Whisper.events.trigger('messageAdded', {
conversationKey: conversation.id, conversationKey: conversation.id,
messageModel: message, messageModel: message,

Loading…
Cancel
Save