Skip to content

Commit

Permalink
feat: debug notification verbosity and alerts optout
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Louvigny authored and glouvigny committed Feb 4, 2019
1 parent 3955fcb commit 796d483
Show file tree
Hide file tree
Showing 22 changed files with 580 additions and 115 deletions.
Expand Up @@ -5,6 +5,7 @@ import colors from '../../../../constants/colors'
import { withNavigation } from 'react-navigation'
import { showMessage } from 'react-native-flash-message'
import { RelayContext } from '../../../../relay'
import { enums } from '../../../../graphql'

class NotificationsBase extends PureComponent {
constructor (props) {
Expand All @@ -14,6 +15,7 @@ class NotificationsBase extends PureComponent {
config: {
pushRelayPubkeyApns: props.config.pushRelayPubkeyApns,
pushRelayPubkeyFcm: props.config.pushRelayPubkeyFcm,
debugNotificationVerbosity: props.config.debugNotificationVerbosity,
},
}
}
Expand All @@ -28,6 +30,16 @@ class NotificationsBase extends PureComponent {
<Menu.Item title={'FCM relay id'} boldLeft />
<Menu.Item value={this.state.config.pushRelayPubkeyFcm} onChangeText={pushRelayPubkeyFcm => this.setState({ config: { ...this.state.config, pushRelayPubkeyFcm } })} input />
</Menu.Section>
<Menu.Section title={'Debug'}>
<Menu.Item title={'Debug verbosity'} boldLeft />
{Object.entries(enums.BertyEntityDebugVerbosityInputDebugVerbosity).map(([k, v]) => <Menu.Item
icon={this.state.config.debugNotificationVerbosity === v ? 'check-circle' : 'circle'}
title={k}
key={k}
onPress={() => this.setState({ config: { ...this.state.config, debugNotificationVerbosity: v } })}
/>
)}
</Menu.Section>
<Menu.Section>
<Menu.Item title={'Save'} boldLeft color={colors.blue} onPress={() => this.updateConfig()} />
</Menu.Section>
Expand All @@ -40,6 +52,7 @@ class NotificationsBase extends PureComponent {
...this.props.config,
pushRelayPubkeyApns: this.state.config.pushRelayPubkeyApns,
pushRelayPubkeyFcm: this.state.config.pushRelayPubkeyFcm,
debugNotificationVerbosity: this.state.config.debugNotificationVerbosity,
}

await this.props.relayContext.mutations.configUpdate(config)
Expand Down
Expand Up @@ -13,6 +13,8 @@ import {
disableMQTTNotifications,
} from '../../../helpers/notifications'
import { enums } from '../../../graphql'
import { withConfig } from '../../../helpers/config'
import { showMessage } from 'react-native-flash-message'

const dummyPubKey =
'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1wyoWXdQZeaQoOKvC2YRwR3+GTb8prpMFNdOmhikU8eionUBKgKnUyIbr/DTvCJQhTlHZfy1pUL6mmRIk9PDQDO1t4ATY9LXfo/O3KoKJ0GmxhGdjheOf1kiKcrem+MJjBVEriZ7tJvuhA/DztQ1zolvflPz9+aNL1qA6qzJD/m2fNYpfEehtZH37MoN/qcn3THnC8H/wwr6soU5GpdPBiXXKcg1IFiaZX9JAoUzKVyzY1xQ/DOzCYCboPSXh1qSsMFsg2LCAmC56s9czKk7foAOV/WZ3Zzbv6yd74K6TdV0xwMgCctZjNa7/Tbq4pCBK2vEMutSXAJlfo+6K9dLQQIDAQAB'
Expand All @@ -28,9 +30,37 @@ class NotificationsBase extends PureComponent {
elt.pushType === enums.BertyPushDevicePushTypeInputDevicePushType.MQTT
)

getCurrentConfig = () => this.props.config

state = {
pushConfigsSwitch: this.getCurrentPushConfigs().length > 0,
mqttConfigsSwitch: this.getCurrentMQTTConfigs().length > 0,
notificationsEnabled: this.getCurrentConfig().notificationsEnabled,
notificationsPreviews: this.getCurrentConfig().notificationsPreviews,
}

async updateConfig () {
try {
const config = {
...this.props.config,
notificationsEnabled: this.state.notificationsEnabled,
notificationsPreviews: this.state.notificationsPreviews,
}

await this.props.context.mutations.configUpdate(config)
} catch (e) {
showMessage({
message: String(e),
type: 'danger',
icon: 'danger',
position: 'top',
})

this.setState({
notificationsEnabled: this.getCurrentConfig().notificationsEnabled,
notificationsPreviews: this.getCurrentConfig().notificationsPreviews,
})
}
}

render () {
Expand Down Expand Up @@ -136,12 +166,18 @@ class NotificationsBase extends PureComponent {
<Menu.Item
title={t('chats.notifications-enabled')}
left
customRight={<Switch justify='end' disabled={false} value />}
customRight={<Switch justify='end' onValueChange={async notificationsEnabled => {
this.setState({ notificationsEnabled }, () => this.updateConfig())
}} value={this.state.notificationsEnabled} />}
/>
<Menu.Item
title={t('chats.notifications-preview')}
left
customRight={<Switch justify='end' disabled={false} value />}
customRight={<Switch justify='end'
onValueChange={async notificationsPreviews => {
this.setState({ notificationsPreviews }, () => this.updateConfig())
}}
value={this.state.notificationsPreviews} />}
/>
<Menu.Item
title={t('chats.notifications-sound')}
Expand Down Expand Up @@ -209,4 +245,4 @@ export default class NotificationWrapper extends React.PureComponent {
}
}

const Notifications = withNamespaces()(NotificationsBase)
const Notifications = withConfig(withNamespaces()(NotificationsBase), { showOnlyLoaded: true })
16 changes: 16 additions & 0 deletions client/react-native/common/graphql/enums.gen.js
Expand Up @@ -294,6 +294,22 @@ export const ValueBertyNetworkConnectionTypeInputConnectionType = {
3: 'CANNOT_CONNECT',
}

export const BertyEntityDebugVerbosityInputDebugVerbosity = {
VERBOSITY_LEVEL_NONE: 0,
VERBOSITY_LEVEL_ERROR: 1,
VERBOSITY_LEVEL_WARN: 2,
VERBOSITY_LEVEL_INFO: 3,
VERBOSITY_LEVEL_DEBUG: 4,
}

export const ValueBertyEntityDebugVerbosityInputDebugVerbosity = {
0: 'VERBOSITY_LEVEL_NONE',
1: 'VERBOSITY_LEVEL_ERROR',
2: 'VERBOSITY_LEVEL_WARN',
3: 'VERBOSITY_LEVEL_INFO',
4: 'VERBOSITY_LEVEL_DEBUG',
}

export const BertyPkgDeviceinfoTypeInputType = { Unknown: 0, Raw: 1, Json: 2 }

export const ValueBertyPkgDeviceinfoTypeInputType = {
Expand Down
11 changes: 7 additions & 4 deletions client/react-native/common/graphql/mutations/ConfigUpdate.js
Expand Up @@ -2,13 +2,16 @@ import { graphql } from 'react-relay'
import { commit } from '../../relay'

const ConfigUpdateMutation = graphql`
mutation ConfigUpdateMutation($pushRelayPubkeyApns: String!, $pushRelayPubkeyFcm: String!) {
ConfigUpdate(id: "", myselfId: "", currentDeviceId: "", pushRelayPubkeyApns: $pushRelayPubkeyApns, pushRelayPubkeyFcm: $pushRelayPubkeyFcm) {
mutation ConfigUpdateMutation($pushRelayPubkeyApns: String!, $pushRelayPubkeyFcm: String!, $notificationsEnabled: Bool!, $notificationsPreviews: Bool!, $debugNotificationVerbosity: Enum) {
ConfigUpdate(id: "", myselfId: "", currentDeviceId: "", pushRelayPubkeyApns: $pushRelayPubkeyApns, pushRelayPubkeyFcm: $pushRelayPubkeyFcm, notificationsEnabled: $notificationsEnabled, notificationsPreviews: $notificationsPreviews, debugNotificationVerbosity: $debugNotificationVerbosity) {
id
createdAt
updatedAt
pushRelayPubkeyApns,
pushRelayPubkeyFcm,
pushRelayPubkeyApns
pushRelayPubkeyFcm
notificationsEnabled
notificationsPreviews
debugNotificationVerbosity
}
}
`
Expand Down
7 changes: 5 additions & 2 deletions client/react-native/common/graphql/queries/ConfigPublic.js
Expand Up @@ -7,8 +7,11 @@ const query = graphql`
id
createdAt
updatedAt
pushRelayPubkeyApns,
pushRelayPubkeyFcm,
pushRelayPubkeyApns
pushRelayPubkeyFcm
notificationsEnabled
notificationsPreviews
debugNotificationVerbosity
}
}
`
Expand Down
7 changes: 7 additions & 0 deletions client/react-native/common/schema.graphql

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

16 changes: 16 additions & 0 deletions core/api/node/graphql/enums.gen.js
Expand Up @@ -294,6 +294,22 @@ export const ValueBertyNetworkConnectionTypeInputConnectionType = {
3: 'CANNOT_CONNECT',
}

export const BertyEntityDebugVerbosityInputDebugVerbosity = {
VERBOSITY_LEVEL_NONE: 0,
VERBOSITY_LEVEL_ERROR: 1,
VERBOSITY_LEVEL_WARN: 2,
VERBOSITY_LEVEL_INFO: 3,
VERBOSITY_LEVEL_DEBUG: 4,
}

export const ValueBertyEntityDebugVerbosityInputDebugVerbosity = {
0: 'VERBOSITY_LEVEL_NONE',
1: 'VERBOSITY_LEVEL_ERROR',
2: 'VERBOSITY_LEVEL_WARN',
3: 'VERBOSITY_LEVEL_INFO',
4: 'VERBOSITY_LEVEL_DEBUG',
}

export const BertyPkgDeviceinfoTypeInputType = { Unknown: 0, Raw: 1, Json: 2 }

export const ValueBertyPkgDeviceinfoTypeInputType = {
Expand Down
9 changes: 9 additions & 0 deletions core/api/node/graphql/gqlgen.gen.yml

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

0 comments on commit 796d483

Please sign in to comment.