From 734debe841bc7f59db7b7eca527280609728ef95 Mon Sep 17 00:00:00 2001 From: Vincent Date: Fri, 5 Jun 2020 10:13:59 +1000 Subject: [PATCH] PendingMessageCache Done --- .../session/LeftPaneMessageSection.tsx | 48 +++++++++++++++---- .../outgoing/content/sync/SyncMessage.ts | 2 +- ts/session/sending/PendingMessageCache.ts | 3 -- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/ts/components/session/LeftPaneMessageSection.tsx b/ts/components/session/LeftPaneMessageSection.tsx index e29b942b1..4c825a427 100644 --- a/ts/components/session/LeftPaneMessageSection.tsx +++ b/ts/components/session/LeftPaneMessageSection.tsx @@ -27,6 +27,12 @@ import { import { SessionSpinner } from './SessionSpinner'; import { joinChannelStateManager } from './LeftPaneChannelSection'; +// HIJACKING BUTTON FOR TESTING +import { PendingMessageCache } from '../../session/sending/PendingMessageCache'; +import { MessageQueue } from '../../session/sending'; +import { ExampleMessage } from '../../session/sending/MessageQueue'; + + export interface Props { searchTerm: string; isSecondaryDevice: boolean; @@ -45,6 +51,10 @@ export class LeftPaneMessageSection extends React.Component { private readonly updateSearchBound: (searchedString: string) => void; private readonly debouncedSearch: (searchTerm: string) => void; + // HIJACKED FOR TESTING + private readonly messageQueue: any; + private readonly pendingMessageCache: any; + public constructor(props: Props) { super(props); @@ -82,6 +92,11 @@ export class LeftPaneMessageSection extends React.Component { this.handleOnPasteSessionID = this.handleOnPasteSessionID.bind(this); this.handleMessageButtonClick = this.handleMessageButtonClick.bind(this); this.debouncedSearch = debounce(this.search.bind(this), 20); + + + // HIJACKING FOR TESTING + this.messageQueue = new MessageQueue(); + this.pendingMessageCache = new PendingMessageCache(); } public componentWillUnmount() { @@ -97,7 +112,7 @@ export class LeftPaneMessageSection extends React.Component { if (conversationList !== undefined) { conversationList = conversationList.filter( conversation => - !conversation.isSecondary && !conversation.isPendingFriendRequest + !conversation.isPendingFriendRequest && !conversation.isSecondary ); } @@ -361,12 +376,29 @@ export class LeftPaneMessageSection extends React.Component { ); } - private handleToggleOverlay() { - this.setState((state: any) => { - return { showComposeView: !state.showComposeView }; - }); - // empty our generalized searchedString (one for the whole app) - this.updateSearch(''); + private async handleToggleOverlay() { + // HIJACKING BUTTON FOR TESTING + console.log('[vince] pendingMessageCache:', this.pendingMessageCache); + + const pubkey = window.textsecure.storage.user.getNumber(); + const exampleMessage = new ExampleMessage(); + + console.log('[vince] exampleMessage:', exampleMessage); + + const devices = this.pendingMessageCache.getPendingDevices(); + console.log('[vince] devices:', devices); + + if ($('.session-search-input input').val()) { + this.pendingMessageCache.removePendingMessageByIdentifier(exampleMessage.identifier); + } else { + this.pendingMessageCache.addPendingMessage(pubkey, exampleMessage); + } + + // this.setState((state: any) => { + // return { showComposeView: !state.showComposeView }; + // }); + // // empty our generalized searchedString (one for the whole app) + // this.updateSearch(''); } private handleOnPasteSessionID(value: string) { @@ -408,4 +440,4 @@ export class LeftPaneMessageSection extends React.Component { const serverURL = window.CONSTANTS.DEFAULT_PUBLIC_CHAT_URL; joinChannelStateManager(this, serverURL, this.handleCloseOnboarding); } -} +} \ No newline at end of file diff --git a/ts/session/messages/outgoing/content/sync/SyncMessage.ts b/ts/session/messages/outgoing/content/sync/SyncMessage.ts index 30ba3d0fb..7321519a6 100644 --- a/ts/session/messages/outgoing/content/sync/SyncMessage.ts +++ b/ts/session/messages/outgoing/content/sync/SyncMessage.ts @@ -1,7 +1,7 @@ import { ContentMessage } from '../ContentMessage'; import { SignalService } from '../../../../../protobuf'; -export class SyncMessage extends ContentMessage { +export abstract class SyncMessage extends ContentMessage { public ttl(): number { return this.getDefaultTTL(); } diff --git a/ts/session/sending/PendingMessageCache.ts b/ts/session/sending/PendingMessageCache.ts index b2189af83..a43485665 100644 --- a/ts/session/sending/PendingMessageCache.ts +++ b/ts/session/sending/PendingMessageCache.ts @@ -3,9 +3,6 @@ import { RawMessage } from '../types/RawMessage'; import { ContentMessage } from '../messages/outgoing'; import * as MessageUtils from '../utils'; import { PubKey } from '../types'; -import logger from 'redux-logger'; - -// TODO: We should be able to import functions straight from the db here without going through the window object // This is an abstraction for storing pending messages. // Ideally we want to store pending messages in the database so that