Skip to content

Commit 6428c04

Browse files
authored
Feature: Update badge count after receiving the notification (#239)
1 parent 488ada3 commit 6428c04

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/actions/notification.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import {
2222
} from '../constants/actions';
2323
import APIHelper from '../helpers/APIHelper';
2424

25+
import { updateBadgeCount } from '../helpers/PushHelper';
26+
2527
import {
2628
GET_NOTIFICATION,
2729
GET_NOTIFICATION_SUCCESS,
@@ -42,6 +44,8 @@ export const getAllNotifications = ({ pageNo = 1 }) => async (dispatch) => {
4244
const updatedPayload = payload.sort((a, b) => {
4345
return b.created_at - a.created_at;
4446
});
47+
const { unread_count } = meta;
48+
updateBadgeCount({ count: unread_count });
4549

4650
dispatch({
4751
type: GET_NOTIFICATION_SUCCESS,
@@ -87,6 +91,8 @@ export const markNotificationAsRead = ({ primaryActorId, primaryActorType }) =>
8791

8892
const updatedUnReadCount = unread_count ? unread_count - 1 : unread_count;
8993

94+
updateBadgeCount({ count: updatedUnReadCount });
95+
9096
dispatch({
9197
type: UPDATE_ALL_NOTIFICATIONS,
9298
payload: {
@@ -109,7 +115,7 @@ export const markAllNotificationAsRead = () => async (dispatch, getState) => {
109115
item.read_at = 'read_at';
110116
return item;
111117
});
112-
118+
updateBadgeCount({ count: 0 });
113119
dispatch({
114120
type: UPDATE_ALL_NOTIFICATIONS,
115121
payload: {

src/helpers/PushHelper.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ export const handlePush = async ({ remoteMessage, type }) => {
4343

4444
export const clearAllDeliveredNotifications = () => {
4545
if (Platform.OS === 'android') {
46-
// PushNotification.cancelAllLocalNotifications();
4746
} else {
4847
PushNotificationIOS.removeAllDeliveredNotifications();
4948
}
5049
};
50+
51+
export const updateBadgeCount = ({ count }) => {
52+
if (Platform.OS === 'android') {
53+
} else {
54+
PushNotificationIOS.setApplicationIconBadgeNumber(count);
55+
}
56+
};

src/screens/ConfigureURLScreen/ConfigureURLScreen.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useSelector, useDispatch } from 'react-redux';
55
import { withStyles } from '@ui-kitten/components';
66
import t from 'tcomb-form-native';
77
import PropTypes from 'prop-types';
8+
import DeviceInfo from 'react-native-device-info';
89

910
import { setInstallationUrl, resetSettings } from '../../actions/settings';
1011
import styles from './ConfigureURLScreen.style';
@@ -21,6 +22,8 @@ const URLForm = t.struct({
2122
url: URL,
2223
});
2324

25+
const appName = DeviceInfo.getApplicationName();
26+
2427
const propTypes = {
2528
eva: PropTypes.shape({
2629
style: PropTypes.object,
@@ -44,7 +47,7 @@ const ConfigureURLScreenComponent = ({ eva }) => {
4447
const dispatch = useDispatch();
4548
const inputRef = useRef(null);
4649
const [values, setValues] = useState({
47-
url: 'app.chatwoot.com',
50+
url: appName === 'Chatwoot' ? 'app.chatwoot.com' : null,
4851
});
4952

5053
const options = {

0 commit comments

Comments
 (0)