From 2aaa27d49ffe80c913fcfb889920196c70d5aecd Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Mon, 18 Nov 2019 19:09:54 -0300 Subject: [PATCH] [FIX] Crash when open thread (#1395) --- app/views/RoomView/Header/RightButtons.js | 24 ++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/views/RoomView/Header/RightButtons.js b/app/views/RoomView/Header/RightButtons.js index aca52a726..4a1c6c385 100644 --- a/app/views/RoomView/Header/RightButtons.js +++ b/app/views/RoomView/Header/RightButtons.js @@ -39,15 +39,15 @@ class RightButtonsContainer extends React.PureComponent { } async componentDidMount() { - const { tmid, userId } = this.props; + const { tmid } = this.props; if (tmid) { const db = database.active; - const threadObservable = await db.collections.get('messages').findAndObserve(tmid); - this.threadSubscription = threadObservable.subscribe((thread) => { - this.setState({ - isFollowingThread: thread.replies && !!thread.replies.find(t => t === userId) - }); - }); + try { + const threadRecord = await db.collections.get('messages').find(tmid); + this.observeThead(threadRecord); + } catch (e) { + console.log('Can\'t find message to observe.'); + } } } @@ -57,10 +57,16 @@ class RightButtonsContainer extends React.PureComponent { } } - updateThread = () => { + observeThead = (threadRecord) => { + const threadObservable = threadRecord.observe(); + this.threadSubscription = threadObservable + .subscribe(thread => this.updateThread(thread)); + } + + updateThread = (thread) => { const { userId } = this.props; this.setState({ - isFollowingThread: this.thread.replies && !!this.thread.replies.find(t => t === userId) + isFollowingThread: thread.replies && !!thread.replies.find(t => t === userId) }); }