From f8b87ab71d7c252a3a7ae3c5d96d09d73b349f28 Mon Sep 17 00:00:00 2001 From: Eero Ruohola Date: Sun, 11 Apr 2021 17:39:18 +0300 Subject: [PATCH] Add support for having multiple registered FCM devices for a user --- __generated__/src/graphql/common.graphql.tsx | 8 ++++---- cypress/fixtures/userMe.json | 2 +- src/context/auth.tsx | 6 +++--- src/graphql/common.graphql | 2 +- src/graphql/common.graphql.d.ts | 6 +++--- src/hocs/withUserMe.tsx | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/__generated__/src/graphql/common.graphql.tsx b/__generated__/src/graphql/common.graphql.tsx index ab14998bb..3b608d628 100644 --- a/__generated__/src/graphql/common.graphql.tsx +++ b/__generated__/src/graphql/common.graphql.tsx @@ -1,4 +1,4 @@ -/* da882a947048069baa3b360345f35376f463fd53 +/* 27e6bf64aeb0aeadb9f56a1015f354733dfd6b81 * This file is automatically generated by graphql-let. */ import { gql } from '@apollo/client'; @@ -237,7 +237,7 @@ export type UserObjectType = { rank?: Maybe; badges?: Maybe>>; unreadActivityCount?: Maybe; - fcmToken?: Maybe; + fcmTokens?: Maybe>; }; /** @@ -1462,7 +1462,7 @@ export type BadgeProgressFieldsFragment = ( export type UserFieldsFragment = ( { __typename?: 'UserObjectType' } - & Pick + & Pick & { badges?: Maybe { const unreadActivityCount = R.propOr(0, 'unreadActivityCount', userMe); const id = R.prop('id', userMe); const slug = R.prop('slug', userMe); - const fcmToken = R.prop('fcmToken', userMe); + const fcmTokens = R.prop('fcmTokens', userMe); const username = R.prop('username', userMe); const email = R.prop('email', userMe); const backupEmail = R.prop('backupEmail', userMe); @@ -77,7 +77,7 @@ export const useAuthContext = (): UseAuthContext => { verified, verifiedBackupEmail, unreadActivityCount, - fcmToken, + fcmTokens, username, email, backupEmail, diff --git a/src/graphql/common.graphql b/src/graphql/common.graphql index 651bc899a..274c60a03 100644 --- a/src/graphql/common.graphql +++ b/src/graphql/common.graphql @@ -264,7 +264,7 @@ fragment userFields on UserObjectType { commentCount created modified - fcmToken + fcmTokens commentReplyEmailPermission threadCommentEmailPermission newBadgeEmailPermission diff --git a/src/graphql/common.graphql.d.ts b/src/graphql/common.graphql.d.ts index 4c870f5d4..3cb6121ad 100644 --- a/src/graphql/common.graphql.d.ts +++ b/src/graphql/common.graphql.d.ts @@ -1,4 +1,4 @@ -/* da882a947048069baa3b360345f35376f463fd53 +/* 27e6bf64aeb0aeadb9f56a1015f354733dfd6b81 * This file is automatically generated by graphql-let. */ import * as Apollo from '@apollo/client'; @@ -226,7 +226,7 @@ export declare type UserObjectType = { rank?: Maybe; badges?: Maybe>>; unreadActivityCount?: Maybe; - fcmToken?: Maybe; + fcmTokens?: Maybe>; }; /** * Models the progress of a user's single badge. @@ -1296,7 +1296,7 @@ export declare type BadgeProgressFieldsFragment = ({ }); export declare type UserFieldsFragment = ({ __typename?: 'UserObjectType'; -} & Pick & { +} & Pick & { badges?: Maybe>>; diff --git a/src/hocs/withUserMe.tsx b/src/hocs/withUserMe.tsx index e44f24a61..3718f1f18 100644 --- a/src/hocs/withUserMe.tsx +++ b/src/hocs/withUserMe.tsx @@ -14,7 +14,7 @@ export const withUserMe = >( ): NextPage => { const WithUserMe: NextPage = (pageProps: T) => { const { authLoading, authNetworkError } = useUserMe(); - const { fcmToken } = useAuthContext(); + const { fcmTokens } = useAuthContext(); const context = useLanguageHeaderContext(); const [registerFcmToken] = useRegisterFcmTokenMutation({ context }); const [markSingleActivityRead] = useMarkActivityAsReadMutation({ context }); @@ -35,7 +35,7 @@ export const withUserMe = >( case 'REGISTER_FCM_TOKEN': { const { token } = json; - if (token !== fcmToken) { + if (!!fcmTokens && !fcmTokens.includes(token)) { await registerFcmToken({ variables: { token } }); } @@ -77,7 +77,7 @@ export const withUserMe = >( } } }, - [fcmToken, registerFcmToken, markSingleActivityRead], + [fcmTokens, registerFcmToken, markSingleActivityRead], ); useEffect(() => {