From 16fd57527a9810ce653f7038d8e721954f1a802a Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Mon, 26 Apr 2021 10:08:24 -0400 Subject: [PATCH] Minor tweaks --- app/actions/actionsTypes.js | 1 - app/i18n/locales/en.json | 3 ++- app/lib/methods/loadMessagesForRoom.js | 13 +++++++--- app/sagas/createChannel.js | 10 +++----- app/utils/goRoom.js | 33 ++++++++++---------------- app/views/SelectedUsersView.js | 6 ++++- 6 files changed, 32 insertions(+), 34 deletions(-) diff --git a/app/actions/actionsTypes.js b/app/actions/actionsTypes.js index 146350087..1fd8679bc 100644 --- a/app/actions/actionsTypes.js +++ b/app/actions/actionsTypes.js @@ -38,7 +38,6 @@ export const INQUIRY = createRequestTypes('INQUIRY', [...defaultTypes, 'SET_ENAB export const APP = createRequestTypes('APP', ['START', 'READY', 'INIT', 'INIT_LOCAL_SETTINGS', 'SET_MASTER_DETAIL']); export const MESSAGES = createRequestTypes('MESSAGES', ['REPLY_BROADCAST']); export const CREATE_CHANNEL = createRequestTypes('CREATE_CHANNEL', [...defaultTypes]); -export const CREATE_TEAM = createRequestTypes('CREATE_TEAM', [...defaultTypes]); export const CREATE_DISCUSSION = createRequestTypes('CREATE_DISCUSSION', [...defaultTypes]); export const SELECTED_USERS = createRequestTypes('SELECTED_USERS', ['ADD_USER', 'REMOVE_USER', 'RESET', 'SET_LOADING']); export const SERVER = createRequestTypes('SERVER', [ diff --git a/app/i18n/locales/en.json b/app/i18n/locales/en.json index f621d00a3..58438f319 100644 --- a/app/i18n/locales/en.json +++ b/app/i18n/locales/en.json @@ -715,5 +715,6 @@ "Private_Team": "Private Team", "Read_Only_Team": "Read Only Team", "Broadcast_Team": "Broadcast Team", - "creating_team" : "creating team" + "creating_team" : "creating team", + "team-name-already-exists": "A team with that name already exists" } diff --git a/app/lib/methods/loadMessagesForRoom.js b/app/lib/methods/loadMessagesForRoom.js index 012e1ea32..9ab5cf215 100644 --- a/app/lib/methods/loadMessagesForRoom.js +++ b/app/lib/methods/loadMessagesForRoom.js @@ -1,13 +1,20 @@ import log from '../../utils/log'; import updateMessages from './updateMessages'; -async function load({ rid: roomId, latest, t }) { - let params = { roomId, count: 50 }; +async function load({ + rid: roomId, latest, t, team +}) { + let params = { roomId: roomId || team.roomId, count: 50 }; + let apiType; if (latest) { params = { ...params, latest: new Date(latest).toISOString() }; } - const apiType = this.roomTypeToApiType(t); + if (team.type) { + apiType = this.roomTypeToApiType('p'); + } else { + apiType = this.roomTypeToApiType(t); + } if (!apiType) { return []; } diff --git a/app/sagas/createChannel.js b/app/sagas/createChannel.js index eb665a094..f8e96aeb1 100644 --- a/app/sagas/createChannel.js +++ b/app/sagas/createChannel.js @@ -74,7 +74,7 @@ const handleRequest = function* handleRequest({ data }) { const subCollection = db.get('subscriptions'); yield db.action(async() => { await subCollection.create((s) => { - s._raw = sanitizedRaw({ id: sub.rid }, subCollection.schema); + s._raw = sanitizedRaw({ id: sub.team ? sub.team.roomId : sub.rid }, subCollection.schema); Object.assign(s, sub); }); }); @@ -94,16 +94,12 @@ const handleSuccess = function* handleSuccess({ data }) { if (isMasterDetail) { Navigation.navigate('DrawerNavigator'); } - if (data.team) { - goRoom({ item: data.team, isMasterDetail }); - } else { - goRoom({ item: data, isMasterDetail }); - } + goRoom({ item: data.team ? data.team : data, isMasterDetail }); }; const handleFailure = function handleFailure({ err }) { setTimeout(() => { - const msg = err.reason || I18n.t('There_was_an_error_while_action', { action: I18n.t('creating_channel') }); + const msg = err.data ? I18n.t(err.data.error) : err.reason || I18n.t('There_was_an_error_while_action', { action: I18n.t('creating_channel') }); showErrorAlert(msg); }, 300); }; diff --git a/app/utils/goRoom.js b/app/utils/goRoom.js index 40fba6e97..45736e337 100644 --- a/app/utils/goRoom.js +++ b/app/utils/goRoom.js @@ -7,27 +7,18 @@ const navigate = ({ item, isMasterDetail, ...props }) => { if (isMasterDetail) { navigationMethod = Navigation.replace; } - console.log({ item }); - if (item.roomId) { - navigationMethod('RoomView', { - rid: item.roomId || item.rid, - name: RocketChat.getRoomTitle(item), - roomUserId: RocketChat.getUidDirectMessage(item), - ...props - }); - } else { - navigationMethod('RoomView', { - rid: item.rid, - name: RocketChat.getRoomTitle(item), - t: item.t, - prid: item.prid, - room: item, - search: item.search, - visitor: item.visitor, - roomUserId: RocketChat.getUidDirectMessage(item), - ...props - }); - } + + navigationMethod('RoomView', { + rid: item.roomId || item.rid, + name: RocketChat.getRoomTitle(item), + t: item.type ? 'p' : item.t, + prid: item.prid, + room: item, + search: item.search, + visitor: item.visitor, + roomUserId: RocketChat.getUidDirectMessage(item), + ...props + }); }; export const goRoom = async({ item = {}, isMasterDetail = false, ...props }) => { diff --git a/app/views/SelectedUsersView.js b/app/views/SelectedUsersView.js index f9d14e169..eb3292bb3 100644 --- a/app/views/SelectedUsersView.js +++ b/app/views/SelectedUsersView.js @@ -50,7 +50,7 @@ class SelectedUsersView extends React.Component { constructor(props) { super(props); this.init(); - + this.flatlist = React.createRef(); const maxUsers = props.route.params?.maxUsers; this.state = { maxUsers, @@ -190,9 +190,13 @@ class SelectedUsersView extends React.Component { if (users.length === 0) { return null; } + const ITEM_WIDTH = 250; return ( this.flatlist = ref} + onContentSizeChange={() => this.flatlist.scrollToEnd()} + getItemLayout={(_, index) => ({ length: ITEM_WIDTH, offset: ITEM_WIDTH * index, index })} keyExtractor={item => item._id} style={[sharedStyles.separatorTop, { borderColor: themes[theme].separatorColor }]} contentContainerStyle={{ marginVertical: 5 }}