From 3ee6e673c84a46d49fedb22b45930354e69b69c7 Mon Sep 17 00:00:00 2001 From: Avinash Lingaloo Date: Fri, 18 Jun 2021 08:57:40 +0400 Subject: [PATCH] MM-35115 [Gekidou] Login flow - Email and Password (#5402) * MM_35115: ADDED select_server screen * MM_35115: ADDED select_server screen * MM_35115: ADDED files on which select_server is dependent * MM_35115: ADDED react-native-button * MM_35115: Fixing TS issues [IN PROGRESS] * MM_35115: Started withObservables [IN PROGRESS] * MM_35115: Started withObservables [IN PROGRESS] * MM_35115: withObservables - defaulting when no connection is available [IN PROGRESS] * MM_35115: withObservables - some code clean up [IN PROGRESS] * MM_35115: withObservables - some code clean up [IN PROGRESS] * MM_35115: withObservables - some code clean up [IN PROGRESS] * MM_35115: Substituting mapDispatchToProps [IN PROGRESS] * MM_35115: Substituting mapDispatchToProps [IN PROGRESS] * MM_35115: Substituting mapDispatchToProps [IN PROGRESS] * MM_35115: Removed resetPing action [IN PROGRESS] * MM_35115: ADDED app/client * MM_35115: Preparing scheduleExpiredNotification * MM_35115: Adding some todos * Server & LoginOptions * Use default server if available and autoconnect if configured * Fix login header & manual server url * MM_35115: Login Options[IN PROGRESS] * MM_35115: Login screen - email [IN PROGRESS] * MM_35115: Login screen - email [IN PROGRESS] * MM_35115: Login screen - email - login api call [IN PROGRESS] * MM_35115: Login screen - email - login api call [IN PROGRESS] * MM_35115: Login screen - email - saving to server db [IN PROGRESS] * MM_35115: Login screen - email - saving to System, Preferences to db [IN PROGRESS] * MM_35115: Login screen - enforcing unique check on System entity [IN PROGRESS] * MM_35115: Login screen - writing TeamMembership [IN PROGRESS] * MM_35115: Login screen - writing Teams [IN PROGRESS] * MM_35115: Login screen [IN PROGRESS] * MM_35115: Login screen- Refactored DataOperator handlers [IN PROGRESS] * MM_35115: Login screen - Proper clean up [IN PROGRESS] * MM_35115: Login screen - completeLogin [IN PROGRESS] * MM_35115: Improving DataOperator * MM_35115: Improving DataOperator * MM_35115: 80% DONE - login with email and password - some todos * MM_35115: 80% DONE - login with email and password - some todos * MM_35115: 80% DONE - login with email and password - some todos * MM_35115: Removing unused app/queries folder * MM_35115: Clean up * MM_35115: Clean up * MM_35115: Clean up * MM_35115: Clean up * MM_35115: Clean up * MM_35115: Adding roles for MYTEAM * MM_35115: Code clean up * MM_35115: Code clean up * MM_35115: Code clean up * MM_35115: Adding rn-fetch-blob for Android * MM_35115: Code clean up * MM_35115: Code clean up * MM_35115: Added test setup * MM_35115: Fix database utils * MM_35115: ADDED loadRolesIfNeeded * MM_35115: Fix TS issue * MM_35115: ADDED Tests setup * MM_35115: Fix TS issues * MM_35115: Fix TS issues * MM_35115: Fix TS issues * MM_35115: Added alternative to site name * MM_35115: Added alternative to site name * MM_35115: Removed hardcoded values * MM_35115: Clean up * MM_35115 - Fixed Android platform check instead of hermes * MM_35115 - Replaced emptyErrorHandlingFunction with emptyFunction * MM_35115 : Implemented TS fixes * Update index.ts * MM-35115 - Fix react-test-renderer issue * MM_35115 - Optimizing DatabaseManager * MM_35115 : Implemented getDatabaseConnection * MM_35115 : Refactoring set/getActiveDatabase to use flag record * MM_35115 : Refactored active database to use flag in Global entity * MM_35115 : Updated manual database manager test * MM_35115 : Fix operator/utils/test * MM_35115 : Fix for base_handler * MM_35115 : Fix test issues with Handlers * MM_35115 : Fix test issues with prepareRecords * MM_35115 : Fix wrapper test issue * MM_35115 : Updated getMostRecentServerConnection to return the serverUrl as well as the connection * MM_35115 : Refactored the way we call DataOperator * MM_35115 : Updated database manager mock * Add getMostRecentServerUrl function (#5440) * fix: add getMostRecentServerUrl func * fix: add ts and tsx to editorconfig * fix: rename functions * fix: return type * Fix unit test setup * fix login screen unit tests * MM-36205 [GEKIDOU] Login Flow SSO (#5454) * MM_35115: Starting LoginOptions SSO * MM_36205: SSO [IN PROGRESS] * MM_36205 : SSO [ IN PROGRESS ] * Update sso_with_redirect_url.tsx * MM_36205 : SSO Tests [ IN PROGRESS ] * MM_36205 : Passing serverUrl to SSO screen * Update sso.test.tsx * Fix ViewTypes imports and keyMirror method * MM_36205 : Code clean up * Fix : Clean up imports * Update: Aligning with PR 5452 * Fix: AndroidManifest file to include redirection ofr scheme mmauthbeta * refactor: SSO Login method via Gitlab now navigates to Channel screen * refactor: SSO Login without redirectURL is also working * feat: SSO - main test completed * feat: ADDED test for sso_with_redirect_url * fix : eslint correction * fix: Updated Loading component name * fix : code clean up from reviews * fix: reviews check * fix: Added mmauthbeta into info.plist * Revert "fix: Added mmauthbeta into info.plist" This reverts commit d87cc23f5b451a49d9ffa9de4745224b7ecfc977. * Update Info.plist * Update AppDelegate.m * feat: ADDED Forgot Password - Test [ IN PROGRESS ] * feat: Forgot Password - Completed & Tested * fix: Including MFA screen [ IN PROGRESS ] * MFA - Properly tested * Properly testing forgot_password screen * Fix login.test.tsx * Fix SSO method calls chain * Update index.tsx * Sort imports for sceen/navigation * fix: Reviews * Update signing + act in test * Removed todo comment on MFA * feedback review * fix login tests Co-authored-by: Avinash Lingaloo <> Co-authored-by: Elias Nahum * App initialization refactor (#5430) * fix: initial init refactor * fix: await isServerPresent * fix: more refactor * fix: move out launch functions * fix: remove comment * fix: update credential functions * fix: refactor launch functions * fix: deep link parsing * fix: lint change * fix: update deeplink and notification handlers * fix: indentation * fix: add relaunchApp * fix eslint * refactor launchProps and autoconnect server for deeplink * fix: use undefined * fix: define OptionalLaunchProps * fix: Android - handle server URL in push notification * fix: rename func * fix: use boolean launchError instead * fix: use DatabaseModule * fix: use DatabaseHelper instead * fix: remove unnecessary null check * fix: iOS - support for serverUrl * fix: iOS - extract serverUrl in reply action * fix: iOS - expose objc specific func * fix: remove unnecessary deviceToken param * fix: return if device is untrusted Co-authored-by: Elias Nahum * fix: bye bye modulePaths * fix: ios build * chore: remove unused aliases from babel.config * chore: fix dependency format in package-lock.json * chore: remove transparent window background color for android AppTheme * chore: remove mattermost.js and use index.ts as app entry * fix: login flow screens theme * fix: Launch types * chore: remove OptionalLaunchProps type * fix: url utils unit tests * chore: update en.json Co-authored-by: Elias Nahum Co-authored-by: Avinash Lingaloo <> Co-authored-by: Elias Nahum Co-authored-by: Miguel Alatzar --- .editorconfig | 2 +- .eslintrc.json | 3 +- .gitignore | 1 + android/app/src/main/AndroidManifest.xml | 22 +- .../com/mattermost/helpers/Credentials.java | 23 +- .../mattermost/helpers/DatabaseHelper.java | 34 + .../rnbeta/CustomPushNotification.java | 28 +- .../mattermost/rnbeta/MainApplication.java | 1 - .../NotificationReplyBroadcastReceiver.java | 4 +- .../mattermost/rnbeta/ReceiptDelivery.java | 6 +- android/app/src/main/res/values/styles.xml | 5 +- app/client/rest/apps.ts | 43 + app/client/rest/base.ts | 375 + app/client/rest/bots.ts | 37 + app/client/rest/channels.ts | 309 + app/client/rest/constants.ts | 14 + app/client/rest/emojis.ts | 99 + app/client/rest/error.ts | 26 + app/client/rest/files.ts | 47 + app/client/rest/general.ts | 95 + app/client/rest/groups.ts | 52 + app/client/rest/index.test.js | 83 + app/client/rest/index.ts | 56 + app/client/rest/integrations.ts | 66 + app/client/rest/posts.ts | 234 + app/client/rest/preferences.ts | 33 + app/client/rest/teams.ts | 175 + app/client/rest/tos.ts | 25 + app/client/rest/users.ts | 396 + app/client/websocket/index.ts | 247 + app/components/app_version/index.tsx | 38 + .../__snapshots__/error_text.test.tsx.snap | 24 + app/components/error_text/error_text.test.tsx | 28 + app/components/error_text/index.tsx | 59 + app/components/formatted_text/index.tsx | 88 + app/components/loading/index.tsx | 38 + app/components/loading/loading.stories.tsx | 17 + app/constants/files.ts | 18 + app/constants/general.ts | 72 + app/constants/index.ts | 8 +- app/constants/screens.ts | 9 + app/constants/sso.ts | 12 + app/constants/view.ts | 4 - app/database/manager/__mocks__/index.ts | 271 +- app/database/manager/index.ts | 269 +- app/database/manager/test.ts | 134 +- app/database/manager/test_manual.ts | 21 +- app/database/models/default/global.ts | 2 +- app/database/operator/comparators/index.ts | 2 +- .../operator/handlers/base_handler.test.ts | 70 +- .../operator/handlers/base_handler.ts | 64 +- .../operator/handlers/channel.test.ts | 38 +- app/database/operator/handlers/channel.ts | 32 +- app/database/operator/handlers/group.test.ts | 38 +- app/database/operator/handlers/group.ts | 32 +- app/database/operator/handlers/post.test.ts | 41 +- app/database/operator/handlers/post.ts | 13 +- app/database/operator/handlers/team.test.ts | 46 +- app/database/operator/handlers/team.ts | 61 +- app/database/operator/handlers/user.test.ts | 44 +- app/database/operator/handlers/user.ts | 46 +- app/database/operator/index.ts | 20 +- .../operator/prepareRecords/general.test.ts | 16 +- app/database/operator/prepareRecords/user.ts | 2 +- .../operator/utils/create_test_connection.ts | 8 +- app/database/operator/utils/general.ts | 22 +- app/database/operator/utils/test.ts | 14 +- app/database/operator/wrapper/index.ts | 29 +- app/database/operator/wrapper/test.ts | 34 +- .../schema/server/table_schemas/user.ts | 1 - app/database/schema/server/test.ts | 2 - app/i18n/index.ts | 106 +- app/init/analytics.ts | 2 +- app/init/credentials.ts | 112 +- app/init/emm_provider.ts | 212 - app/init/fetch.js | 145 + app/init/global_event_handler.ts | 30 +- app/init/launch.ts | 146 + app/init/managed_app.ts | 190 + app/init/push_notifications.ts | 355 +- app/mattermost.ts | 98 - app/queries/global.ts | 13 + app/queries/role.ts | 14 + app/queries/system.ts | 38 + app/queries/user.ts | 12 + app/requests/local/systems.ts | 84 + app/requests/local/timezone.ts | 56 + app/requests/remote/error.ts | 39 + app/requests/remote/general.ts | 46 + app/requests/remote/push_notification.ts | 82 + app/requests/remote/role.ts | 39 + app/requests/remote/systems.ts | 22 + app/requests/remote/user.ts | 386 + app/screens/channel/index.tsx | 20 +- .../forgot_password.test.tsx.snap | 152 + .../forgot_password/forgot_password.test.tsx | 52 + app/screens/forgot_password/index.tsx | 223 + app/screens/{index.ts => index.tsx} | 69 +- .../login/__snapshots__/login.test.tsx.snap | 213 + app/screens/login/index.tsx | 452 + app/screens/login/login.test.tsx | 141 + app/screens/login_options/email.tsx | 63 + app/screens/login_options/gitlab.tsx | 73 + app/screens/login_options/google.tsx | 72 + app/screens/login_options/index.tsx | 145 + app/screens/login_options/ldap.tsx | 78 + app/screens/login_options/office365.tsx | 66 + app/screens/login_options/open_id.tsx | 64 + app/screens/login_options/saml.tsx | 71 + app/screens/login_options/types.d.ts | 12 + .../mfa/__snapshots__/mfa.test.tsx.snap | 172 + app/screens/mfa/index.tsx | 222 + app/screens/mfa/mfa.test.tsx | 51 + app/screens/navigation.ts | 69 +- app/screens/server/index.tsx | 438 +- app/screens/sso/index.tsx | 116 + app/screens/sso/sso.test.tsx | 44 + .../sso/sso_with_redirect_url.test.tsx | 50 + app/screens/sso/sso_with_redirect_url.tsx | 182 + app/screens/sso/sso_with_webview.tsx | 247 + app/store/ephemeral_store.ts | 12 - app/utils/database.ts | 58 + app/utils/{font_family.js => font_family.ts} | 5 +- app/utils/general/index.ts | 27 + app/utils/helpers.ts | 74 + packager/modules.ios.js => app/utils/i18n.ts | 4 +- app/utils/key_mirror.ts | 32 +- app/utils/markdown/index.ts | 207 + app/utils/tap/index.ts | 21 + app/utils/tap/test.ts | 49 + app/utils/theme/index.ts | 151 + app/utils/theme/test.ts | 41 + .../deep_linking.ts => utils/time_tracker.ts} | 6 +- app/utils/url/index.ts | 265 + app/utils/url/latin_map.ts | 995 +++ app/utils/url/latinise.ts | 13 + app/utils/url/test.ts | 288 + assets/base/i18n/en.json | 601 +- assets/base/images/google.png | Bin 0 -> 601 bytes assets/base/images/logo.png | Bin 0 -> 32490 bytes babel.config.js | 7 +- index.ts | 79 +- .../DatabaseHelper.xcodeproj/project.pbxproj | 320 + .../xcschemes/DatabaseHelper.xcscheme | 67 + .../DatabaseHelper-Bridging-Header.h | 12 + .../DatabaseHelper/DatabaseHelper.swift | 82 + ios/Mattermost.xcodeproj/project.pbxproj | 75 + .../xcschemes/Mattermost.xcscheme | 16 +- .../xcschemes/MattermostShare.xcscheme | 23 +- .../xcschemes/NotificationService.xcscheme | 46 +- ios/Mattermost/AppDelegate.m | 29 +- ios/Mattermost/Info.plist | 1 + ...tificationEventHandler+HandleReplyAction.m | 20 +- ios/Mattermost/SwimeProxy.swift | 3 +- ios/MattermostShare/ShareViewController.swift | 56 +- .../NotificationService.swift | 10 +- ios/Podfile.lock | 12 +- .../project.pbxproj | 5 + .../xcschemes/UploadAttachments.xcscheme | 4 - .../UploadAttachments/AttachmentItem.swift | 2 +- .../UploadAttachments/StoreManager.h | 3 +- .../UploadAttachments/StoreManager.m | 25 +- .../UploadAttachments/UploadManager.swift | 11 +- .../UploadAttachments/UploadSession.swift | 80 +- .../UploadSessionManager.swift | 21 +- jest.config.js | 20 +- metro.config.js | 48 +- package-lock.json | 285 +- package.json | 16 +- packager/generateModulePaths.js | 46 - patches/react-native-button+3.0.1.patch | 28 + patches/rn-fetch-blob+0.12.0.patch | 7792 +++++++++++++++++ test/intl-test-helper.tsx | 25 + test/setup.ts | 276 +- test/test_helper.js | 477 + tsconfig.json | 9 +- types/api/apps.d.ts | 211 + types/api/bots.d.ts | 20 + types/api/channels.d.ts | 106 + types/api/client4.d.ts | 35 + types/api/config.d.ts | 3 + types/api/emojis.d.ts | 41 + types/api/error.d.ts | 9 + types/api/files.d.ts | 33 + types/api/groups.d.ts | 69 + types/api/integrations.d.ts | 87 + types/api/license.d.ts | 33 + types/api/posts.d.ts | 113 + types/api/preferences.d.ts | 2 +- types/api/reactions.d.ts | 9 + types/api/roles.d.ts | 17 + types/api/teams.d.ts | 55 + types/api/users.d.ts | 80 + types/credentials/index.d.ts | 7 + types/database/config.ts | 170 + types/database/database.d.ts | 41 +- types/database/global.d.ts | 2 +- types/database/index.d.ts | 4 +- types/database/license.ts | 33 + types/global/global_event_handler.d.ts | 10 - types/global/preferences.d.ts | 29 - types/global/push_notifications.d.ts | 1 + types/global/utilities.d.ts | 29 +- types/launch/index.ts | 52 + .../modules/mock-async-storage.d.ts | 2 +- types/screens/gallery.d.ts | 3 - types/utils/index.d.ts | 4 + 207 files changed, 22050 insertions(+), 2252 deletions(-) create mode 100644 android/app/src/main/java/com/mattermost/helpers/DatabaseHelper.java create mode 100644 app/client/rest/apps.ts create mode 100644 app/client/rest/base.ts create mode 100644 app/client/rest/bots.ts create mode 100644 app/client/rest/channels.ts create mode 100644 app/client/rest/constants.ts create mode 100644 app/client/rest/emojis.ts create mode 100644 app/client/rest/error.ts create mode 100644 app/client/rest/files.ts create mode 100644 app/client/rest/general.ts create mode 100644 app/client/rest/groups.ts create mode 100644 app/client/rest/index.test.js create mode 100644 app/client/rest/index.ts create mode 100644 app/client/rest/integrations.ts create mode 100644 app/client/rest/posts.ts create mode 100644 app/client/rest/preferences.ts create mode 100644 app/client/rest/teams.ts create mode 100644 app/client/rest/tos.ts create mode 100644 app/client/rest/users.ts create mode 100644 app/client/websocket/index.ts create mode 100644 app/components/app_version/index.tsx create mode 100644 app/components/error_text/__snapshots__/error_text.test.tsx.snap create mode 100644 app/components/error_text/error_text.test.tsx create mode 100644 app/components/error_text/index.tsx create mode 100644 app/components/formatted_text/index.tsx create mode 100644 app/components/loading/index.tsx create mode 100644 app/components/loading/loading.stories.tsx create mode 100644 app/constants/files.ts create mode 100644 app/constants/general.ts create mode 100644 app/constants/sso.ts delete mode 100644 app/init/emm_provider.ts create mode 100644 app/init/fetch.js create mode 100644 app/init/launch.ts create mode 100644 app/init/managed_app.ts delete mode 100644 app/mattermost.ts create mode 100644 app/queries/global.ts create mode 100644 app/queries/role.ts create mode 100644 app/queries/system.ts create mode 100644 app/queries/user.ts create mode 100644 app/requests/local/systems.ts create mode 100644 app/requests/local/timezone.ts create mode 100644 app/requests/remote/error.ts create mode 100644 app/requests/remote/general.ts create mode 100644 app/requests/remote/push_notification.ts create mode 100644 app/requests/remote/role.ts create mode 100644 app/requests/remote/systems.ts create mode 100644 app/requests/remote/user.ts create mode 100644 app/screens/forgot_password/__snapshots__/forgot_password.test.tsx.snap create mode 100644 app/screens/forgot_password/forgot_password.test.tsx create mode 100644 app/screens/forgot_password/index.tsx rename app/screens/{index.ts => index.tsx} (82%) create mode 100644 app/screens/login/__snapshots__/login.test.tsx.snap create mode 100644 app/screens/login/index.tsx create mode 100644 app/screens/login/login.test.tsx create mode 100644 app/screens/login_options/email.tsx create mode 100644 app/screens/login_options/gitlab.tsx create mode 100644 app/screens/login_options/google.tsx create mode 100644 app/screens/login_options/index.tsx create mode 100644 app/screens/login_options/ldap.tsx create mode 100644 app/screens/login_options/office365.tsx create mode 100644 app/screens/login_options/open_id.tsx create mode 100644 app/screens/login_options/saml.tsx create mode 100644 app/screens/login_options/types.d.ts create mode 100644 app/screens/mfa/__snapshots__/mfa.test.tsx.snap create mode 100644 app/screens/mfa/index.tsx create mode 100644 app/screens/mfa/mfa.test.tsx create mode 100644 app/screens/sso/index.tsx create mode 100644 app/screens/sso/sso.test.tsx create mode 100644 app/screens/sso/sso_with_redirect_url.test.tsx create mode 100644 app/screens/sso/sso_with_redirect_url.tsx create mode 100644 app/screens/sso/sso_with_webview.tsx create mode 100644 app/utils/database.ts rename app/utils/{font_family.js => font_family.ts} (84%) create mode 100644 app/utils/general/index.ts create mode 100644 app/utils/helpers.ts rename packager/modules.ios.js => app/utils/i18n.ts (70%) create mode 100644 app/utils/markdown/index.ts create mode 100644 app/utils/tap/index.ts create mode 100644 app/utils/tap/test.ts create mode 100644 app/utils/theme/index.ts create mode 100644 app/utils/theme/test.ts rename app/{constants/deep_linking.ts => utils/time_tracker.ts} (64%) create mode 100644 app/utils/url/index.ts create mode 100644 app/utils/url/latin_map.ts create mode 100644 app/utils/url/latinise.ts create mode 100644 app/utils/url/test.ts create mode 100644 assets/base/images/google.png create mode 100755 assets/base/images/logo.png create mode 100644 ios/DatabaseHelper/DatabaseHelper.xcodeproj/project.pbxproj create mode 100644 ios/DatabaseHelper/DatabaseHelper.xcodeproj/xcshareddata/xcschemes/DatabaseHelper.xcscheme create mode 100644 ios/DatabaseHelper/DatabaseHelper/DatabaseHelper-Bridging-Header.h create mode 100644 ios/DatabaseHelper/DatabaseHelper/DatabaseHelper.swift delete mode 100644 packager/generateModulePaths.js create mode 100644 patches/react-native-button+3.0.1.patch create mode 100644 patches/rn-fetch-blob+0.12.0.patch create mode 100644 test/intl-test-helper.tsx create mode 100644 test/test_helper.js create mode 100644 types/api/apps.d.ts create mode 100644 types/api/bots.d.ts create mode 100644 types/api/channels.d.ts create mode 100644 types/api/client4.d.ts create mode 100644 types/api/emojis.d.ts create mode 100644 types/api/error.d.ts create mode 100644 types/api/files.d.ts create mode 100644 types/api/groups.d.ts create mode 100644 types/api/integrations.d.ts create mode 100644 types/api/license.d.ts create mode 100644 types/api/posts.d.ts create mode 100644 types/api/reactions.d.ts create mode 100644 types/api/roles.d.ts create mode 100644 types/api/teams.d.ts create mode 100644 types/api/users.d.ts create mode 100644 types/credentials/index.d.ts create mode 100644 types/database/config.ts create mode 100644 types/database/license.ts delete mode 100644 types/global/global_event_handler.d.ts create mode 100644 types/launch/index.ts rename packager/moduleNames.js => types/modules/mock-async-storage.d.ts (75%) diff --git a/.editorconfig b/.editorconfig index be3c34776..8496df79f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,7 +7,7 @@ end_of_line = lf insert_final_newline = true charset = utf-8 -[*.{js,jsx,json,html}] +[*.{js,jsx,json,html,ts,tsx}] indent_style = space indent_size = 4 diff --git a/.eslintrc.json b/.eslintrc.json index b7d9dbed4..191b60b9a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,7 +2,8 @@ "extends": [ "plugin:mattermost/react", "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended" + "plugin:@typescript-eslint/recommended", + "plugin:react-hooks/recommended" ], "parser": "@typescript-eslint/parser", "plugins": [ diff --git a/.gitignore b/.gitignore index 8871c6170..7be23d51e 100644 --- a/.gitignore +++ b/.gitignore @@ -101,3 +101,4 @@ detox/artifacts #editor-settings .vscode +.scannerwork diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 2bcc4148f..8e49c43b2 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + @@ -44,17 +43,16 @@ + + + + + + - - - + + + keys = new ArrayList(1); - keys.add(CURRENT_SERVER_URL); - KeysReadableArray asyncStorageKeys = new KeysReadableArray() { - @Override - public int size() { - return keys.size(); - } - @Override - public String getString(int index) { - return keys.get(index); - } - }; - - HashMap asyncStorageResults = asyncStorage.multiGet(asyncStorageKeys); - String serverUrl = asyncStorageResults.get(CURRENT_SERVER_URL); final WritableMap options = Arguments.createMap(); // KeyChain module fails if `authenticationPrompt` is not set final WritableMap authPrompt = Arguments.createMap(); diff --git a/android/app/src/main/java/com/mattermost/helpers/DatabaseHelper.java b/android/app/src/main/java/com/mattermost/helpers/DatabaseHelper.java new file mode 100644 index 000000000..cf3b07338 --- /dev/null +++ b/android/app/src/main/java/com/mattermost/helpers/DatabaseHelper.java @@ -0,0 +1,34 @@ +package com.mattermost.helpers; + +import android.content.Context; +import android.database.Cursor; +import android.net.Uri; + +import com.nozbe.watermelondb.Database; + +public class DatabaseHelper { + private static final String DEFAULT_DATABASE_NAME = "default.db"; + private static Database defaultDatabase; + + private static void setDefaultDatabase(Context context) { + String databaseName = Uri.fromFile(context.getFilesDir()).toString() + "/" + DEFAULT_DATABASE_NAME; + defaultDatabase = new Database(databaseName, context); + } + + public static String getOnlyServerUrl(Context context) { + if (defaultDatabase == null) { + setDefaultDatabase(context); + } + + String emptyArray[] = {}; + String query = "SELECT url FROM servers"; + Cursor cursor = defaultDatabase.rawQuery(query, emptyArray); + + if (cursor.getCount() == 1) { + cursor.moveToFirst(); + return cursor.getString(0); + } + + return null; + } +} diff --git a/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.java b/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.java index f5b713096..ebe9cc987 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.java +++ b/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.java @@ -27,6 +27,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.mattermost.helpers.DatabaseHelper; +import com.mattermost.helpers.ResolvePromise; import com.wix.reactnativenotifications.core.notification.PushNotification; import com.wix.reactnativenotifications.core.NotificationIntentAdapter; import com.wix.reactnativenotifications.core.AppLaunchHelper; @@ -35,11 +37,10 @@ import com.wix.reactnativenotifications.core.JsIOHelper; import static com.wix.reactnativenotifications.Defs.NOTIFICATION_RECEIVED_EVENT_NAME; -import com.mattermost.helpers.ResolvePromise; - public class CustomPushNotification extends PushNotification { public static final int MESSAGE_NOTIFICATION_ID = 435345; public static final String GROUP_KEY_MESSAGES = "mm_group_key_messages"; + public static final String NOTIFICATION = "notification"; public static final String NOTIFICATION_ID = "notificationId"; public static final String KEY_TEXT_REPLY = "CAN_REPLY"; public static final String NOTIFICATION_REPLIED_EVENT_NAME = "notificationReplied"; @@ -61,6 +62,7 @@ public class CustomPushNotification extends PushNotification { public CustomPushNotification(Context context, Bundle bundle, AppLifecycleFacade appLifecycleFacade, AppLaunchHelper appLaunchHelper, JsIOHelper jsIoHelper) { super(context, bundle, appLifecycleFacade, appLaunchHelper, jsIoHelper); this.context = context; + createNotificationChannels(); } @@ -106,8 +108,10 @@ public class CustomPushNotification extends PushNotification { final boolean isIdLoaded = initialData.getString("id_loaded") != null ? initialData.getString("id_loaded").equals("true") : false; int notificationId = MESSAGE_NOTIFICATION_ID; - if (ackId != null) { - notificationReceiptDelivery(ackId, postId, type, isIdLoaded, new ResolvePromise() { + String serverUrl = initialData.getString("server_url", DatabaseHelper.getOnlyServerUrl(context)); + + if (ackId != null && serverUrl != null) { + notificationReceiptDelivery(ackId, serverUrl, postId, type, isIdLoaded, new ResolvePromise() { @Override public void resolve(@Nullable Object value) { if (isIdLoaded) { @@ -127,6 +131,11 @@ public class CustomPushNotification extends PushNotification { // so we fetch the bundle again final Bundle data = mNotificationProps.asBundle(); + if (serverUrl == null) { + String message = data.getString("message"); + data.putString("message", "Unknown Server\n" + message); + } + if (channelId != null) { notificationId = channelId.hashCode(); @@ -465,15 +474,18 @@ public class CustomPushNotification extends PushNotification { private void addNotificationReplyAction(Notification.Builder notification, int notificationId, Bundle bundle) { String postId = bundle.getString("post_id"); + String serverUrl = bundle.getString("server_url", DatabaseHelper.getOnlyServerUrl(context)); - if (android.text.TextUtils.isEmpty(postId) || Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { + if (android.text.TextUtils.isEmpty(postId) || + serverUrl == null || + Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { return; } Intent replyIntent = new Intent(mContext, NotificationReplyBroadcastReceiver.class); replyIntent.setAction(KEY_TEXT_REPLY); replyIntent.putExtra(NOTIFICATION_ID, notificationId); - replyIntent.putExtra("pushNotification", bundle); + replyIntent.putExtra(NOTIFICATION, bundle); PendingIntent replyPendingIntent = PendingIntent.getBroadcast( mContext, @@ -540,8 +552,8 @@ public class CustomPushNotification extends PushNotification { return message.replaceFirst(": ", "").trim(); } - private void notificationReceiptDelivery(String ackId, String postId, String type, boolean isIdLoaded, ResolvePromise promise) { - ReceiptDelivery.send(context, ackId, postId, type, isIdLoaded, promise); + private void notificationReceiptDelivery(String ackId, String serverUrl, String postId, String type, boolean isIdLoaded, ResolvePromise promise) { + ReceiptDelivery.send(context, ackId, serverUrl, postId, type, isIdLoaded, promise); } private void createNotificationChannels() { diff --git a/android/app/src/main/java/com/mattermost/rnbeta/MainApplication.java b/android/app/src/main/java/com/mattermost/rnbeta/MainApplication.java index 6452d4c02..fc2884bd8 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/MainApplication.java +++ b/android/app/src/main/java/com/mattermost/rnbeta/MainApplication.java @@ -46,7 +46,6 @@ import com.facebook.soloader.SoLoader; import org.unimodules.adapters.react.ModuleRegistryAdapter; import org.unimodules.adapters.react.ReactModuleRegistryProvider; -import org.unimodules.core.interfaces.SingletonModule; import com.swmansion.reanimated.ReanimatedJSIModulePackage; diff --git a/android/app/src/main/java/com/mattermost/rnbeta/NotificationReplyBroadcastReceiver.java b/android/app/src/main/java/com/mattermost/rnbeta/NotificationReplyBroadcastReceiver.java index f630fb4af..e81e46622 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/NotificationReplyBroadcastReceiver.java +++ b/android/app/src/main/java/com/mattermost/rnbeta/NotificationReplyBroadcastReceiver.java @@ -48,9 +48,11 @@ public class NotificationReplyBroadcastReceiver extends BroadcastReceiver { final ReactApplicationContext reactApplicationContext = new ReactApplicationContext(context); final int notificationId = intent.getIntExtra(CustomPushNotification.NOTIFICATION_ID, -1); + final Bundle notification = intent.getBundleExtra(CustomPushNotification.NOTIFICATION); + final String serverUrl = notification.getString("serverUrl"); - Credentials.getCredentialsForCurrentServer(reactApplicationContext, new ResolvePromise() { + Credentials.getCredentialsForServer(reactApplicationContext, serverUrl, new ResolvePromise() { @Override public void resolve(@Nullable Object value) { if (value instanceof Boolean && !(Boolean)value) { diff --git a/android/app/src/main/java/com/mattermost/rnbeta/ReceiptDelivery.java b/android/app/src/main/java/com/mattermost/rnbeta/ReceiptDelivery.java index 2e8ab101a..256d81fa2 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/ReceiptDelivery.java +++ b/android/app/src/main/java/com/mattermost/rnbeta/ReceiptDelivery.java @@ -22,14 +22,12 @@ import com.facebook.react.bridge.WritableMap; import com.mattermost.helpers.*; public class ReceiptDelivery { - static final String CURRENT_SERVER_URL = "@currentServerUrl"; - private static final int[] FIBONACCI_BACKOFFS = new int[] { 0, 1, 2, 3, 5, 8 }; - public static void send(Context context, final String ackId, final String postId, final String type, final boolean isIdLoaded, ResolvePromise promise) { + public static void send(Context context, final String ackId, final String serverUrl, final String postId, final String type, final boolean isIdLoaded, ResolvePromise promise) { final ReactApplicationContext reactApplicationContext = new ReactApplicationContext(context); - Credentials.getCredentialsForCurrentServer(reactApplicationContext, new ResolvePromise() { + Credentials.getCredentialsForServer(reactApplicationContext, serverUrl, new ResolvePromise() { @Override public void resolve(@Nullable Object value) { if (value instanceof Boolean && !(Boolean)value) { diff --git a/android/app/src/main/res/values/styles.xml b/android/app/src/main/res/values/styles.xml index 140b05030..166843b94 100644 --- a/android/app/src/main/res/values/styles.xml +++ b/android/app/src/main/res/values/styles.xml @@ -1,10 +1,7 @@ -