Skip to content

Commit

Permalink
chore(entity): use interactor for conversation
Browse files Browse the repository at this point in the history
Signed-off-by: Godefroy Ponsinet <godefroy.ponsinet@outlook.com>
  • Loading branch information
90dy committed Apr 8, 2019
1 parent 33a36ae commit 94aa178
Show file tree
Hide file tree
Showing 28 changed files with 842 additions and 656 deletions.
Expand Up @@ -19,7 +19,7 @@ public class NotificationNative implements NativeNotificationDriver {
public static int PERMISSION_CODE = 200;
private Logger logger = new Logger("chat.berty.io");

private static final String CHANNEL_ID = "berty-chat-android-notification-id";
private static final String CHANNEL_ID = "berty-chat-wandroid-notification-id";
private static final String CHANNEL_NAME = "berty.chat.android.core.notification.name";
private static final String CHANNEL_DESCRIPTION = "berty.chat.android.core.notification.description";

Expand Down
@@ -0,0 +1,47 @@
import React from 'react'
import { colors } from '../../../constants'
import ActionList from './ActionList'
import RelayContext from '../../../relay/RelayContext'
import { withNamespaces } from 'react-i18next'

const ActionsUnknown = ({ data, inModal, t }) => (
<RelayContext.Consumer>
{({ mutations }) => (
<ActionList inModal={inModal}>
<ActionList.Action
icon={'send'}
color={colors.green}
title={t('contacts.request-action')}
dismissOnSuccess
action={() => {
const contact = Object.keys(data)
.filter(key => key.substring(0, 2) !== '__')
.reduce(
(acc, key) => ({
...acc,
[key]: data[key],
}),
{}
)
return mutations.contactRequest({
contactId: contact.id,
contactOverrideDisplayName:
contact.overrideDisplayName || contact.displayName || '',
introText: '',
})
}}
successMessage={t('contacts.request-action-feedback')}
/>
<ActionList.Action
icon={'x'}
color={colors.white}
title={inModal ? t('contacts.cancel-request-action') : null}
action={() => mutations.contactRemove({ id: data.id })}
successMessage={t('contacts.cancel-request-action-feedback')}
/>
</ActionList>
)}
</RelayContext.Consumer>
)

export default withNamespaces()(ActionsUnknown)
13 changes: 5 additions & 8 deletions client/react-native/common/components/Screens/Chats/Detail.js
Expand Up @@ -70,9 +70,9 @@ class Message extends React.Component {
data: { seenAt },
} = this.props
if (seenAt !== nextProps.data.seenAt) {
return false
return true
}
return true
return false
}

render () {
Expand All @@ -87,9 +87,8 @@ class Message extends React.Component {
const isMyself = contact && contact.status === 42
const isOneToOne =
conversation.kind === enums.BertyEntityConversationInputKind.OneToOne

// TODO: implement message seen
if (this.props.data.seenAt === null) {
// TODO: implement message seeni
if (new Date(this.props.data.seenAt).getTime() === 0) {
this.messageSeen()
}
return (
Expand Down Expand Up @@ -147,9 +146,7 @@ class Message extends React.Component {
{dateFns.fuzzyTimeOrFull(new Date(data.createdAt))}{' '}
{isMyself ? (
<Icon
name={
new Date(data.ackedAt).getTime() > 0 ? 'check-circle' : 'circle'
}
name={utils.isReadByOthers(data) ? 'check-circle' : 'circle'}
size={10}
/>
) : null}{' '}
Expand Down
3 changes: 1 addition & 2 deletions client/react-native/common/components/Screens/Chats/List.js
Expand Up @@ -139,8 +139,7 @@ const ItemBase = fragments.Conversation(
const { data, navigation, t } = this.props
const { connected, unread } = this.state

const isRead = utils.isRead(data)

const isRead = utils.isReadByMe(data)
// fix when contact request is send after conversation invite
if (
data.members.length === 2 &&
Expand Down
92 changes: 48 additions & 44 deletions client/react-native/common/components/Screens/Contacts/List/Item.js
Expand Up @@ -5,60 +5,64 @@ import { borderBottom, marginLeft, padding } from '../../../../styles'
import { colors } from '../../../../constants'
import { showContact } from '../../../../helpers/contacts'
import { withNavigation } from 'react-navigation'
import ActionsUnknown from '../../../Library/ContactIdentityActions/ActionsUnknown'
import ActionsReceived from '../../../Library/ContactIdentityActions/ActionsReceived'
import ActionsSent from '../../../Library/ContactIdentityActions/ActionsSent'
import { withNamespaces } from 'react-i18next'

const Item = fragments.Contact(class Item extends PureComponent {
async showDetails () {
const { data, context, navigation } = this.props
const Item = fragments.Contact(
class Item extends PureComponent {
async showDetails () {
const { data, context, navigation } = this.props

return showContact({ data, context, navigation })
}
return showContact({ data, context, navigation })
}

render () {
const { data, ignoreMyself, t } = this.props
const { overrideDisplayName, displayName, status } = data
render () {
const { data, ignoreMyself, t } = this.props
const { overrideDisplayName, displayName, status } = data

if (
ignoreMyself &&
if (
ignoreMyself &&
status === enums.BertyEntityContactInputStatus.Myself
) {
return null
}
) {
return null
}

return (
<Flex.Cols
align='center'
style={[
{ 'height': 72 },
padding,
borderBottom,
]}
onPress={() => this.showDetails()}
>
<Flex.Cols size={1} align='center'>
<Avatar data={data} size={40} />
<Flex.Rows size={3} justify='start' style={[marginLeft]}>
<Text color={colors.fakeBlack} left ellipsed>
{overrideDisplayName || displayName}
</Text>
<Text color={colors.subtleGrey} left ellipsed tiny>
{t(`contacts.statuses.${
enums.ValueBertyEntityContactInputStatus[status]
}`)}
</Text>
</Flex.Rows>
return (
<Flex.Cols
align='center'
style={[{ height: 72 }, padding, borderBottom]}
onPress={() => this.showDetails()}
>
<Flex.Cols size={1} align='center'>
<Avatar data={data} size={40} />
<Flex.Rows size={3} justify='start' style={[marginLeft]}>
<Text color={colors.fakeBlack} left ellipsed>
{overrideDisplayName || displayName}
</Text>
<Text color={colors.subtleGrey} left ellipsed tiny>
{t(
`contacts.statuses.${
enums.ValueBertyEntityContactInputStatus[status]
}`
)}
</Text>
</Flex.Rows>
</Flex.Cols>
{status === enums.BertyEntityContactInputStatus.Unknown && (
<ActionsUnknown data={data} />
)}
{status === enums.BertyEntityContactInputStatus.RequestedMe && (
<ActionsReceived data={data} />
)}
{status === enums.BertyEntityContactInputStatus.IsRequested && (
<ActionsSent data={data} />
)}
</Flex.Cols>
{status === enums.BertyEntityContactInputStatus.RequestedMe && (
<ActionsReceived data={data} />
)}
{status === enums.BertyEntityContactInputStatus.IsRequested && (
<ActionsSent data={data} />
)}
</Flex.Cols>
)
)
}
}
})
)

export default withNavigation(withNamespaces()(Item))
2 changes: 2 additions & 0 deletions client/react-native/common/graphql/fragments/Conversation.js
Expand Up @@ -9,6 +9,7 @@ export default component =>
createdAt
updatedAt
readAt
wroteAt
title
topic
infos
Expand All @@ -18,6 +19,7 @@ export default component =>
createdAt
updatedAt
readAt
wroteAt
status
contact {
id
Expand Down
4 changes: 4 additions & 0 deletions client/react-native/common/graphql/queries/Conversation.js
Expand Up @@ -9,6 +9,7 @@ const query = graphql`
$createdAt: GoogleProtobufTimestampInput
$updatedAt: GoogleProtobufTimestampInput
$readAt: GoogleProtobufTimestampInput
$wroteAt: GoogleProtobufTimestampInput
$title: String!
$topic: String!
$infos: String!
Expand All @@ -19,6 +20,7 @@ const query = graphql`
createdAt: $createdAt
updatedAt: $updatedAt
readAt: $readAt
wroteAt: $wroteAt
title: $title
topic: $topic
infos: $infos
Expand All @@ -29,13 +31,15 @@ const query = graphql`
createdAt
updatedAt
readAt
wroteAt
title
topic
infos
members {
id
createdAt
updatedAt
wroteAt
status
contact {
id
Expand Down
2 changes: 2 additions & 0 deletions client/react-native/common/i18n/en/messages.json
Expand Up @@ -169,6 +169,8 @@
"decline-action-feedback": "Contact request has been declined",
"resend-action": "Resend",
"resend-action-feedback": "Contact request has been sent again",
"request-action": "Request",
"request-action-feedback": "Contact request has been sent",
"cancel-request-action": "Remove",
"cancel-request-action-feedback": "Contact invitation has been removed",
"block-confirm-question": "Are you sure you want to block this contact?",
Expand Down
2 changes: 2 additions & 0 deletions client/react-native/common/i18n/fr/messages.json
Expand Up @@ -169,6 +169,8 @@
"decline-action-feedback": "L'invitation a été refusée",
"resend-action": "Renvoyer",
"resend-action-feedback": "L'invitation a été envoyée à nouveau",
"request-action": "Ajouter",
"request-action-feedback": "L'invitation a été envoyée",
"cancel-request-action": "Annuler",
"cancel-request-action-feedback": "L'invitation a été annulée",
"block-confirm-question": "Êtes vous sûr de vouloir bloquer ce contact ?",
Expand Down
27 changes: 17 additions & 10 deletions client/react-native/common/schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions client/react-native/common/utils/conversation.js
Expand Up @@ -28,12 +28,26 @@ export const getTitle = ({ title, members }) =>
export const getRelayID = id => btoa(`conversation:${id}`)
export const getCoreID = id => atob(id).match(/:(.*)$/)[1]

export const isRead = ({ members }) => {
export const isReadByMe = ({ wroteAt, members }) => {
const myself = members.find(
_ => _.contact.status === BertyEntityContactInputStatus.Myself
_ => _.contact && _.contact.status === BertyEntityContactInputStatus.Myself
)
if (myself == null) {
return true
}
return new Date(myself.readAt).getTime() > 0
return new Date(myself.readAt).getTime() >= new Date(wroteAt).getTime()
}

export const isMessageReadByMe = ({ members }, { createdAt }) => {
const myself = members.find(
_ => _.contact && _.contact.status === BertyEntityContactInputStatus.Myself
)
if (myself == null) {
return true
}
return new Date(myself.readAt).getTime() >= new Date(createdAt).getTime()
}

export const isReadByOthers = message =>
message.dispatches &&
message.dispatches.some(_ => new Date(_.ackedAt).getTime() > 0)

0 comments on commit 94aa178

Please sign in to comment.