From 4def17c2e99773d1e43a82ea40b40aa6cdbf06c8 Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Mon, 29 Jun 2020 15:47:48 -0300 Subject: [PATCH] [IMPROVEMENT] Mark thread as read on open (#2225) * [IMPROVEMENT] Mark a thread as read * Use methodCallWrapper * Check server version Co-authored-by: Diego Mello --- app/lib/rocketchat.js | 8 ++++++++ app/views/RoomView/List.js | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 831d75790..06ff12eda 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -1141,6 +1141,14 @@ const RocketChat = { rid, updatedSince }); }, + readThreads(tmid) { + const serverVersion = reduxStore.getState().server.version; + if (serverVersion && semver.gte(semver.coerce(serverVersion), '3.4.0')) { + // RC 3.4.0 + return this.methodCallWrapper('readThreads', tmid); + } + return Promise.resolve(); + }, runSlashCommand(command, roomId, params, triggerId, tmid) { // RC 0.60.2 return this.post('commands.run', { diff --git a/app/views/RoomView/List.js b/app/views/RoomView/List.js index 4e58fe0fa..d0dc7c88d 100644 --- a/app/views/RoomView/List.js +++ b/app/views/RoomView/List.js @@ -115,6 +115,7 @@ class List extends React.Component { } else { this.state.messages = messages; } + this.readThreads(); }); } } @@ -125,6 +126,18 @@ class List extends React.Component { this.init(); } + readThreads = async() => { + const { tmid } = this.props; + + if (tmid) { + try { + await RocketChat.readThreads(tmid); + } catch { + // Do nothing + } + } + } + shouldComponentUpdate(nextProps, nextState) { const { loading, end, refreshing } = this.state; const { hideSystemMessages, theme } = this.props;