Skip to content

Commit

Permalink
feat: Refresh conversations and messages when the app start from the …
Browse files Browse the repository at this point in the history
…b.g (#720)
  • Loading branch information
muhsin-k committed Jul 24, 2023
1 parent 827787f commit dffd859
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 30 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Expand Up @@ -140,8 +140,8 @@ android {
applicationId "com.chatwoot.app"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 5171
versionName "1.10.1"
versionCode 5174
versionName "1.10.2"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

multiDexEnabled true
Expand Down
8 changes: 4 additions & 4 deletions ios/Chatwoot.xcodeproj/project.pbxproj
Expand Up @@ -567,7 +567,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Chatwoot/Chatwoot.entitlements;
CURRENT_PROJECT_VERSION = 304;
CURRENT_PROJECT_VERSION = 305;
DEVELOPMENT_TEAM = L7YLMN4634;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Chatwoot/Info.plist;
Expand All @@ -580,7 +580,7 @@
"$(SDKROOT)/usr/lib/swift",
"$(inherited)",
);
MARKETING_VERSION = 1.10.1;
MARKETING_VERSION = 1.10.2;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand All @@ -605,7 +605,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = Chatwoot/Chatwoot.entitlements;
CURRENT_PROJECT_VERSION = 304;
CURRENT_PROJECT_VERSION = 305;
DEVELOPMENT_TEAM = L7YLMN4634;
INFOPLIST_FILE = Chatwoot/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Chatwoot;
Expand All @@ -617,7 +617,7 @@
"$(SDKROOT)/usr/lib/swift",
"$(inherited)",
);
MARKETING_VERSION = 1.10.1;
MARKETING_VERSION = 1.10.2;
OTHER_LDFLAGS = (
"$(inherited)",
"-ObjC",
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@chatwoot/mobile-app",
"version": "1.10.1",
"version": "1.10.2",
"private": true,
"scripts": {
"android": "react-native run-android",
Expand Down
4 changes: 2 additions & 2 deletions src/constants/index.js
Expand Up @@ -4,8 +4,8 @@ export const SCREENS = {
LOGIN: 'Login',
CONFIG_URL: 'ConfigureURL',
CONVERSATION: 'ConversationScreen',
NOTIFICATION: 'Notification',
SETTINGS: 'Settings',
NOTIFICATION: 'NotificationScreen',
SETTINGS: 'SettingsScreen',
DETAIL: 'Detail',
CHAT: 'ChatScreen',
};
Expand Down
8 changes: 6 additions & 2 deletions src/screens/ChatScreen/ChatScreen.js
Expand Up @@ -145,10 +145,14 @@ const ChatScreenComponent = ({ navigation, route }) => {
// Update messages list when app comes to foreground from background
useEffect(() => {
const appStateListener = AppState.addEventListener('change', nextAppState => {
if (appState === 'background' && nextAppState === 'active') {
if (appState.match(/inactive|background/) && nextAppState === 'active') {
const routeName = getCurrentRouteName();
if (routeName === SCREENS.CHAT) {
dispatch(conversationActions.updateConversationAndMessages({ conversationId }));
dispatch(
conversationActions.fetchPreviousMessages({
conversationId,
}),
);
}
}
setAppState(nextAppState);
Expand Down
32 changes: 15 additions & 17 deletions src/screens/Conversation/ConversationScreen.js
Expand Up @@ -120,37 +120,35 @@ const ConversationScreen = () => {
// Update notifications when app comes to foreground from background
useEffect(() => {
const appStateListener = AppState.addEventListener('change', nextAppState => {
if (appState === 'background' && nextAppState === 'active') {
if (appState.match(/inactive|background/) && nextAppState === 'active') {
const routeName = getCurrentRouteName();
if (REFRESH_SCREEN_LIST.includes(routeName)) {
loadConversations({
page: pageNumber,
assignee: assigneeType,
status: conversationStatus,
inboxId: activeInboxId,
sortBy: sortFilter,
});
refreshConversationsAgain();
}
}
setAppState(nextAppState);
});
return () => {
appStateListener?.remove();
};
}, [
appState,
pageNumber,
assigneeType,
conversationStatus,
activeInboxId,
loadConversations,
sortFilter,
]);
}, [appState, refreshConversationsAgain]);

const onChangePage = async () => {
setPage(pageNumber + 1);
};

const refreshConversationsAgain = useCallback(async () => {
await dispatch(clearAllConversations());
setPage(1);
loadConversations({
page: 1,
assignee: assigneeType,
status: conversationStatus,
inboxId: activeInboxId,
sortBy: sortFilter,
});
}, [dispatch, assigneeType, conversationStatus, activeInboxId, loadConversations, sortFilter]);

const refreshConversations = async () => {
AnalyticsHelper.track(CONVERSATION_EVENTS.REFRESH_CONVERSATIONS);
await dispatch(clearAllConversations());
Expand Down
4 changes: 2 additions & 2 deletions src/screens/Notification/NotificationScreen.js
Expand Up @@ -110,10 +110,10 @@ const NotificationScreen = ({ navigation }) => {
);
};

// Update conversations when app comes to foreground from background
// Update notifications when app comes to foreground from background
useEffect(() => {
const appStateListener = AppState.addEventListener('change', nextAppState => {
if (appState === 'background' && nextAppState === 'active') {
if (appState.match(/inactive|background/) && nextAppState === 'active') {
const routeName = getCurrentRouteName();
if (REFRESH_SCREEN_LIST.includes(routeName)) {
dispatch(notificationsActions.index({ pageNo }));
Expand Down

0 comments on commit dffd859

Please sign in to comment.