Skip to content

Commit

Permalink
Better touch handling on rooms list (#462)
Browse files Browse the repository at this point in the history
* Use react-native-gesture-handler at RoomItem

* Fixed info message author

* Edit message render improvement

* Fix ws to http replace
  • Loading branch information
diegolmello committed Sep 26, 2018
1 parent c58df3b commit d6162d9
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 4,048 deletions.
1,321 changes: 6 additions & 1,315 deletions __tests__/__snapshots__/RoomItem.js.snap

Large diffs are not rendered by default.

2,716 changes: 11 additions & 2,705 deletions __tests__/__snapshots__/Storyshots.test.js.snap

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/containers/message/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const SYSTEM_MESSAGES = [
];

const getInfoMessage = ({
type, role, msg, user
type, role, msg, author
}) => {
const { username } = user;
const { username } = author;
if (type === 'rm') {
return I18n.t('Message_removed');
} else if (type === 'uj') {
Expand Down
20 changes: 11 additions & 9 deletions app/containers/message/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import {
@connect(state => ({
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '',
customEmojis: state.customEmojis,
editing: state.messages.editing,
Message_GroupingPeriod: state.settings.Message_GroupingPeriod,
Message_TimeFormat: state.settings.Message_TimeFormat,
message: state.messages.message,
editingMessage: state.messages.message,
useRealName: state.settings.UI_Use_Real_Name
}), dispatch => ({
errorActionsShow: actionMessage => dispatch(errorActionsShowAction(actionMessage)),
Expand All @@ -43,10 +42,9 @@ export default class MessageContainer extends React.Component {
// redux
baseUrl: PropTypes.string,
customEmojis: PropTypes.object,
editing: PropTypes.bool,
Message_GroupingPeriod: PropTypes.number,
Message_TimeFormat: PropTypes.string,
message: PropTypes.object,
editingMessage: PropTypes.object,
useRealName: PropTypes.bool,
// methods - props
onLongPress: PropTypes.func,
Expand All @@ -73,7 +71,7 @@ export default class MessageContainer extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
const { reactionsModal } = this.state;
const {
status, reactions, broadcast, editing, _updatedAt
status, reactions, broadcast, _updatedAt, editingMessage, item
} = this.props;

if (reactionsModal !== nextState.reactionsModal) {
Expand All @@ -92,8 +90,12 @@ export default class MessageContainer extends React.Component {
if (broadcast !== nextProps.broadcast) {
return true;
}
if (editing !== nextProps.editing) {
return true;
if (!equal(editingMessage, nextProps.editingMessage)) {
if (nextProps.editingMessage && nextProps.editingMessage._id === item._id) {
return true;
} else if (!nextProps.editingMessage._id !== item._id && editingMessage._id === item._id) {
return true;
}
}
return _updatedAt.toGMTString() !== nextProps._updatedAt.toGMTString();
}
Expand Down Expand Up @@ -163,12 +165,12 @@ export default class MessageContainer extends React.Component {
render() {
const { reactionsModal } = this.state;
const {
item, message, editing, user, style, archived, baseUrl, customEmojis, useRealName, broadcast
item, editingMessage, user, style, archived, baseUrl, customEmojis, useRealName, broadcast
} = this.props;
const {
msg, ts, attachments, urls, reactions, t, status, avatar, u, alias, editedBy, role
} = item;
const isEditing = message._id === item._id && editing;
const isEditing = editingMessage._id === item._id;
return (
<Message
msg={msg}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/canOpenRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const restTypes = {
async function canOpenRoomREST({ type, rid }) {
try {
const { token, id } = this.ddp._login;
const server = this.ddp.url.replace('ws', 'http');
const server = this.ddp.url.replace(/^ws/, 'http');
await post({ token, id, server }, `${ restTypes[type] }.open`, { roomId: rid });
return true;
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/getRooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const getRoomRest = async function() {
const { ddp } = this;
const updatedSince = lastMessage();
const { token, id } = ddp._login;
const server = this.ddp.url.replace('ws', 'http');
const server = this.ddp.url.replace(/^ws/, 'http');
const [subscriptions, rooms] = await Promise.all([get({ token, id, server }, 'subscriptions.get', { updatedSince }), get({ token, id, server }, 'rooms.get', { updatedSince })]);
return mergeSubscriptionsRooms(subscriptions, rooms);
};
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/loadMessagesForRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const types = {

async function loadMessagesForRoomRest({ rid: roomId, latest, t }) {
const { token, id } = this.ddp._login;
const server = this.ddp.url.replace('ws', 'http');
const server = this.ddp.url.replace(/^ws/, 'http');
const data = await get({ token, id, server }, `${ types[t] }.history`, { roomId, latest });
if (!data || data.status === 'error') {
return [];
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/loadMissedMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import log from '../../utils/log';

async function loadMissedMessagesRest({ rid: roomId, lastOpen: lastUpdate }) {
const { token, id } = this.ddp._login;
const server = this.ddp.url.replace('ws', 'http');
const server = this.ddp.url.replace(/^ws/, 'http');
const { result } = await get({ token, id, server }, 'chat.syncMessages', { roomId, lastUpdate });
// TODO: api fix
if (!result) {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/readMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import log from '../../utils/log';

const readMessagesREST = function readMessagesREST(rid) {
const { token, id } = this.ddp._login;
const server = this.ddp.url.replace('ws', 'http');
const server = this.ddp.url.replace(/^ws/, 'http');
return post({ token, id, server }, 'subscriptions.read', { rid });
};

Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/sendMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const getMessage = (rid, msg = {}) => {

function sendMessageByRest(message) {
const { token, id } = this.ddp._login;
const server = this.ddp.url.replace('ws', 'http');
const server = this.ddp.url.replace(/^ws/, 'http');
const { _id, rid, msg } = message;
return post({ token, id, server }, 'chat.sendMessage', { message: { _id, rid, msg } });
}
Expand Down
20 changes: 10 additions & 10 deletions app/presentation/RoomItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from 'react-native';
import { connect } from 'react-redux';
import { emojify } from 'react-emojione';
import { RectButton } from 'react-native-gesture-handler';

import Avatar from '../containers/Avatar';
import Status from '../containers/status';
Expand Down Expand Up @@ -142,7 +143,6 @@ export default class RoomItem extends React.Component {
userMentions: PropTypes.number,
id: PropTypes.string,
onPress: PropTypes.func,
onLongPress: PropTypes.func,
username: PropTypes.string,
avatarSize: PropTypes.number,
testID: PropTypes.string,
Expand Down Expand Up @@ -229,7 +229,7 @@ export default class RoomItem extends React.Component {

render() {
const {
favorite, unread, userMentions, name, _updatedAt, alert, testID, height, onPress, onLongPress
favorite, unread, userMentions, name, _updatedAt, alert, testID, height, onPress
} = this.props;

const date = this.formatDate(_updatedAt);
Expand All @@ -250,16 +250,16 @@ export default class RoomItem extends React.Component {
}

return (
<Touch
<RectButton
onPress={onPress}
onLongPress={onLongPress}
underlayColor='#FFFFFF'
activeOpacity={0.5}
accessibilityLabel={accessibilityLabel}
accessibilityTraits='selected'
activeOpacity={0.8}
underlayColor='#e1e5e8'
testID={testID}
>
<View style={[styles.container, favorite && styles.favorite, height && { height }]}>
<View
style={[styles.container, favorite && styles.favorite, height && { height }]}
accessibilityLabel={accessibilityLabel}
>
{this.avatar}
<View style={styles.centerContainer}>
<View style={styles.titleContainer}>
Expand All @@ -276,7 +276,7 @@ export default class RoomItem extends React.Component {
</View>
{this.renderDisclosureIndicator()}
</View>
</Touch>
</RectButton>
);
}
}
3 changes: 2 additions & 1 deletion app/views/RoomActionsView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Icon from 'react-native-vector-icons/Ionicons';
import MaterialIcon from 'react-native-vector-icons/MaterialIcons';
import { connect, Provider } from 'react-redux';
import { Navigation } from 'react-native-navigation';
import { gestureHandlerRootHOC } from 'react-native-gesture-handler';

import { leaveRoom as leaveRoomAction } from '../../actions/room';
import LoggedView from '../View';
Expand Down Expand Up @@ -74,7 +75,7 @@ export default class RoomActionsView extends LoggedView {
if (item.route) {
if (modules[item.route] == null) {
modules[item.route] = item.require();
Navigation.registerComponent(item.route, () => modules[item.route], store, Provider);
Navigation.registerComponent(item.route, () => gestureHandlerRootHOC(modules[item.route]), store, Provider);
}
navigator.push({
screen: item.route,
Expand Down

0 comments on commit d6162d9

Please sign in to comment.