diff --git a/client/react-native/common/components/Navigator/BottomNavigator.js b/client/react-native/common/components/Navigator/BottomNavigator.js index 19e0518368..77067547f6 100644 --- a/client/react-native/common/components/Navigator/BottomNavigator.js +++ b/client/react-native/common/components/Navigator/BottomNavigator.js @@ -1,5 +1,6 @@ import ContactNavigator, { - SplitSideContactNavigator, SubviewsContactNavigator, + SplitSideContactNavigator, + SubviewsContactNavigator, } from './ContactNavigator' import ChatNavigator, { SubviewsChatNavigator, @@ -23,47 +24,54 @@ class TabBarIconBase extends Component { super(props) const { - context: { - queries, - subscriptions, - }, + context: { queries, subscriptions }, } = props this.state = { stored: [], queryList: queries.EventList.graphql, - queryVariables: props.routeName === 'contacts' || props.routeName === 'side/contacts' - ? merge([queries.EventList.defaultVariables, { - filter: { - kind: 201, - direction: 1, - }, - onlyWithoutSeenAt: 1, - }]) - : merge([queries.EventList.defaultVariables, { - filter: { - kind: 302, - direction: 1, - }, - onlyWithoutSeenAt: 1, - }]), - subscription: props.routeName === 'contacts' || props.routeName === 'side/contacts' - ? [subscriptions.contactRequest] - : [subscriptions.message], + queryVariables: + props.routeName === 'contacts' || props.routeName === 'side/contacts' + ? merge([ + queries.EventList.defaultVariables, + { + filter: { + kind: 201, + direction: 1, + }, + onlyWithoutSeenAt: 1, + }, + ]) + : merge([ + queries.EventList.defaultVariables, + { + filter: { + kind: 302, + direction: 1, + }, + onlyWithoutSeenAt: 1, + }, + ]), + subscription: + props.routeName === 'contacts' || props.routeName === 'side/contacts' + ? [subscriptions.contactRequest] + : [subscriptions.message], } this.subscriber = null } componentDidMount () { - const { context: { queries, subscriptions } } = this.props + const { + context: { queries, subscriptions }, + } = this.props const { queryVariables } = this.state - queries.EventUnseen.fetch(queryVariables).then((e) => { + queries.EventUnseen.fetch(queryVariables).then(e => { this.setState({ stored: e.reduce((acc, val) => { - if (acc.indexOf(val.conversationId) === -1) { - acc.push(val.conversationId) + if (acc.indexOf(val.targetAddr) === -1) { + acc.push(val.targetAddr) } return acc }, []), @@ -85,22 +93,20 @@ class TabBarIconBase extends Component { const { stored, queryVariables: { - filter: { - kind, - }, + filter: { kind }, }, } = this.state if (entity && entity.kind === kind && entity.direction === 1) { - if (entity.seenAt === null && stored.indexOf(entity.conversationId) === -1) { + if (entity.seenAt === null && stored.indexOf(entity.targetAddr) === -1) { this.setState({ - stored: [ - ...stored, - entity.conversationId, - ], + stored: [...stored, entity.targetAddr], }) - } else if (entity.seenAt !== null && stored.indexOf(entity.conversationId) !== -1) { - stored.splice(stored.indexOf(entity.conversationId), 1) + } else if ( + entity.seenAt !== null && + stored.indexOf(entity.targetAddr) !== -1 + ) { + stored.splice(stored.indexOf(entity.targetAddr), 1) this.setState({ stored: stored, }) @@ -110,11 +116,13 @@ class TabBarIconBase extends Component { contactSeen = async () => { if (this.state.stored.length > 0) { - await Promise.all(this.state.stored.map((val) => { - return this.props.context.mutations.eventSeen({ - id: val, + await Promise.all( + this.state.stored.map(val => { + return this.props.context.mutations.eventSeen({ + id: val, + }) }) - })) + ) this.setState({ stored: [], @@ -123,15 +131,8 @@ class TabBarIconBase extends Component { } render () { - const { - tintColor, - routeName, - navigation, - context, - } = this.props - const { - stored, - } = this.state + const { tintColor, routeName, navigation, context } = this.props + const { stored } = this.state context.relay = context.environment let iconName = { @@ -143,33 +144,35 @@ class TabBarIconBase extends Component { 'side/settings': 'settings', }[routeName] - if ((routeName === 'contacts' || routeName === 'side/contacts') && navigation.isFocused() === true) { + if ( + (routeName === 'contacts' || routeName === 'side/contacts') && + navigation.isFocused() === true + ) { this.contactSeen() } - return routeName === 'settings' || routeName === 'side/settings' - ? ( - - {({ availableUpdate }) => ( - - )} - - ) : ( - <> + return routeName === 'settings' || routeName === 'side/settings' ? ( + + {({ availableUpdate }) => ( 0 ? '!' : ''} - value={stored.length} + badge={availableUpdate ? '!' : ''} /> - - ) + )} + + ) : ( + <> + 0 ? '!' : ''} + value={stored.length} + /> + + ) } } @@ -178,7 +181,14 @@ const TabBarIcon = withRelayContext(TabBarIconBase) const handleBothNavigationsOptions = ({ navigation }) => { return { tabBarIcon: function withTabBarIcon ({ tintColor, focused }) { - return () + return ( + + ) }, } } @@ -208,7 +218,7 @@ const options = { shadowRadius: Platform.OS === 'web' ? 5 : 3, ...(Platform.OS === 'android' ? { height: 54, paddingTop: 3 } - : { height: 50.500, paddingTop: 5, paddingBottom: 6 }), + : { height: 50.5, paddingTop: 5, paddingBottom: 6 }), }, ], }, @@ -235,34 +245,39 @@ export default createBottomTabNavigator( }), }, }, - options, + options ) -export const SplitNavigator = createSplitNavigator({ - 'placeholder': Placeholder, - 'contacts': SubviewsContactNavigator, - 'chats/subviews': SubviewsChatNavigator, -}, { - 'side/contacts': { - screen: SplitSideContactNavigator, - navigationOptions: () => ({ - title: I18n.t('contacts.title'), - }), - }, - 'side/chats': { - screen: SplitSideChatNavigator, - navigationOptions: () => ({ - title: I18n.t('chats.title'), - }), +export const SplitNavigator = createSplitNavigator( + { + placeholder: Placeholder, + contacts: SubviewsContactNavigator, + 'chats/subviews': SubviewsChatNavigator, }, - 'side/settings': { - screen: SettingsNavigator, - navigationOptions: () => ({ - title: I18n.t('settings.title'), - }), + { + 'side/contacts': { + screen: SplitSideContactNavigator, + navigationOptions: () => ({ + title: I18n.t('contacts.title'), + }), + }, + 'side/chats': { + screen: SplitSideChatNavigator, + navigationOptions: () => ({ + title: I18n.t('chats.title'), + }), + }, + 'side/settings': { + screen: SettingsNavigator, + navigationOptions: () => ({ + title: I18n.t('settings.title'), + }), + }, }, -}, {}, { - ...options, - backBehavior: 'none', - initialRouteName: 'side/chats', -}) + {}, + { + ...options, + backBehavior: 'none', + initialRouteName: 'side/chats', + } +) diff --git a/client/react-native/common/components/Screens/Chats/Detail.js b/client/react-native/common/components/Screens/Chats/Detail.js index 4b7ae0cdee..47cb1ef603 100644 --- a/client/react-native/common/components/Screens/Chats/Detail.js +++ b/client/react-native/common/components/Screens/Chats/Detail.js @@ -1,6 +1,7 @@ import { ActivityIndicator, - Platform, StyleSheet, + Platform, + StyleSheet, TextInput as RNTextInput, View, } from 'react-native' @@ -8,7 +9,15 @@ import { btoa } from 'b64-lite' import { withNamespaces } from 'react-i18next' import React, { PureComponent } from 'react' -import { Flex, Header, Icon, Screen, Text, Avatar, Markdown } from '../../Library' +import { + Flex, + Header, + Icon, + Screen, + Text, + Avatar, + Markdown, +} from '../../Library' import { Pagination, QueryReducer, RelayContext } from '../../../relay' import { colors } from '../../../constants' import { fragments } from '../../../graphql' @@ -20,27 +29,32 @@ import * as dateFns from '../../../i18n/dateFns' import withRelayContext from '../../../helpers/withRelayContext' import * as KeyboardContext from '../../../helpers/KeyboardContext' -const textStyles = StyleSheet.flatten([Markdown.styles, { - text: { - color: colors.white, - ...(Platform.OS === 'web' ? { - wordBreak: 'break-all', - overflowWrap: 'break-word', - } : {}), - }, - listUnorderedItemIcon: { - color: colors.white, - }, - listOrderedItemIcon: { - color: colors.white, - }, - blocklink: { - borderColor: colors.white, - }, - u: { - borderColor: colors.white, +const textStyles = StyleSheet.flatten([ + Markdown.styles, + { + text: { + color: colors.white, + ...(Platform.OS === 'web' + ? { + wordBreak: 'break-all', + overflowWrap: 'break-word', + } + : {}), + }, + listUnorderedItemIcon: { + color: colors.white, + }, + listOrderedItemIcon: { + color: colors.white, + }, + blocklink: { + borderColor: colors.white, + }, + u: { + borderColor: colors.white, + }, }, -}]) +]) class Message extends React.Component { static contextType = RelayContext @@ -52,7 +66,9 @@ class Message extends React.Component { } shouldComponentUpdate (nextProps, nextState) { - const { data: { seenAt } } = this.props + const { + data: { seenAt }, + } = this.props if (seenAt !== nextProps.data.seenAt) { return false } @@ -113,7 +129,9 @@ class Message extends React.Component { borderBottomRightRadius: isMyself ? 3 : 14.5, }} > - {parseEmbedded(data.attributes).message.text} + + {parseEmbedded(data.attributes).message.text} + {({ keyboardVisible }) => - { - if (!keyboardVisible && !e.shiftKey && e.nativeEvent.key === 'Enter') { - this.props.onSubmit() - } - }} - onContentSizeChange={this.onContentSizeChange} - autoFocus - placeholder={t('chats.write-message')} - placeholderTextColor={colors.lightGrey} - onChangeText={this.props.onChangeText} - value={value} - multiline - /> - } + + {({ keyboardVisible }) => ( + { + if ( + !keyboardVisible && + !e.shiftKey && + e.nativeEvent.key === 'Enter' + ) { + this.props.onSubmit() + } + }} + onContentSizeChange={this.onContentSizeChange} + autoFocus + placeholder={t('chats.write-message')} + placeholderTextColor={colors.lightGrey} + onChangeText={this.props.onChangeText} + value={value} + multiline + /> + )} + ) } } @@ -208,16 +232,14 @@ class Input extends PureComponent { try { const conversation = this.props.navigation.state.params || {} input && - (await this.props.context.mutations.conversationAddMessage( - { - conversation: { - id: conversation.id, - }, - message: { - text: input, - }, - } - )) + (await this.props.context.mutations.conversationAddMessage({ + conversation: { + id: conversation.id, + }, + message: { + text: input, + }, + })) } catch (err) { console.error(err) } @@ -240,7 +262,17 @@ class Input extends PureComponent { align='center' style={ Platform.OS === 'web' - ? [{ borderTopWidth: 0.5, borderTopColor: colors.borderGrey, position: 'absolute', bottom: 0, left: 0, right: 0 }, shadow] + ? [ + { + borderTopWidth: 0.5, + borderTopColor: colors.borderGrey, + position: 'absolute', + bottom: 0, + left: 0, + right: 0, + }, + shadow, + ] : [shadow] } > @@ -305,7 +337,7 @@ const Chat = fragments.Conversation( { filter: { kind: 302, - conversationId: data.id, + targetAddr: data.id, }, }, ])} @@ -336,7 +368,7 @@ class Detail extends PureComponent { header: (
{utils.getTitle(navigation.state.params) || {}} - {navigation.state.params.topic - ? ( - - {navigation.state.params.topic} - - ) : null - } + {navigation.state.params.topic ? ( + + {navigation.state.params.topic} + + ) : null} - )} + } rightBtnIcon='more-vertical' onPressRightBtn={() => navigation.navigate('chats/settings', { @@ -381,11 +411,9 @@ class Detail extends PureComponent { } onConversationRead = async () => { - const res = await this.props.context.mutations.conversationRead( - { - id: this.props.navigation.getParam('id'), - } - ) + const res = await this.props.context.mutations.conversationRead({ + id: this.props.navigation.getParam('id'), + }) this.props.navigation.setParams(res.ConversationRead) } diff --git a/client/react-native/common/components/Screens/Chats/List.js b/client/react-native/common/components/Screens/Chats/List.js index 5c6c475eeb..99fce6b7f1 100644 --- a/client/react-native/common/components/Screens/Chats/List.js +++ b/client/react-native/common/components/Screens/Chats/List.js @@ -65,7 +65,7 @@ const ItemBase = fragments.Conversation( { filter: { kind: 302, - conversationId: this.props.data.id, + targetAddr: this.props.data.id, direction: 1, }, onlyWithoutSeenAt: 1, diff --git a/client/react-native/common/graphql/subscriptions/ConversationNewMessage.js b/client/react-native/common/graphql/subscriptions/ConversationNewMessage.js index 1dd43aa33f..c33e35719b 100644 --- a/client/react-native/common/graphql/subscriptions/ConversationNewMessage.js +++ b/client/react-native/common/graphql/subscriptions/ConversationNewMessage.js @@ -9,7 +9,7 @@ export default context => ({ (async (store, data) => { if (data.EventStream.kind === 302) { await context.queries.Conversation.fetch({ - id: data.EventStream.conversationId, + id: data.EventStream.targetAddr, }) } }), diff --git a/client/react-native/common/graphql/subscriptions/ConversationRead.js b/client/react-native/common/graphql/subscriptions/ConversationRead.js index 50e41f4d40..947ba22a9f 100644 --- a/client/react-native/common/graphql/subscriptions/ConversationRead.js +++ b/client/react-native/common/graphql/subscriptions/ConversationRead.js @@ -9,11 +9,11 @@ export default context => ({ (async (store, data) => { if (data.EventStream.kind === 303) { await context.queries.Conversation.fetch({ - id: data.EventStream.conversationId, + id: data.EventStream.targetAddr, }) await context.queries.EventList.fetch({ filter: { - conversationId: data.EventStream.conversationId, + conversationId: data.EventStream.targetAddr, kind: 302, }, }) diff --git a/client/react-native/common/graphql/subscriptions/EventSeen.js b/client/react-native/common/graphql/subscriptions/EventSeen.js index 9c6a4eb9c4..ef164c5c72 100644 --- a/client/react-native/common/graphql/subscriptions/EventSeen.js +++ b/client/react-native/common/graphql/subscriptions/EventSeen.js @@ -24,13 +24,13 @@ export default context => ({ // update all conversations events.reduce((conversations, event) => { - if (conversations[event.conversationId]) { + if (conversations[event.targetAddr]) { return conversations } const promise = context.queries.Conversation.fetch({ - id: data.EventStream.conversationId, + id: data.EventStream.targetAddr, }) - conversations[event.conversationId] = promise + conversations[event.targetAddr] = promise return conversations }, {}) } diff --git a/client/react-native/common/utils/event.js b/client/react-native/common/utils/event.js index 839b5615c3..534143d25c 100644 --- a/client/react-native/common/utils/event.js +++ b/client/react-native/common/utils/event.js @@ -3,6 +3,5 @@ export default { sourceDeviceId: '', sourceContactId: '', apiVersion: 0, - destinationDeviceId: '', - conversationId: '', + targetAddr: '', }