diff --git a/android/app/build.gradle b/android/app/build.gradle index 586f17276..ac1afb01c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -136,8 +136,8 @@ android { applicationId "com.chatwoot.app" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 5014 - versionName "1.3.11" + versionCode 5015 + versionName "1.3.15" multiDexEnabled true } splits { diff --git a/ios/Chatwoot.xcodeproj/project.pbxproj b/ios/Chatwoot.xcodeproj/project.pbxproj index 4328a968f..a7737ded2 100644 --- a/ios/Chatwoot.xcodeproj/project.pbxproj +++ b/ios/Chatwoot.xcodeproj/project.pbxproj @@ -753,14 +753,14 @@ CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 137; + CURRENT_PROJECT_VERSION = 140; DEVELOPMENT_TEAM = 6C953F3RX2; ENABLE_BITCODE = NO; EXCLUDED_ARCHS = ""; INFOPLIST_FILE = Chatwoot/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.3; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 1.3.11; + MARKETING_VERSION = 1.3.15; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -786,13 +786,13 @@ CODE_SIGN_ENTITLEMENTS = Chatwoot/Chatwoot.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 137; + CURRENT_PROJECT_VERSION = 140; DEVELOPMENT_TEAM = 6C953F3RX2; EXCLUDED_ARCHS = ""; INFOPLIST_FILE = Chatwoot/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.3; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 1.3.11; + MARKETING_VERSION = 1.3.15; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", diff --git a/package.json b/package.json index 1e28ac2c5..64cd8ca51 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chatwoot/mobile-app", - "version": "1.3.11", + "version": "1.3.15", "private": true, "scripts": { "clean": "rm -rf $TMPDIR/react-* && watchman watch-del-all && npm cache clean --force", diff --git a/src/actions/notification.js b/src/actions/notification.js index 05277d583..8f0b2bc98 100644 --- a/src/actions/notification.js +++ b/src/actions/notification.js @@ -30,78 +30,79 @@ import { GET_NOTIFICATION_ERROR, } from '../constants/actions'; -export const getAllNotifications = ({ pageNo = 1 }) => async (dispatch) => { - try { - if (pageNo === 1) { - dispatch({ type: GET_NOTIFICATION }); - } - - const response = await APIHelper.get(`notifications?page=${pageNo}`); - const { - data: { payload, meta }, - } = response.data; +export const getAllNotifications = + ({ pageNo = 1 }) => + async dispatch => { + try { + if (pageNo === 1) { + dispatch({ type: GET_NOTIFICATION }); + } - const updatedPayload = payload.sort((a, b) => { - return b.created_at - a.created_at; - }); - const { unread_count } = meta; - updateBadgeCount({ count: unread_count }); + const response = await APIHelper.get(`notifications?page=${pageNo}`); + const { + data: { payload, meta }, + } = response.data; - dispatch({ - type: GET_NOTIFICATION_SUCCESS, - payload: { - notifications: updatedPayload, - meta, - }, - }); + const updatedPayload = payload.sort((a, b) => { + return b.created_at - a.created_at; + }); + const { unread_count } = meta; + updateBadgeCount({ count: unread_count }); - if (payload.length < 25) { dispatch({ - type: ALL_NOTIFICATIONS_LOADED, + type: GET_NOTIFICATION_SUCCESS, + payload: { + notifications: updatedPayload, + meta, + }, }); + + if (payload.length < 25) { + dispatch({ + type: ALL_NOTIFICATIONS_LOADED, + }); + } + } catch (error) { + dispatch({ type: GET_NOTIFICATION_ERROR, payload: error }); } - } catch (error) { - dispatch({ type: GET_NOTIFICATION_ERROR, payload: error }); - } -}; + }; -export const markNotificationAsRead = ({ primaryActorId, primaryActorType }) => async ( - dispatch, - getState, -) => { - const { - data: { payload, meta }, - } = getState().notification; - try { - const apiUrl = 'notifications/read_all'; - await APIHelper.post(apiUrl, { - primary_actor_type: primaryActorType, - primary_actor_id: primaryActorId, - }); +export const markNotificationAsRead = + ({ primaryActorId, primaryActorType }) => + async (dispatch, getState) => { + const { + data: { payload, meta }, + } = getState().notification; + try { + const apiUrl = 'notifications/read_all'; + await APIHelper.post(apiUrl, { + primary_actor_type: primaryActorType, + primary_actor_id: primaryActorId, + }); - const updatedNotifications = payload.map((item, index) => { - if (item.primary_actor_id === primaryActorId) { - item.read_at = 'read_at'; - item.mass = 'mass'; - } - return item; - }); + const updatedNotifications = payload.map((item, index) => { + if (item.primary_actor_id === primaryActorId) { + item.read_at = 'read_at'; + item.mass = 'mass'; + } + return item; + }); - const { unread_count } = meta; + const { unread_count } = meta; - const updatedUnReadCount = unread_count ? unread_count - 1 : unread_count; + const updatedUnReadCount = unread_count ? unread_count - 1 : unread_count; - updateBadgeCount({ count: updatedUnReadCount }); + updateBadgeCount({ count: updatedUnReadCount }); - dispatch({ - type: UPDATE_ALL_NOTIFICATIONS, - payload: { - notifications: updatedNotifications, - meta: { unread_count: updatedUnReadCount }, - }, - }); - } catch {} -}; + dispatch({ + type: UPDATE_ALL_NOTIFICATIONS, + payload: { + notifications: updatedNotifications, + meta: { unread_count: updatedUnReadCount }, + }, + }); + } catch {} + }; export const markAllNotificationAsRead = () => async (dispatch, getState) => { const { @@ -126,18 +127,13 @@ export const markAllNotificationAsRead = () => async (dispatch, getState) => { } catch (error) {} }; -export const saveDeviceDetails = ({ token }) => async (dispatch) => { +export const saveDeviceDetails = () => async dispatch => { try { - const checkPermission = await messaging().hasPermission(); - if (!checkPermission || checkPermission === -1) { + const permissionEnabled = await messaging().hasPermission(); + if (!permissionEnabled || permissionEnabled === -1) { await messaging().requestPermission(); } - - if (Platform.os === 'ios') { - await messaging().registerForRemoteNotifications(); - } - // Check refresh token or create new fcm token - const fcmToken = token || (await messaging().getToken()); + const fcmToken = await messaging().getToken(); const deviceId = getUniqueId(); const devicePlatform = getSystemName(); const manufacturer = await getManufacturer(); @@ -161,23 +157,27 @@ export const saveDeviceDetails = ({ token }) => async (dispatch) => { }; const headers = await getHeaders(); const baseURL = await getBaseUrl(); + await axios.post(`${baseURL}${API_URL}notification_subscriptions`, pushData, { headers: headers, }); + dispatch({ type: SET_PUSH_TOKEN, payload: fcmToken }); } catch (err) {} }; -export const addNotification = ({ notification }) => async (dispatch, getState) => { - const { - data: { payload }, - } = getState().notification; +export const addNotification = + ({ notification }) => + async (dispatch, getState) => { + const { + data: { payload }, + } = getState().notification; - // Check notification is already exists or not - const [notificationExists] = payload.filter((c) => c.id === notification.id); + // Check notification is already exists or not + const [notificationExists] = payload.filter(c => c.id === notification.id); - if (notificationExists) { - return; - } - dispatch({ type: ADD_NOTIFICATION, payload: notification }); -}; + if (notificationExists) { + return; + } + dispatch({ type: ADD_NOTIFICATION, payload: notification }); + }; diff --git a/src/helpers/PushHelper.js b/src/helpers/PushHelper.js index 6748b4901..ea5121b40 100644 --- a/src/helpers/PushHelper.js +++ b/src/helpers/PushHelper.js @@ -53,8 +53,7 @@ export const clearAllDeliveredNotifications = () => { }; export const updateBadgeCount = ({ count }) => { - if (Platform.OS === 'android') { - } else { + if (Platform.OS === 'ios' && count) { PushNotificationIOS.setApplicationIconBadgeNumber(count); } }; diff --git a/src/screens/ConversationList/ConversationList.js b/src/screens/ConversationList/ConversationList.js index f5892ebb3..90e6d5d54 100644 --- a/src/screens/ConversationList/ConversationList.js +++ b/src/screens/ConversationList/ConversationList.js @@ -39,7 +39,6 @@ const ConversationList = ({ eva: { style }, navigation }) => { const conversations = useSelector(state => state.conversation.data); const conversationStatus = useSelector(state => state.conversation.conversationStatus); const inboxSelected = useSelector(state => state.inbox.inboxSelected); - const pushToken = useSelector(state => state.notification.pushToken); useEffect(() => { clearAllDeliveredNotifications(); @@ -47,15 +46,14 @@ const ConversationList = ({ eva: { style }, navigation }) => { dispatch(getInstalledVersion()); dispatch(getInboxes()); dispatch(getAgents()); - // loadConversations(); - dispatch(getAllNotifications({ pageNo: 1 })); - // TODO: Check this logic later - dispatch(saveDeviceDetails({ token: null })); - if (!pushToken) { - dispatch(saveDeviceDetails({ token: pushToken })); - } + dispatch(saveDeviceDetails()); storeUser(); - }, [dispatch, initActionCable, loadConversations, storeUser, pushToken]); + }, [dispatch, initActionCable, storeUser]); + + useEffect(() => { + loadConversations(); + dispatch(getAllNotifications({ pageNo: 1 })); + }, [dispatch, initActionCable, loadConversations]); const loadConversations = useCallback(() => { dispatch(