Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add discussions support #696

Merged
merged 34 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c96cea1
Add threads support
sampaiodiego Mar 11, 2019
595e642
Add prid field to schema
sampaiodiego Mar 11, 2019
6c38e6d
Add prid migration
diegolmello Mar 11, 2019
7035a64
Icon
diegolmello Mar 11, 2019
59f29e1
Started a thread message
diegolmello Mar 11, 2019
58ed56e
Merge branch 'develop' into add-threads-support
diegolmello Mar 19, 2019
9f50cf4
Merge branch 'develop' into add-threads-support
diegolmello Mar 27, 2019
f331c55
color fix
diegolmello Mar 27, 2019
48d27c2
Merge branch 'develop' into add-threads-support
diegolmello Apr 1, 2019
50d4589
Refactor open room logic
diegolmello Apr 1, 2019
248fa42
changes on header
diegolmello Apr 1, 2019
89419f4
Remove room from redux
diegolmello Apr 2, 2019
d6febe5
Fix emit typing
diegolmello Apr 2, 2019
d12e85e
Fix stream room messages
diegolmello Apr 2, 2019
edfec6d
Remove room from redux
diegolmello Apr 2, 2019
5b5694d
Discussion navigation
diegolmello Apr 2, 2019
2a00001
Icons changed
diegolmello Apr 2, 2019
8a753bb
Removed actions
diegolmello Apr 3, 2019
7d06d75
Fix draft message per room
diegolmello Apr 3, 2019
40e5f29
Add RoomViewHeader stories
diegolmello Apr 3, 2019
b3f32c1
Discussions group when grouping for room type
diegolmello Apr 3, 2019
fe52337
fix lint
diegolmello Apr 3, 2019
03f6ce8
Update tests
diegolmello Apr 3, 2019
d8b6001
Fix separator date
diegolmello Apr 3, 2019
2c93cf4
Room type icon style and disclaimer
diegolmello Apr 3, 2019
644895c
Use react-native-platform-touchable on messages
diegolmello Apr 4, 2019
4f9a066
Fix e2e
diegolmello Apr 4, 2019
8325cfb
Add discussion message type
diegolmello Apr 4, 2019
5bf38d9
Merge branch 'develop' into add-threads-support
diegolmello Apr 4, 2019
750a843
Merge branch 'develop' into add-threads-support
diegolmello Apr 4, 2019
7ed9253
I18n
diegolmello Apr 4, 2019
adc1896
Increased <Typing /> space
diegolmello Apr 4, 2019
73f5d90
- Remove scroll bottom
diegolmello Apr 5, 2019
2e26ed7
Perform discussions migrations
diegolmello Apr 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,111 changes: 5,314 additions & 1,797 deletions __tests__/__snapshots__/Storyshots.test.js.snap

Large diffs are not rendered by default.

Binary file modified android/app/src/main/assets/fonts/custom.ttf
Binary file not shown.
12 changes: 1 addition & 11 deletions app/actions/actionsTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,7 @@ export const ROOMS = createRequestTypes('ROOMS', [
'OPEN_SEARCH_HEADER',
'CLOSE_SEARCH_HEADER'
]);
export const ROOM = createRequestTypes('ROOM', [
'ADD_USER_TYPING',
'REMOVE_USER_TYPING',
'SOMEONE_TYPING',
'OPEN',
'CLOSE',
'LEAVE',
'ERASE',
'USER_TYPING',
'MESSAGE_RECEIVED'
]);
export const ROOM = createRequestTypes('ROOM', ['LEAVE', 'ERASE', 'USER_TYPING']);
export const APP = createRequestTypes('APP', ['START', 'READY', 'INIT']);
export const MESSAGES = createRequestTypes('MESSAGES', [
...defaultTypes,
Expand Down
45 changes: 2 additions & 43 deletions app/actions/room.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,5 @@
import * as types from './actionsTypes';


export function removeUserTyping(username) {
return {
type: types.ROOM.REMOVE_USER_TYPING,
username
};
}

export function someoneTyping(data) {
return {
type: types.ROOM.SOMEONE_TYPING,
...data
};
}

export function addUserTyping(username) {
return {
type: types.ROOM.ADD_USER_TYPING,
username
};
}

export function openRoom(room) {
return {
type: types.ROOM.OPEN,
room
};
}

export function closeRoom() {
return {
type: types.ROOM.CLOSE
};
}

export function leaveRoom(rid, t) {
return {
type: types.ROOM.LEAVE,
Expand All @@ -51,16 +16,10 @@ export function eraseRoom(rid, t) {
};
}

export function userTyping(status = true) {
export function userTyping(rid, status = true) {
return {
type: types.ROOM.USER_TYPING,
rid,
status
};
}

export function roomMessageReceived(message) {
return {
type: types.ROOM.MESSAGE_RECEIVED,
message
};
}
4 changes: 2 additions & 2 deletions app/containers/ConnectionBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import I18n from '../i18n';
import debounce from '../utils/debounce';
import sharedStyles from '../views/Styles';
import {
COLOR_BACKGROUND_CONTAINER, COLOR_DANGER, COLOR_SUCCESS, COLOR_WHITE
COLOR_BACKGROUND_CONTAINER, COLOR_DANGER, COLOR_SUCCESS, COLOR_WHITE, COLOR_TEXT_DESCRIPTION
} from '../constants/colors';

const styles = StyleSheet.create({
Expand Down Expand Up @@ -117,7 +117,7 @@ class ConnectionBadge extends Component {
if (connecting) {
return (
<Animated.View style={[styles.container, { transform: [{ translateY }] }]}>
<ActivityIndicator color='#9EA2A8' style={styles.activityIndicator} />
<ActivityIndicator color={COLOR_TEXT_DESCRIPTION} style={styles.activityIndicator} />
<Text style={[styles.text, styles.textConnecting]}>{I18n.t('Connecting')}</Text>
</Animated.View>
);
Expand Down
60 changes: 30 additions & 30 deletions app/containers/MessageBox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,7 @@ const imagePickerConfig = {
cropperCancelText: I18n.t('Cancel')
};

@connect(state => ({
roomType: state.room.t,
message: state.messages.message,
replyMessage: state.messages.replyMessage,
replying: state.messages.replyMessage && !!state.messages.replyMessage.msg,
editing: state.messages.editing,
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
}
}), dispatch => ({
editCancel: () => dispatch(editCancelAction()),
editRequest: message => dispatch(editRequestAction(message)),
typing: status => dispatch(userTypingAction(status)),
closeReply: () => dispatch(replyCancelAction())
}))
export default class MessageBox extends Component {
class MessageBox extends Component {
static propTypes = {
rid: PropTypes.string.isRequired,
baseUrl: PropTypes.string.isRequired,
Expand Down Expand Up @@ -113,13 +95,17 @@ export default class MessageBox extends Component {
const [room] = database.objects('subscriptions').filtered('rid = $0', rid);
if (room.draftMessage && room.draftMessage !== '') {
this.setInput(room.draftMessage);
this.setShowSend(true);
}
}

componentWillReceiveProps(nextProps) {
const { message, replyMessage } = this.props;
if (message !== nextProps.message && nextProps.message.msg) {
this.setInput(nextProps.message.msg);
if (this.text) {
this.setShowSend(true);
}
this.focus();
} else if (replyMessage !== nextProps.replyMessage && nextProps.replyMessage.msg) {
this.focus();
Expand Down Expand Up @@ -165,14 +151,6 @@ export default class MessageBox extends Component {
return false;
}

componentWillUnmount() {
const { rid } = this.props;
const [room] = database.objects('subscriptions').filtered('rid = $0', rid);
database.write(() => {
room.draftMessage = this.text;
});
}

onChangeText = (text) => {
const isTextEmpty = text.length === 0;
this.setShowSend(!isTextEmpty);
Expand Down Expand Up @@ -461,13 +439,13 @@ export default class MessageBox extends Component {
}

handleTyping = (isTyping) => {
const { typing } = this.props;
const { typing, rid } = this.props;
if (!isTyping) {
if (this.typingTimeout) {
clearTimeout(this.typingTimeout);
this.typingTimeout = false;
}
typing(false);
typing(rid, false);
return;
}

Expand All @@ -476,7 +454,7 @@ export default class MessageBox extends Component {
}

this.typingTimeout = setTimeout(() => {
typing(true);
typing(rid, true);
this.typingTimeout = false;
}, 1000);
}
Expand Down Expand Up @@ -835,3 +813,25 @@ export default class MessageBox extends Component {
);
}
}

const mapStateToProps = state => ({
message: state.messages.message,
replyMessage: state.messages.replyMessage,
replying: state.messages.replyMessage && !!state.messages.replyMessage.msg,
editing: state.messages.editing,
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
}
});

const dispatchToProps = ({
editCancel: () => editCancelAction(),
editRequest: message => editRequestAction(message),
typing: (rid, status) => userTypingAction(rid, status),
closeReply: () => replyCancelAction()
});

export default connect(mapStateToProps, dispatchToProps, null, { forwardRef: true })(MessageBox);
13 changes: 12 additions & 1 deletion app/containers/RoomTypeIcon.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import React from 'react';
import { Image, StyleSheet } from 'react-native';
import PropTypes from 'prop-types';
import { CustomIcon } from '../lib/Icons';
import { COLOR_TEXT_DESCRIPTION } from '../constants/colors';

const styles = StyleSheet.create({
style: {
marginRight: 7,
marginTop: 3,
tintColor: '#9EA2A8'
tintColor: COLOR_TEXT_DESCRIPTION,
color: COLOR_TEXT_DESCRIPTION
},
discussion: {
marginRight: 6
}
});

Expand All @@ -15,6 +21,11 @@ const RoomTypeIcon = React.memo(({ type, size, style }) => {
return null;
}

if (type === 'discussion') {
// FIXME: These are temporary only. We should have all room icons on <Customicon />, but our design team is still working on this.
return <CustomIcon name='chat' size={13} style={[styles.style, styles.discussion]} />;
}

if (type === 'c') {
return <Image source={{ uri: 'hashtag' }} style={[styles.style, style, { width: size, height: size }]} />;
}
Expand Down
28 changes: 14 additions & 14 deletions app/containers/message/Image.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import FastImage from 'react-native-fast-image';
import { RectButton } from 'react-native-gesture-handler';
import equal from 'deep-equal';
import Touchable from 'react-native-platform-touchable';

import PhotoModal from './PhotoModal';
import Markdown from './Markdown';
import styles from './styles';
import { COLOR_WHITE } from '../../constants/colors';

export default class extends Component {
static propTypes = {
Expand Down Expand Up @@ -37,7 +36,7 @@ export default class extends Component {
return false;
}

onPressButton() {
onPressButton = () => {
this.setState({
modalVisible: true
});
Expand Down Expand Up @@ -67,20 +66,21 @@ export default class extends Component {

return (
[
<RectButton
<Touchable
key='image'
onPress={() => this.onPressButton()}
onActiveStateChange={this.isPressed}
onPress={this.onPressButton}
style={styles.imageContainer}
underlayColor={COLOR_WHITE}
background={Touchable.Ripple('#fff')}
>
<FastImage
style={[styles.image, isPressed && { opacity: 0.5 }]}
source={{ uri: encodeURI(img) }}
resizeMode={FastImage.resizeMode.cover}
/>
{this.getDescription()}
</RectButton>,
<React.Fragment>
<FastImage
style={[styles.image, isPressed && { opacity: 0.5 }]}
source={{ uri: encodeURI(img) }}
resizeMode={FastImage.resizeMode.cover}
/>
{this.getDescription()}
</React.Fragment>
</Touchable>,
<PhotoModal
key='modal'
title={file.title}
Expand Down
39 changes: 5 additions & 34 deletions app/containers/message/Markdown.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Text, Image, Platform } from 'react-native';
import { Text, Image } from 'react-native';
import PropTypes from 'prop-types';
import { emojify } from 'react-emojione';
import MarkdownRenderer, { PluginContainer } from 'react-native-markdown-renderer';
Expand All @@ -8,20 +8,12 @@ import styles from './styles';
import CustomEmoji from '../EmojiPicker/CustomEmoji';
import MarkdownEmojiPlugin from './MarkdownEmojiPlugin';

import sharedStyles from '../../views/Styles';
import { COLOR_BACKGROUND_CONTAINER, COLOR_BORDER, COLOR_PRIMARY } from '../../constants/colors';

// Support <http://link|Text>
const formatText = text => text.replace(
new RegExp('(?:<|<)((?:https|http):\\/\\/[^\\|]+)\\|(.+?)(?=>|>)(?:>|>)', 'gm'),
(match, url, title) => `[${ title }](${ url })`
);

const codeFontFamily = Platform.select({
ios: { fontFamily: 'Courier New' },
android: { fontFamily: 'monospace' }
});

export default class Markdown extends React.Component {
shouldComponentUpdate(nextProps) {
const { msg } = this.props;
Expand Down Expand Up @@ -94,31 +86,10 @@ export default class Markdown extends React.Component {
}}
style={{
paragraph: styles.paragraph,
text: {
fontSize: 16,
...sharedStyles.textColorNormal,
...sharedStyles.textRegular
},
codeInline: {
...sharedStyles.textRegular,
...codeFontFamily,
borderWidth: 1,
backgroundColor: COLOR_BACKGROUND_CONTAINER,
borderRadius: 4
},
codeBlock: {
...sharedStyles.textRegular,
...codeFontFamily,
backgroundColor: COLOR_BACKGROUND_CONTAINER,
borderColor: COLOR_BORDER,
borderWidth: 1,
borderRadius: 4,
padding: 4
},
link: {
color: COLOR_PRIMARY,
...sharedStyles.textRegular
},
text: styles.text,
codeInline: styles.codeInline,
codeBlock: styles.codeBlock,
link: styles.link,
...style
}}
plugins={[
Expand Down
Loading