From 26138c9a973bc1b37e2cf17669868ec6a5afe5a4 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 10 Feb 2020 15:21:51 -0300 Subject: [PATCH 1/4] Add reselect --- package.json | 1 + yarn.lock | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/package.json b/package.json index c57c3dc17f9..0216c29e68a 100644 --- a/package.json +++ b/package.json @@ -96,6 +96,7 @@ "redux-immutable-state-invariant": "^2.1.0", "redux-saga": "1.1.3", "remove-markdown": "^0.3.0", + "reselect": "^4.0.0", "rn-extensions-share": "^2.3.10", "rn-fetch-blob": "0.11.2", "rn-root-view": "^1.0.3", diff --git a/yarn.lock b/yarn.lock index f67cb8297b5..6be1d43250f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10123,6 +10123,11 @@ requires-port@^1.0.0: resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8= +reselect@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/reselect/-/reselect-4.0.0.tgz#f2529830e5d3d0e021408b246a206ef4ea4437f7" + integrity sha512-qUgANli03jjAyGlnbYVAV5vvnOmJnODyABz51RdBN7M4WaVu8mecZWgyQNkG8Yqe3KRGRt0l4K4B3XVEULC4CA== + resize-observer-polyfill@^1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464" From c71d72ed89af31041d36e89043d921afb05c4ec4 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 10 Feb 2020 15:24:00 -0300 Subject: [PATCH 2/4] Add selector to user reducer calls --- app/containers/MessageBox/index.js | 7 ++----- app/notifications/inApp/index.js | 9 ++++----- app/selectors/login.js | 8 ++++++++ app/views/AdminPanelView/index.js | 9 +++++---- app/views/AttachmentView.js | 6 ++---- app/views/CreateChannelView.js | 6 ++---- app/views/DirectoryView/index.js | 6 ++---- app/views/LanguageView/index.js | 3 ++- app/views/MessagesView/index.js | 7 ++----- app/views/NewMessageView.js | 6 ++---- app/views/ProfileView/index.js | 10 ++-------- app/views/ReadReceiptView/index.js | 9 ++++----- app/views/RoomActionsView/index.js | 6 ++---- app/views/RoomInfoView/index.js | 6 ++---- app/views/RoomMembersView/index.js | 6 ++---- app/views/RoomView/Header/RightButtons.js | 3 ++- app/views/RoomView/Header/index.js | 7 ++++--- app/views/RoomView/index.js | 7 ++----- app/views/RoomsListView/index.js | 21 ++++++++++++--------- app/views/SearchMessagesView/index.js | 7 ++----- app/views/SelectedUsersView.js | 6 ++---- app/views/SetUsernameView.js | 3 ++- app/views/SettingsView/index.js | 3 ++- app/views/SidebarView/index.js | 10 ++-------- app/views/ThreadMessagesView/index.js | 7 ++----- 25 files changed, 75 insertions(+), 103 deletions(-) create mode 100644 app/selectors/login.js diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index 23ce62be180..5e1f6878521 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -43,6 +43,7 @@ import { } from './constants'; import CommandsPreview from './CommandsPreview'; import { Review } from '../../utils/review'; +import { getUserSelector } from '../../selectors/login'; const imagePickerConfig = { cropping: true, @@ -876,11 +877,7 @@ class MessageBox extends Component { const mapStateToProps = state => ({ baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', threadsEnabled: state.settings.Threads_enabled, - user: { - id: state.login.user && state.login.user.id, - username: state.login.user && state.login.user.username, - token: state.login.user && state.login.user.token - }, + user: getUserSelector(state), FileUpload_MediaTypeWhiteList: state.settings.FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize: state.settings.FileUpload_MaxFileSize }); diff --git a/app/notifications/inApp/index.js b/app/notifications/inApp/index.js index c03f2093d11..5af85b2b685 100644 --- a/app/notifications/inApp/index.js +++ b/app/notifications/inApp/index.js @@ -16,6 +16,7 @@ import { removeNotification as removeNotificationAction } from '../../actions/no import sharedStyles from '../../views/Styles'; import { ROW_HEIGHT } from '../../presentation/RoomItem'; import { withTheme } from '../../theme'; +import { getUserSelector } from '../../selectors/login'; const AVATAR_SIZE = 48; const ANIMATION_DURATION = 300; @@ -72,8 +73,7 @@ class NotificationBadge extends React.Component { static propTypes = { navigation: PropTypes.object, baseUrl: PropTypes.string, - token: PropTypes.string, - userId: PropTypes.string, + user: PropTypes.object, notification: PropTypes.object, window: PropTypes.object, removeNotification: PropTypes.func, @@ -173,7 +173,7 @@ class NotificationBadge extends React.Component { render() { const { - baseUrl, token, userId, notification, window, theme + baseUrl, user: { id: userId, token }, notification, window, theme } = this.props; const { message, payload } = notification; const { type } = payload; @@ -227,9 +227,8 @@ class NotificationBadge extends React.Component { } const mapStateToProps = state => ({ - userId: state.login.user && state.login.user.id, + user: getUserSelector(state), baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', - token: state.login.user && state.login.user.token, notification: state.notification }); diff --git a/app/selectors/login.js b/app/selectors/login.js new file mode 100644 index 00000000000..6bbba8b9f80 --- /dev/null +++ b/app/selectors/login.js @@ -0,0 +1,8 @@ +import { createSelector } from 'reselect'; + +const getUser = state => state.login.user || {}; + +export const getUserSelector = createSelector( + [getUser], + user => user +); diff --git a/app/views/AdminPanelView/index.js b/app/views/AdminPanelView/index.js index 1fc0ba02163..c6750fcacfc 100644 --- a/app/views/AdminPanelView/index.js +++ b/app/views/AdminPanelView/index.js @@ -11,6 +11,7 @@ import styles from '../Styles'; import { themedHeader } from '../../utils/navigation'; import { withTheme } from '../../theme'; import { themes } from '../../constants/colors'; +import { getUserSelector } from '../../selectors/login'; class AdminPanelView extends React.Component { static navigationOptions = ({ navigation, screenProps }) => ({ @@ -21,12 +22,12 @@ class AdminPanelView extends React.Component { static propTypes = { baseUrl: PropTypes.string, - authToken: PropTypes.string, + token: PropTypes.string, theme: PropTypes.string } render() { - const { baseUrl, authToken, theme } = this.props; + const { baseUrl, token, theme } = this.props; if (!baseUrl) { return null; } @@ -35,7 +36,7 @@ class AdminPanelView extends React.Component { ); @@ -44,7 +45,7 @@ class AdminPanelView extends React.Component { const mapStateToProps = state => ({ baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', - authToken: state.login.user && state.login.user.token + token: getUserSelector(state).token }); export default connect(mapStateToProps)(withTheme(AdminPanelView)); diff --git a/app/views/AttachmentView.js b/app/views/AttachmentView.js index 8b86ece697c..92004446ced 100644 --- a/app/views/AttachmentView.js +++ b/app/views/AttachmentView.js @@ -19,6 +19,7 @@ import { formatAttachmentUrl } from '../lib/utils'; import RCActivityIndicator from '../containers/ActivityIndicator'; import { SaveButton, CloseModalButton } from '../containers/HeaderButton'; import { isAndroid } from '../utils/deviceInfo'; +import { getUserSelector } from '../selectors/login'; const styles = StyleSheet.create({ container: { @@ -143,10 +144,7 @@ class AttachmentView extends React.Component { const mapStateToProps = state => ({ baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', - user: { - id: state.login.user && state.login.user.id, - token: state.login.user && state.login.user.token - } + user: getUserSelector(state) }); export default connect(mapStateToProps)(withTheme(AttachmentView)); diff --git a/app/views/CreateChannelView.js b/app/views/CreateChannelView.js index 3b19fb9e6cb..34dbb91bea9 100644 --- a/app/views/CreateChannelView.js +++ b/app/views/CreateChannelView.js @@ -23,6 +23,7 @@ import { SWITCH_TRACK_COLOR, themes } from '../constants/colors'; import { withTheme } from '../theme'; import { themedHeader } from '../utils/navigation'; import { Review } from '../utils/review'; +import { getUserSelector } from '../selectors/login'; const styles = StyleSheet.create({ container: { @@ -371,10 +372,7 @@ const mapStateToProps = state => ({ isFetching: state.createChannel.isFetching, result: state.createChannel.result, users: state.selectedUsers.users, - user: { - id: state.login.user && state.login.user.id, - token: state.login.user && state.login.user.token - } + user: getUserSelector(state) }); const mapDispatchToProps = dispatch => ({ diff --git a/app/views/DirectoryView/index.js b/app/views/DirectoryView/index.js index 0f91b2caaa0..51ab7a4af78 100644 --- a/app/views/DirectoryView/index.js +++ b/app/views/DirectoryView/index.js @@ -23,6 +23,7 @@ import { withTheme } from '../../theme'; import { themes } from '../../constants/colors'; import styles from './styles'; import { themedHeader } from '../../utils/navigation'; +import { getUserSelector } from '../../selectors/login'; class DirectoryView extends React.Component { static navigationOptions = ({ navigation, screenProps }) => { @@ -254,10 +255,7 @@ class DirectoryView extends React.Component { const mapStateToProps = state => ({ baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', - user: { - id: state.login.user && state.login.user.id, - token: state.login.user && state.login.user.token - }, + user: getUserSelector(state), isFederationEnabled: state.settings.FEDERATION_Enabled }); diff --git a/app/views/LanguageView/index.js b/app/views/LanguageView/index.js index e342795d03e..e20f9d7d579 100644 --- a/app/views/LanguageView/index.js +++ b/app/views/LanguageView/index.js @@ -18,6 +18,7 @@ import Separator from '../../containers/Separator'; import { themes } from '../../constants/colors'; import { withTheme } from '../../theme'; import { themedHeader } from '../../utils/navigation'; +import { getUserSelector } from '../../selectors/login'; const LANGUAGES = [ { @@ -182,7 +183,7 @@ class LanguageView extends React.Component { } const mapStateToProps = state => ({ - userLanguage: state.login.user && state.login.user.language + userLanguage: getUserSelector(state).language }); const mapDispatchToProps = dispatch => ({ diff --git a/app/views/MessagesView/index.js b/app/views/MessagesView/index.js index 4736f394f94..f72cda72671 100644 --- a/app/views/MessagesView/index.js +++ b/app/views/MessagesView/index.js @@ -17,6 +17,7 @@ import { themes } from '../../constants/colors'; import { withTheme } from '../../theme'; import { withSplit } from '../../split'; import { themedHeader } from '../../utils/navigation'; +import { getUserSelector } from '../../selectors/login'; const ACTION_INDEX = 0; const CANCEL_INDEX = 1; @@ -307,11 +308,7 @@ class MessagesView extends React.Component { const mapStateToProps = state => ({ baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', - user: { - id: state.login.user && state.login.user.id, - username: state.login.user && state.login.user.username, - token: state.login.user && state.login.user.token - }, + user: getUserSelector(state), customEmojis: state.customEmojis }); diff --git a/app/views/NewMessageView.js b/app/views/NewMessageView.js index e16f3d8ca65..873d35e768a 100644 --- a/app/views/NewMessageView.js +++ b/app/views/NewMessageView.js @@ -23,6 +23,7 @@ import StatusBar from '../containers/StatusBar'; import { themes } from '../constants/colors'; import { withTheme } from '../theme'; import { themedHeader } from '../utils/navigation'; +import { getUserSelector } from '../selectors/login'; const styles = StyleSheet.create({ safeAreaView: { @@ -228,10 +229,7 @@ class NewMessageView extends React.Component { const mapStateToProps = state => ({ baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', - user: { - id: state.login.user && state.login.user.id, - token: state.login.user && state.login.user.token - } + user: getUserSelector(state) }); export default connect(mapStateToProps)(withTheme(NewMessageView)); diff --git a/app/views/ProfileView/index.js b/app/views/ProfileView/index.js index 3121db989b6..f2a1bbfebd9 100644 --- a/app/views/ProfileView/index.js +++ b/app/views/ProfileView/index.js @@ -31,6 +31,7 @@ import StatusBar from '../../containers/StatusBar'; import { themes } from '../../constants/colors'; import { withTheme } from '../../theme'; import { themedHeader } from '../../utils/navigation'; +import { getUserSelector } from '../../selectors/login'; class ProfileView extends React.Component { static navigationOptions = ({ navigation, screenProps }) => ({ @@ -497,14 +498,7 @@ class ProfileView extends React.Component { } const mapStateToProps = state => ({ - user: { - id: state.login.user && state.login.user.id, - name: state.login.user && state.login.user.name, - username: state.login.user && state.login.user.username, - customFields: state.login.user && state.login.user.customFields, - emails: state.login.user && state.login.user.emails, - token: state.login.user && state.login.user.token - }, + user: getUserSelector(state), Accounts_CustomFields: state.settings.Accounts_CustomFields, baseUrl: state.settings.Site_Url || state.server ? state.server.server : '' }); diff --git a/app/views/ReadReceiptView/index.js b/app/views/ReadReceiptView/index.js index d5d90fcd135..1ff1e3ac1c3 100644 --- a/app/views/ReadReceiptView/index.js +++ b/app/views/ReadReceiptView/index.js @@ -15,6 +15,7 @@ import StatusBar from '../../containers/StatusBar'; import { withTheme } from '../../theme'; import { themedHeader } from '../../utils/navigation'; import { themes } from '../../constants/colors'; +import { getUserSelector } from '../../selectors/login'; class ReadReceiptView extends React.Component { static navigationOptions = ({ screenProps }) => ({ @@ -26,8 +27,7 @@ class ReadReceiptView extends React.Component { navigation: PropTypes.object, Message_TimeFormat: PropTypes.string, baseUrl: PropTypes.string, - userId: PropTypes.string, - token: PropTypes.string, + user: PropTypes.object, theme: PropTypes.string } @@ -92,7 +92,7 @@ class ReadReceiptView extends React.Component { renderItem = ({ item }) => { const { - Message_TimeFormat, userId, baseUrl, token, theme + Message_TimeFormat, user: { id: userId, token }, baseUrl, theme } = this.props; const time = moment(item.ts).format(Message_TimeFormat); return ( @@ -168,8 +168,7 @@ class ReadReceiptView extends React.Component { const mapStateToProps = state => ({ Message_TimeFormat: state.settings.Message_TimeFormat, baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', - userId: state.login.user && state.login.user.id, - token: state.login.user && state.login.user.token + user: getUserSelector(state) }); export default connect(mapStateToProps)(withTheme(ReadReceiptView)); diff --git a/app/views/RoomActionsView/index.js b/app/views/RoomActionsView/index.js index 18e4a05796a..e611c479345 100644 --- a/app/views/RoomActionsView/index.js +++ b/app/views/RoomActionsView/index.js @@ -24,6 +24,7 @@ import { themes } from '../../constants/colors'; import { withTheme } from '../../theme'; import { themedHeader } from '../../utils/navigation'; import { CloseModalButton } from '../../containers/HeaderButton'; +import { getUserSelector } from '../../selectors/login'; class RoomActionsView extends React.Component { static navigationOptions = ({ navigation, screenProps }) => { @@ -523,10 +524,7 @@ class RoomActionsView extends React.Component { } const mapStateToProps = state => ({ - user: { - id: state.login.user && state.login.user.id, - token: state.login.user && state.login.user.token - }, + user: getUserSelector(state), baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', jitsiEnabled: state.settings.Jitsi_Enabled || false }); diff --git a/app/views/RoomInfoView/index.js b/app/views/RoomInfoView/index.js index ada9df185a0..568944a74ad 100644 --- a/app/views/RoomInfoView/index.js +++ b/app/views/RoomInfoView/index.js @@ -19,6 +19,7 @@ import log from '../../utils/log'; import { themes } from '../../constants/colors'; import { withTheme } from '../../theme'; import { themedHeader } from '../../utils/navigation'; +import { getUserSelector } from '../../selectors/login'; const PERMISSION_EDIT_ROOM = 'edit-room'; @@ -310,10 +311,7 @@ class RoomInfoView extends React.Component { const mapStateToProps = state => ({ baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', - user: { - id: state.login.user && state.login.user.id, - token: state.login.user && state.login.user.token - }, + user: getUserSelector(state), Message_TimeFormat: state.settings.Message_TimeFormat }); diff --git a/app/views/RoomMembersView/index.js b/app/views/RoomMembersView/index.js index 40b59d29854..787cae1036e 100644 --- a/app/views/RoomMembersView/index.js +++ b/app/views/RoomMembersView/index.js @@ -24,6 +24,7 @@ import ActivityIndicator from '../../containers/ActivityIndicator'; import { withTheme } from '../../theme'; import { themedHeader } from '../../utils/navigation'; import { themes } from '../../constants/colors'; +import { getUserSelector } from '../../selectors/login'; const PAGE_SIZE = 25; @@ -288,10 +289,7 @@ class RoomMembersView extends React.Component { const mapStateToProps = state => ({ baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', - user: { - id: state.login.user && state.login.user.id, - token: state.login.user && state.login.user.token - } + user: getUserSelector(state) }); export default connect(mapStateToProps)(withTheme(RoomMembersView)); diff --git a/app/views/RoomView/Header/RightButtons.js b/app/views/RoomView/Header/RightButtons.js index 87a4d6d153d..b1c6e90d292 100644 --- a/app/views/RoomView/Header/RightButtons.js +++ b/app/views/RoomView/Header/RightButtons.js @@ -4,6 +4,7 @@ import { connect } from 'react-redux'; import { CustomHeaderButtons, Item } from '../../../containers/HeaderButton'; import database from '../../../lib/database'; +import { getUserSelector } from '../../../selectors/login'; class RightButtonsContainer extends React.PureComponent { static propTypes = { @@ -102,7 +103,7 @@ class RightButtonsContainer extends React.PureComponent { } const mapStateToProps = state => ({ - userId: state.login.user && state.login.user.id, + userId: getUserSelector(state).id, threadsEnabled: state.settings.Threads_enabled }); diff --git a/app/views/RoomView/Header/index.js b/app/views/RoomView/Header/index.js index 4911be2d3a5..145e22792f7 100644 --- a/app/views/RoomView/Header/index.js +++ b/app/views/RoomView/Header/index.js @@ -8,6 +8,7 @@ import Header from './Header'; import RightButtons from './RightButtons'; import { withTheme } from '../../../theme'; import RoomHeaderLeft from './RoomHeaderLeft'; +import { getUserSelector } from '../../../selectors/login'; class RoomHeaderView extends Component { static propTypes = { @@ -86,9 +87,9 @@ const mapStateToProps = (state, ownProps) => { let status; const { rid, type } = ownProps; if (type === 'd') { - if (state.login.user && state.login.user.id) { - const { id: loggedUserId } = state.login.user; - const userId = rid.replace(loggedUserId, '').trim(); + const user = getUserSelector(state); + if (user.id) { + const userId = rid.replace(user.id, '').trim(); status = state.activeUsers[userId]; } } diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index 5b1ccb41adf..8f488026b28 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -49,6 +49,7 @@ import { import ModalNavigation from '../../lib/ModalNavigation'; import { Review } from '../../utils/review'; import RoomClass from '../../lib/methods/subscriptions/room'; +import { getUserSelector } from '../../selectors/login'; const stateAttrsUpdate = [ 'joined', @@ -922,11 +923,7 @@ class RoomView extends React.Component { } const mapStateToProps = state => ({ - user: { - id: state.login.user && state.login.user.id, - username: state.login.user && state.login.user.username, - token: state.login.user && state.login.user.token - }, + user: getUserSelector(state), appState: state.app.ready && state.app.foreground ? 'foreground' : 'background', useRealName: state.settings.UI_Use_Real_Name, isAuthenticated: state.login.isAuthenticated, diff --git a/app/views/RoomsListView/index.js b/app/views/RoomsListView/index.js index 468370a7ea6..8036fff2bfd 100644 --- a/app/views/RoomsListView/index.js +++ b/app/views/RoomsListView/index.js @@ -59,6 +59,7 @@ import { } from '../../commands'; import { MAX_SIDEBAR_WIDTH } from '../../constants/tablet'; import { withSplit } from '../../split'; +import { getUserSelector } from '../../selectors/login'; const SCROLL_OFFSET = 56; const INITIAL_NUM_TO_RENDER = isTablet ? 20 : 12; @@ -148,9 +149,11 @@ class RoomsListView extends React.Component { static propTypes = { navigation: PropTypes.object, - userId: PropTypes.string, - username: PropTypes.string, - token: PropTypes.string, + user: PropTypes.shape({ + id: PropTypes.string, + username: PropTypes.string, + token: PropTypes.string + }), baseUrl: PropTypes.string, server: PropTypes.string, searchText: PropTypes.string, @@ -700,9 +703,11 @@ class RoomsListView extends React.Component { const { width } = this.state; const { - userId, - username, - token, + user: { + id: userId, + username, + token + }, baseUrl, StoreLastMessage, theme, @@ -815,9 +820,7 @@ class RoomsListView extends React.Component { } const mapStateToProps = state => ({ - userId: state.login.user && state.login.user.id, - username: state.login.user && state.login.user.username, - token: state.login.user && state.login.user.token, + user: getUserSelector(state), server: state.server.server, baseUrl: state.settings.baseUrl || state.server ? state.server.server : '', searchText: state.rooms.searchText, diff --git a/app/views/SearchMessagesView/index.js b/app/views/SearchMessagesView/index.js index 9b03ccb92a7..c666fb5f3cb 100644 --- a/app/views/SearchMessagesView/index.js +++ b/app/views/SearchMessagesView/index.js @@ -19,6 +19,7 @@ import log from '../../utils/log'; import { themes } from '../../constants/colors'; import { withTheme } from '../../theme'; import { themedHeader } from '../../utils/navigation'; +import { getUserSelector } from '../../selectors/login'; class SearchMessagesView extends React.Component { static navigationOptions = ({ screenProps }) => ({ @@ -168,11 +169,7 @@ class SearchMessagesView extends React.Component { const mapStateToProps = state => ({ baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', - user: { - id: state.login.user && state.login.user.id, - username: state.login.user && state.login.user.username, - token: state.login.user && state.login.user.token - }, + user: getUserSelector(state), customEmojis: state.customEmojis }); diff --git a/app/views/SelectedUsersView.js b/app/views/SelectedUsersView.js index 82055075d35..5ff0547e020 100644 --- a/app/views/SelectedUsersView.js +++ b/app/views/SelectedUsersView.js @@ -25,6 +25,7 @@ import { themes } from '../constants/colors'; import { animateNextTransition } from '../utils/layoutAnimation'; import { withTheme } from '../theme'; import { themedHeader } from '../utils/navigation'; +import { getUserSelector } from '../selectors/login'; const styles = StyleSheet.create({ safeAreaView: { @@ -308,10 +309,7 @@ const mapStateToProps = state => ({ baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', users: state.selectedUsers.users, loading: state.selectedUsers.loading, - user: { - id: state.login.user && state.login.user.id, - token: state.login.user && state.login.user.token - } + user: getUserSelector(state) }); const mapDispatchToProps = dispatch => ({ diff --git a/app/views/SetUsernameView.js b/app/views/SetUsernameView.js index 4c3c37abbb8..93d31829f49 100644 --- a/app/views/SetUsernameView.js +++ b/app/views/SetUsernameView.js @@ -21,6 +21,7 @@ import { themedHeader } from '../utils/navigation'; import { withTheme } from '../theme'; import { themes } from '../constants/colors'; import { isTablet } from '../utils/deviceInfo'; +import { getUserSelector } from '../selectors/login'; const styles = StyleSheet.create({ loginTitle: { @@ -161,7 +162,7 @@ class SetUsernameView extends React.Component { const mapStateToProps = state => ({ server: state.server.server, - token: state.login.user && state.login.user.token + token: getUserSelector(state).token }); const mapDispatchToProps = dispatch => ({ diff --git a/app/views/SettingsView/index.js b/app/views/SettingsView/index.js index 17cd34ef029..022b11663da 100644 --- a/app/views/SettingsView/index.js +++ b/app/views/SettingsView/index.js @@ -36,6 +36,7 @@ import { LISTENER } from '../../containers/Toast'; import EventEmitter from '../../utils/events'; import { appStart as appStartAction } from '../../actions'; import { onReviewPress } from '../../utils/review'; +import { getUserSelector } from '../../selectors/login'; const SectionSeparator = React.memo(({ theme }) => ( ({ server: state.server, - token: state.login.user && state.login.user.token, + token: getUserSelector(state).token, useMarkdown: state.markdown.useMarkdown, allowCrashReport: state.crashReport.allowCrashReport }); diff --git a/app/views/SidebarView/index.js b/app/views/SidebarView/index.js index 7a83fb9ef01..75d0e517448 100644 --- a/app/views/SidebarView/index.js +++ b/app/views/SidebarView/index.js @@ -22,6 +22,7 @@ import database from '../../lib/database'; import { animateNextTransition } from '../../utils/layoutAnimation'; import { withTheme } from '../../theme'; import { withSplit } from '../../split'; +import { getUserSelector } from '../../selectors/login'; const keyExtractor = item => item.id; @@ -297,14 +298,7 @@ class Sidebar extends Component { const mapStateToProps = state => ({ Site_Name: state.settings.Site_Name, - user: { - id: state.login.user && state.login.user.id, - language: state.login.user && state.login.user.language, - status: state.login.user && state.login.user.status, - username: state.login.user && state.login.user.username, - token: state.login.user && state.login.user.token, - roles: state.login.user && state.login.user.roles - }, + user: getUserSelector(state), baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', loadingServer: state.server.loading }); diff --git a/app/views/ThreadMessagesView/index.js b/app/views/ThreadMessagesView/index.js index 6a953340cf6..97198e1db7b 100644 --- a/app/views/ThreadMessagesView/index.js +++ b/app/views/ThreadMessagesView/index.js @@ -25,6 +25,7 @@ import { themes } from '../../constants/colors'; import { withTheme } from '../../theme'; import { themedHeader } from '../../utils/navigation'; import ModalNavigation from '../../lib/ModalNavigation'; +import { getUserSelector } from '../../selectors/login'; const Separator = React.memo(({ theme }) => ); Separator.propTypes = { @@ -349,11 +350,7 @@ class ThreadMessagesView extends React.Component { const mapStateToProps = state => ({ baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', - user: { - id: state.login.user && state.login.user.id, - username: state.login.user && state.login.user.username, - token: state.login.user && state.login.user.token - }, + user: getUserSelector(state), useRealName: state.settings.UI_Use_Real_Name, customEmojis: state.customEmojis }); From df62dcd45ca628cf21cc96f2ceedd101373bbcc3 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 10 Feb 2020 15:29:00 -0300 Subject: [PATCH 3/4] Use server url instead of Site_Url --- app/containers/MessageBox/EmojiKeyboard.js | 2 +- app/containers/MessageBox/ReplyPreview.js | 2 +- app/containers/MessageBox/index.js | 2 +- app/lib/methods/sendFileMessage.js | 6 +----- app/notifications/inApp/index.js | 2 +- app/views/AdminPanelView/index.js | 2 +- app/views/AttachmentView.js | 2 +- app/views/CreateChannelView.js | 2 +- app/views/DirectoryView/index.js | 2 +- app/views/MessagesView/index.js | 2 +- app/views/NewMessageView.js | 2 +- app/views/ProfileView/index.js | 2 +- app/views/ReadReceiptView/index.js | 2 +- app/views/RoomActionsView/index.js | 2 +- app/views/RoomInfoView/index.js | 2 +- app/views/RoomMembersView/index.js | 2 +- app/views/RoomView/ReactionPicker.js | 2 +- app/views/RoomView/index.js | 2 +- app/views/RoomsListView/index.js | 6 ++---- app/views/SearchMessagesView/index.js | 2 +- app/views/SelectedUsersView.js | 2 +- app/views/ShareListView/index.js | 8 +++----- app/views/ShareView/index.js | 4 ++-- app/views/SidebarView/index.js | 2 +- app/views/ThreadMessagesView/index.js | 2 +- 25 files changed, 29 insertions(+), 37 deletions(-) diff --git a/app/containers/MessageBox/EmojiKeyboard.js b/app/containers/MessageBox/EmojiKeyboard.js index 6f65d6fe4b5..f8bc13019b4 100644 --- a/app/containers/MessageBox/EmojiKeyboard.js +++ b/app/containers/MessageBox/EmojiKeyboard.js @@ -17,7 +17,7 @@ export default class EmojiKeyboard extends React.PureComponent { constructor(props) { super(props); const state = store.getState(); - this.baseUrl = state.settings.Site_Url || state.server ? state.server.server : ''; + this.baseUrl = state.server.server; } onEmojiSelected = (emoji) => { diff --git a/app/containers/MessageBox/ReplyPreview.js b/app/containers/MessageBox/ReplyPreview.js index 97d0cd5b729..54d872ebdac 100644 --- a/app/containers/MessageBox/ReplyPreview.js +++ b/app/containers/MessageBox/ReplyPreview.js @@ -92,7 +92,7 @@ ReplyPreview.propTypes = { const mapStateToProps = state => ({ useMarkdown: state.markdown.useMarkdown, Message_TimeFormat: state.settings.Message_TimeFormat, - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '' + baseUrl: state.server.server }); export default connect(mapStateToProps)(ReplyPreview); diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index 5e1f6878521..e7f7b71714e 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -875,7 +875,7 @@ class MessageBox extends Component { } const mapStateToProps = state => ({ - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, threadsEnabled: state.settings.Threads_enabled, user: getUserSelector(state), FileUpload_MediaTypeWhiteList: state.settings.FileUpload_MediaTypeWhiteList, diff --git a/app/lib/methods/sendFileMessage.js b/app/lib/methods/sendFileMessage.js index 51133915867..6297d645f3f 100644 --- a/app/lib/methods/sendFileMessage.js +++ b/app/lib/methods/sendFileMessage.js @@ -28,13 +28,9 @@ export async function cancelUpload(item) { export function sendFileMessage(rid, fileInfo, tmid, server, user) { return new Promise(async(resolve, reject) => { try { - const serversDB = database.servers; - const serversCollection = serversDB.collections.get('servers'); - const serverInfo = await serversCollection.find(server); - const { id: Site_Url } = serverInfo; const { id, token } = user; - const uploadUrl = `${ Site_Url }/api/v1/rooms.upload/${ rid }`; + const uploadUrl = `${ server }/api/v1/rooms.upload/${ rid }`; const xhr = new XMLHttpRequest(); const formData = new FormData(); diff --git a/app/notifications/inApp/index.js b/app/notifications/inApp/index.js index 5af85b2b685..9c562397348 100644 --- a/app/notifications/inApp/index.js +++ b/app/notifications/inApp/index.js @@ -228,7 +228,7 @@ class NotificationBadge extends React.Component { const mapStateToProps = state => ({ user: getUserSelector(state), - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, notification: state.notification }); diff --git a/app/views/AdminPanelView/index.js b/app/views/AdminPanelView/index.js index c6750fcacfc..3bda33ffe4b 100644 --- a/app/views/AdminPanelView/index.js +++ b/app/views/AdminPanelView/index.js @@ -44,7 +44,7 @@ class AdminPanelView extends React.Component { } const mapStateToProps = state => ({ - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, token: getUserSelector(state).token }); diff --git a/app/views/AttachmentView.js b/app/views/AttachmentView.js index 92004446ced..e89893d202c 100644 --- a/app/views/AttachmentView.js +++ b/app/views/AttachmentView.js @@ -143,7 +143,7 @@ class AttachmentView extends React.Component { } const mapStateToProps = state => ({ - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, user: getUserSelector(state) }); diff --git a/app/views/CreateChannelView.js b/app/views/CreateChannelView.js index 34dbb91bea9..78564735393 100644 --- a/app/views/CreateChannelView.js +++ b/app/views/CreateChannelView.js @@ -366,7 +366,7 @@ class CreateChannelView extends React.Component { } const mapStateToProps = state => ({ - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, error: state.createChannel.error, failure: state.createChannel.failure, isFetching: state.createChannel.isFetching, diff --git a/app/views/DirectoryView/index.js b/app/views/DirectoryView/index.js index 51ab7a4af78..51c7b4f2b8c 100644 --- a/app/views/DirectoryView/index.js +++ b/app/views/DirectoryView/index.js @@ -254,7 +254,7 @@ class DirectoryView extends React.Component { } const mapStateToProps = state => ({ - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, user: getUserSelector(state), isFederationEnabled: state.settings.FEDERATION_Enabled }); diff --git a/app/views/MessagesView/index.js b/app/views/MessagesView/index.js index f72cda72671..49aeb8713b0 100644 --- a/app/views/MessagesView/index.js +++ b/app/views/MessagesView/index.js @@ -307,7 +307,7 @@ class MessagesView extends React.Component { } const mapStateToProps = state => ({ - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, user: getUserSelector(state), customEmojis: state.customEmojis }); diff --git a/app/views/NewMessageView.js b/app/views/NewMessageView.js index 873d35e768a..2140df18b06 100644 --- a/app/views/NewMessageView.js +++ b/app/views/NewMessageView.js @@ -228,7 +228,7 @@ class NewMessageView extends React.Component { } const mapStateToProps = state => ({ - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, user: getUserSelector(state) }); diff --git a/app/views/ProfileView/index.js b/app/views/ProfileView/index.js index f2a1bbfebd9..e1305688202 100644 --- a/app/views/ProfileView/index.js +++ b/app/views/ProfileView/index.js @@ -500,7 +500,7 @@ class ProfileView extends React.Component { const mapStateToProps = state => ({ user: getUserSelector(state), Accounts_CustomFields: state.settings.Accounts_CustomFields, - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '' + baseUrl: state.server.server }); const mapDispatchToProps = dispatch => ({ diff --git a/app/views/ReadReceiptView/index.js b/app/views/ReadReceiptView/index.js index 1ff1e3ac1c3..bd58e6906cf 100644 --- a/app/views/ReadReceiptView/index.js +++ b/app/views/ReadReceiptView/index.js @@ -167,7 +167,7 @@ class ReadReceiptView extends React.Component { const mapStateToProps = state => ({ Message_TimeFormat: state.settings.Message_TimeFormat, - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, user: getUserSelector(state) }); diff --git a/app/views/RoomActionsView/index.js b/app/views/RoomActionsView/index.js index e611c479345..7f60e6e6718 100644 --- a/app/views/RoomActionsView/index.js +++ b/app/views/RoomActionsView/index.js @@ -525,7 +525,7 @@ class RoomActionsView extends React.Component { const mapStateToProps = state => ({ user: getUserSelector(state), - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, jitsiEnabled: state.settings.Jitsi_Enabled || false }); diff --git a/app/views/RoomInfoView/index.js b/app/views/RoomInfoView/index.js index 568944a74ad..1df5566bbf8 100644 --- a/app/views/RoomInfoView/index.js +++ b/app/views/RoomInfoView/index.js @@ -310,7 +310,7 @@ class RoomInfoView extends React.Component { } const mapStateToProps = state => ({ - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, user: getUserSelector(state), Message_TimeFormat: state.settings.Message_TimeFormat }); diff --git a/app/views/RoomMembersView/index.js b/app/views/RoomMembersView/index.js index 787cae1036e..74e4bf6a845 100644 --- a/app/views/RoomMembersView/index.js +++ b/app/views/RoomMembersView/index.js @@ -288,7 +288,7 @@ class RoomMembersView extends React.Component { } const mapStateToProps = state => ({ - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, user: getUserSelector(state) }); diff --git a/app/views/RoomView/ReactionPicker.js b/app/views/RoomView/ReactionPicker.js index 1c158ab9aa9..3a10b3fcb67 100644 --- a/app/views/RoomView/ReactionPicker.js +++ b/app/views/RoomView/ReactionPicker.js @@ -83,7 +83,7 @@ class ReactionPicker extends React.Component { } const mapStateToProps = state => ({ - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '' + baseUrl: state.server.server }); export default responsive(connect(mapStateToProps)(withSplit(ReactionPicker))); diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js index 8f488026b28..30a434c3c3a 100644 --- a/app/views/RoomView/index.js +++ b/app/views/RoomView/index.js @@ -931,7 +931,7 @@ const mapStateToProps = state => ({ Message_TimeFormat: state.settings.Message_TimeFormat, useMarkdown: state.markdown.useMarkdown, customEmojis: state.customEmojis, - baseUrl: state.settings.baseUrl || state.server ? state.server.server : '', + baseUrl: state.server.server, Message_Read_Receipt_Enabled: state.settings.Message_Read_Receipt_Enabled }); diff --git a/app/views/RoomsListView/index.js b/app/views/RoomsListView/index.js index 8036fff2bfd..fb72085acb4 100644 --- a/app/views/RoomsListView/index.js +++ b/app/views/RoomsListView/index.js @@ -154,7 +154,6 @@ class RoomsListView extends React.Component { username: PropTypes.string, token: PropTypes.string }), - baseUrl: PropTypes.string, server: PropTypes.string, searchText: PropTypes.string, loadingServer: PropTypes.bool, @@ -708,7 +707,7 @@ class RoomsListView extends React.Component { username, token }, - baseUrl, + server, StoreLastMessage, theme, split @@ -735,7 +734,7 @@ class RoomsListView extends React.Component { token={token} rid={item.rid} type={item.t} - baseUrl={baseUrl} + baseUrl={server} prid={item.prid} showLastMessage={StoreLastMessage} onPress={() => this._onPressItem(item)} @@ -822,7 +821,6 @@ class RoomsListView extends React.Component { const mapStateToProps = state => ({ user: getUserSelector(state), server: state.server.server, - baseUrl: state.settings.baseUrl || state.server ? state.server.server : '', searchText: state.rooms.searchText, loadingServer: state.server.loading, showServerDropdown: state.rooms.showServerDropdown, diff --git a/app/views/SearchMessagesView/index.js b/app/views/SearchMessagesView/index.js index c666fb5f3cb..c7c102ff525 100644 --- a/app/views/SearchMessagesView/index.js +++ b/app/views/SearchMessagesView/index.js @@ -168,7 +168,7 @@ class SearchMessagesView extends React.Component { } const mapStateToProps = state => ({ - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, user: getUserSelector(state), customEmojis: state.customEmojis }); diff --git a/app/views/SelectedUsersView.js b/app/views/SelectedUsersView.js index 5ff0547e020..530b7e3d713 100644 --- a/app/views/SelectedUsersView.js +++ b/app/views/SelectedUsersView.js @@ -306,7 +306,7 @@ class SelectedUsersView extends React.Component { } const mapStateToProps = state => ({ - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, users: state.selectedUsers.users, loading: state.selectedUsers.loading, user: getUserSelector(state) diff --git a/app/views/ShareListView/index.js b/app/views/ShareListView/index.js index bb254c421e4..d16b9c8fe12 100644 --- a/app/views/ShareListView/index.js +++ b/app/views/ShareListView/index.js @@ -87,7 +87,6 @@ class ShareListView extends React.Component { static propTypes = { navigation: PropTypes.object, server: PropTypes.string, - baseUrl: PropTypes.string, token: PropTypes.string, userId: PropTypes.string, theme: PropTypes.string @@ -301,7 +300,7 @@ class ShareListView extends React.Component { renderItem = ({ item }) => { const { - userId, token, baseUrl, theme + userId, token, server, theme } = this.props; return ( ({ userId: share.user && share.user.id, token: share.user && share.user.token, - server: share.server, - baseUrl: share ? share.server : '' + server: share.server })); export default connect(mapStateToProps)(withTheme(ShareListView)); diff --git a/app/views/ShareView/index.js b/app/views/ShareView/index.js index 049adfeef48..dae9ba7f3f8 100644 --- a/app/views/ShareView/index.js +++ b/app/views/ShareView/index.js @@ -104,7 +104,7 @@ class ShareView extends React.Component { sendMediaMessage = async() => { const { rid, fileInfo, file } = this.state; - const { baseUrl: server, user } = this.props; + const { server, user } = this.props; const { name, description } = file; const fileMessage = { name, @@ -293,7 +293,7 @@ const mapStateToProps = (({ share }) => ({ username: share.user && share.user.username, token: share.user && share.user.token }, - baseUrl: share ? share.server : '' + server: share.server })); export default connect(mapStateToProps)(withTheme(ShareView)); diff --git a/app/views/SidebarView/index.js b/app/views/SidebarView/index.js index 75d0e517448..08b6931eaef 100644 --- a/app/views/SidebarView/index.js +++ b/app/views/SidebarView/index.js @@ -299,7 +299,7 @@ class Sidebar extends Component { const mapStateToProps = state => ({ Site_Name: state.settings.Site_Name, user: getUserSelector(state), - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, loadingServer: state.server.loading }); diff --git a/app/views/ThreadMessagesView/index.js b/app/views/ThreadMessagesView/index.js index 97198e1db7b..33001d9150e 100644 --- a/app/views/ThreadMessagesView/index.js +++ b/app/views/ThreadMessagesView/index.js @@ -349,7 +349,7 @@ class ThreadMessagesView extends React.Component { } const mapStateToProps = state => ({ - baseUrl: state.settings.Site_Url || state.server ? state.server.server : '', + baseUrl: state.server.server, user: getUserSelector(state), useRealName: state.settings.UI_Use_Real_Name, customEmojis: state.customEmojis From e7cea06cbd317a17623de893a60e9ea388c417aa Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Mon, 10 Feb 2020 18:30:07 -0300 Subject: [PATCH 4/4] [FIX] Lint --- app/views/ShareView/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/ShareView/index.js b/app/views/ShareView/index.js index dae9ba7f3f8..f5552331904 100644 --- a/app/views/ShareView/index.js +++ b/app/views/ShareView/index.js @@ -48,7 +48,7 @@ class ShareView extends React.Component { username: PropTypes.string.isRequired, token: PropTypes.string.isRequired }), - baseUrl: PropTypes.string.isRequired + server: PropTypes.string }; constructor(props) {