From 0dd180d4f474b20d284648d91c065477cedf63c1 Mon Sep 17 00:00:00 2001 From: Beaudan Brown Date: Tue, 3 Sep 2019 13:54:53 +1000 Subject: [PATCH] Wrap polling function in try finally for safety, fix issue with empty array check and lint --- js/modules/loki_public_chat_api.js | 19 ++++++++++++----- ts/components/conversation/MessageDetail.tsx | 22 +++++++++----------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index c33552523..7ea7bdce3 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -411,6 +411,16 @@ class LokiPublicChannelAPI { // get channel messages async pollForMessages() { + try { + await this.pollOnceForMessages(); + } finally { + setTimeout(() => { + this.pollForMessages(); + }, GROUPCHAT_POLL_EVERY); + } + } + + async pollOnceForMessages() { const params = { include_annotations: 1, count: -20, @@ -437,7 +447,10 @@ class LokiPublicChannelAPI { if (adnMessage.is_deleted) { return; } - if (adnMessage.annotations !== []) { + if ( + Array.isArray(adnMessage.annotations) && + adnMessage.annotations.length !== 0 + ) { const noteValue = adnMessage.annotations[0].value; ({ from, timestamp, source } = noteValue); } @@ -493,10 +506,6 @@ class LokiPublicChannelAPI { }); conversation.setLastRetrievedMessage(this.lastGot); } - - setTimeout(() => { - this.pollForMessages(); - }, GROUPCHAT_POLL_EVERY); } // create a message in the channel diff --git a/ts/components/conversation/MessageDetail.tsx b/ts/components/conversation/MessageDetail.tsx index 1a18a780a..deca2a6b4 100644 --- a/ts/components/conversation/MessageDetail.tsx +++ b/ts/components/conversation/MessageDetail.tsx @@ -56,18 +56,16 @@ export class MessageDetail extends React.Component { public renderDeleteButton() { const { i18n, message } = this.props; - return ( - message.isDeletable ? ( -
- -
- ) : null - ); + return message.isDeletable ? ( +
+ +
+ ) : null; } public renderContact(contact: Contact) {