From 097c502f9300185529022cb75f8219c573ee7557 Mon Sep 17 00:00:00 2001 From: Ezequiel de Oliveira Date: Fri, 8 May 2020 09:57:04 -0300 Subject: [PATCH] [IMPROVEMENT] Close announcement banner (#2064) * [NEW] Created new field in subscription table Signed-off-by: Ezequiel De Oliveira * [NEW] New field added to obeserver in room view Signed-off-by: Ezequiel De Oliveira * [NEW] Added icon and new design to banner Signed-off-by: Ezequiel De Oliveira * [NEW] Close banner function works Signed-off-by: Ezequiel De Oliveira * [IMPROVEMENT] closed banner status now update correctly Signed-off-by: Ezequiel De Oliveira * improve banner style Co-authored-by: Djorkaeff Alexandre Co-authored-by: Diego Mello --- app/lib/database/model/Subscription.js | 2 ++ app/lib/database/model/migrations.js | 11 +++++++++ app/lib/database/schema/app.js | 3 ++- .../methods/helpers/findSubscriptionsRooms.js | 1 + app/lib/methods/subscriptions/rooms.js | 6 +++++ app/sagas/rooms.js | 5 ++++ app/views/RoomView/Banner.js | 19 +++++++++++---- app/views/RoomView/index.js | 24 ++++++++++++++++--- app/views/RoomView/styles.js | 4 ++++ 9 files changed, 67 insertions(+), 8 deletions(-) diff --git a/app/lib/database/model/Subscription.js b/app/lib/database/model/Subscription.js index 37bab8c0..ba928da6 100644 --- a/app/lib/database/model/Subscription.js +++ b/app/lib/database/model/Subscription.js @@ -50,6 +50,8 @@ export default class Subscription extends Model { @field('announcement') announcement; + @field('banner_closed') bannerClosed; + @field('topic') topic; @field('blocked') blocked; diff --git a/app/lib/database/model/migrations.js b/app/lib/database/model/migrations.js index c8d81524..93414ab0 100644 --- a/app/lib/database/model/migrations.js +++ b/app/lib/database/model/migrations.js @@ -74,6 +74,17 @@ export default schemaMigrations({ ] }) ] + }, + { + toVersion: 8, + steps: [ + addColumns({ + table: 'subscriptions', + columns: [ + { name: 'banner_closed', type: 'boolean', isOptional: true } + ] + }) + ] } ] }); diff --git a/app/lib/database/schema/app.js b/app/lib/database/schema/app.js index a16cb547..dbd7a232 100644 --- a/app/lib/database/schema/app.js +++ b/app/lib/database/schema/app.js @@ -1,7 +1,7 @@ import { appSchema, tableSchema } from '@nozbe/watermelondb'; export default appSchema({ - version: 7, + version: 8, tables: [ tableSchema({ name: 'subscriptions', @@ -25,6 +25,7 @@ export default appSchema({ { name: 'last_message', type: 'string', isOptional: true }, { name: 'description', type: 'string', isOptional: true }, { name: 'announcement', type: 'string', isOptional: true }, + { name: 'banner_closed', type: 'boolean', isOptional: true }, { name: 'topic', type: 'string', isOptional: true }, { name: 'blocked', type: 'boolean', isOptional: true }, { name: 'blocker', type: 'boolean', isOptional: true }, diff --git a/app/lib/methods/helpers/findSubscriptionsRooms.js b/app/lib/methods/helpers/findSubscriptionsRooms.js index 9773c5f7..a0a9c5c2 100644 --- a/app/lib/methods/helpers/findSubscriptionsRooms.js +++ b/app/lib/methods/helpers/findSubscriptionsRooms.js @@ -27,6 +27,7 @@ export default async(subscriptions = [], rooms = []) => { lastOpen: s.lastOpen, description: s.description, announcement: s.announcement, + bannerClosed: s.bannerClosed, topic: s.topic, blocked: s.blocked, blocker: s.blocker, diff --git a/app/lib/methods/subscriptions/rooms.js b/app/lib/methods/subscriptions/rooms.js index 85e0ac3a..da1b50d9 100644 --- a/app/lib/methods/subscriptions/rooms.js +++ b/app/lib/methods/subscriptions/rooms.js @@ -57,6 +57,7 @@ const createOrUpdateSubscription = async(subscription, room) => { lastOpen: s.lastOpen, description: s.description, announcement: s.announcement, + bannerClosed: s.bannerClosed, topic: s.topic, blocked: s.blocked, blocker: s.blocker, @@ -121,6 +122,11 @@ const createOrUpdateSubscription = async(subscription, room) => { try { const update = sub.prepareUpdate((s) => { Object.assign(s, tmp); + if (subscription.announcement) { + if (subscription.announcement !== sub.announcement) { + s.bannerClosed = false; + } + } }); batch.push(update); } catch (e) { diff --git a/app/sagas/rooms.js b/app/sagas/rooms.js index 1b5940d1..4575120d 100644 --- a/app/sagas/rooms.js +++ b/app/sagas/rooms.js @@ -70,6 +70,11 @@ const handleRoomsRequest = function* handleRoomsRequest({ params }) { ...subsToUpdate.map((subscription) => { const newSub = subscriptions.find(s => s._id === subscription._id); return subscription.prepareUpdate(() => { + if (newSub.announcement) { + if (newSub.announcement !== subscription.announcement) { + subscription.bannerClosed = false; + } + } Object.assign(subscription, newSub); }); }), diff --git a/app/views/RoomView/Banner.js b/app/views/RoomView/Banner.js index a023fa1c..44ae55d1 100644 --- a/app/views/RoomView/Banner.js +++ b/app/views/RoomView/Banner.js @@ -6,17 +6,18 @@ import Modal from 'react-native-modal'; import Markdown from '../../containers/markdown'; +import { CustomIcon } from '../../lib/Icons'; import { themes } from '../../constants/colors'; import styles from './styles'; const Banner = React.memo(({ - text, title, theme + text, title, theme, bannerClosed, closeBanner }) => { const [showModal, openModal] = useState(false); const toggleModal = () => openModal(prevState => !prevState); - if (text) { + if (text && !bannerClosed) { return ( <> + + + prevProps.text === nextProps.text && prevProps.theme === nextProps.theme); +}, (prevProps, nextProps) => prevProps.text === nextProps.text && prevProps.theme === nextProps.theme && prevProps.bannerClosed === nextProps.bannerClosed); Banner.propTypes = { text: PropTypes.string, title: PropTypes.string, - theme: PropTypes.string + theme: PropTypes.string, + bannerClosed: PropTypes.bool, + closeBanner: PropTypes.func }; export default Banner; diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index 9599e032..345709b7 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -69,7 +69,7 @@ const stateAttrsUpdate = [ 'readOnly', 'member' ]; -const roomAttrsUpdate = ['f', 'ro', 'blocked', 'blocker', 'archived', 'muted', 'jitsiTimeout', 'announcement', 'sysMes', 'topic', 'name', 'fname', 'roles']; +const roomAttrsUpdate = ['f', 'ro', 'blocked', 'blocker', 'archived', 'muted', 'jitsiTimeout', 'announcement', 'sysMes', 'topic', 'name', 'fname', 'roles', 'bannerClosed']; class RoomView extends React.Component { static navigationOptions = ({ navigation, screenProps }) => { @@ -810,6 +810,20 @@ class RoomView extends React.Component { } }); + closeBanner = async() => { + const { room } = this.state; + try { + const db = database.active; + await db.action(async() => { + await room.update((r) => { + r.bannerClosed = true; + }); + }); + } catch { + // do nothing + } + }; + renderItem = (item, previousItem) => { const { room, lastOpen, canAutoTranslate } = this.state; const { @@ -988,7 +1002,9 @@ class RoomView extends React.Component { const { user, baseUrl, theme, navigation, Hide_System_Messages } = this.props; - const { rid, t, sysMes } = room; + const { + rid, t, sysMes, bannerClosed, announcement + } = room; return (