From 4027e2f329dc9a1e98d6556839a7797631b850d6 Mon Sep 17 00:00:00 2001 From: Tiago Savioli Date: Wed, 13 Nov 2024 02:58:16 -0300 Subject: [PATCH 01/14] fix: remove firebasepushToken unused const + add types verification #34 --- src/contexts/Persisted/persistedAccount.ts | 89 ++++++++++++---------- src/contexts/Persisted/types.ts | 1 - 2 files changed, 49 insertions(+), 41 deletions(-) diff --git a/src/contexts/Persisted/persistedAccount.ts b/src/contexts/Persisted/persistedAccount.ts index c58b765..2db81f1 100644 --- a/src/contexts/Persisted/persistedAccount.ts +++ b/src/contexts/Persisted/persistedAccount.ts @@ -5,7 +5,6 @@ const storageKey = storageKeys().account export interface AccountState extends AccountDataType { setUnreadNotificationsCount: (value: number) => void - setFirebasePushToken: (value: string) => void setJwtToken: (value: string) => void setJwtExpiration: (value: string) => void setBlocked: (value: boolean) => void @@ -19,7 +18,6 @@ export interface AccountState extends AccountDataType { export const useAccountStore = create((set) => ({ unreadNotificationsCount: storage.getNumber(storageKey.unreadNotificationsCount) || 0, - firebasePushToken: storage.getString(storageKey.firebasePushToken) || "", jwtToken: storage.getString(storageKey.jwt.token) || "", jwtExpiration: storage.getString(storageKey.jwt.expiration) || "", blocked: storage.getBoolean(storageKey.blocked) || false, @@ -28,65 +26,78 @@ export const useAccountStore = create((set) => ({ last_login_at: storage.getString(storageKey.last_login_at) || new Date().toString(), setUnreadNotificationsCount: (value: number) => { - storage.set(storageKey.unreadNotificationsCount, Number(value)) - set({ unreadNotificationsCount: value }) - }, - - setFirebasePushToken: (value: string) => { - storage.set(storageKey.firebasePushToken, value.toString()) - set({ firebasePushToken: value }) + if (typeof value === "number") { + storage.set(storageKey.unreadNotificationsCount, value) + set({ unreadNotificationsCount: value }) + } }, setJwtToken: (value: string) => { - if (value) storage.set(storageKey.jwt.token, value) - set({ jwtToken: value }) + if (typeof value === "string") { + storage.set(storageKey.jwt.token, value) + set({ jwtToken: value }) + } }, setJwtExpiration: (value: string) => { - if (value) storage.set(storageKey.jwt.expiration, value) - set({ jwtExpiration: value }) + if (typeof value === "string") { + storage.set(storageKey.jwt.expiration, value) + set({ jwtExpiration: value }) + } }, setBlocked: (value: boolean) => { - storage.set(storageKey.blocked, value) - set({ blocked: value }) + if (typeof value === "boolean") { + storage.set(storageKey.blocked, value) + set({ blocked: value }) + } }, + setMuted: (value: boolean) => { - storage.set(storageKey.muted, value) - set({ muted: value }) + if (typeof value === "boolean") { + storage.set(storageKey.muted, value) + set({ muted: value }) + } }, + setLastActiveAt: (value: string) => { - storage.set(storageKey.last_active_at, value) - set({ last_active_at: value }) + if (typeof value === "string") { + storage.set(storageKey.last_active_at, value) + set({ last_active_at: value }) + } }, + setLastLoginAt: (value: string) => { - storage.set(storageKey.last_login_at, value) - set({ last_login_at: value }) + if (typeof value === "string") { + storage.set(storageKey.last_login_at, value) + set({ last_login_at: value }) + } }, + set: (value: AccountDataType) => { set({ - unreadNotificationsCount: 0, - firebasePushToken: value.firebasePushToken, - blocked: value.blocked, - muted: value.muted, - last_active_at: value.last_active_at, - last_login_at: value.last_login_at, - jwtToken: value.jwtToken, - jwtExpiration: value.jwtExpiration, + unreadNotificationsCount: value.unreadNotificationsCount || 0, + blocked: value.blocked || false, + muted: value.muted || false, + last_active_at: value.last_active_at || new Date().toString(), + last_login_at: value.last_login_at || new Date().toString(), + jwtToken: value.jwtToken || "", + jwtExpiration: value.jwtExpiration || "", }) - storage.set(storageKey.unreadNotificationsCount, 0) - storage.set(storageKey.firebasePushToken, value.firebasePushToken.toString()) - storage.set(storageKey.blocked, value.blocked) - storage.set(storageKey.jwt.token, value.jwtToken) - storage.set(storageKey.jwt.expiration, value.jwtExpiration) - storage.set(storageKey.muted, value.blocked) - storage.set(storageKey.last_active_at, value.last_active_at) - storage.set(storageKey.last_login_at, value.last_login_at) + + /** + + storage.set(storageKey.unreadNotificationsCount, value.unreadNotificationsCount || 0) + storage.set(storageKey.blocked, value.blocked || false) + storage.set(storageKey.muted, value.muted || false) + storage.set(storageKey.jwt.token, value.jwtToken || "") + storage.set(storageKey.jwt.expiration, value.jwtExpiration || "") + storage.set(storageKey.last_active_at, value.last_active_at || new Date().toString()) + storage.set(storageKey.last_login_at, value.last_login_at || new Date().toString())*/ }, load: () => { set({ unreadNotificationsCount: storage.getNumber(storageKey.unreadNotificationsCount) || 0, - firebasePushToken: storage.getString(storageKey.firebasePushToken) || "", blocked: storage.getBoolean(storageKey.blocked) || false, muted: storage.getBoolean(storageKey.muted) || false, jwtToken: storage.getString(storageKey.jwt.token) || "", @@ -97,7 +108,6 @@ export const useAccountStore = create((set) => ({ }, remove: () => { storage.delete(storageKey.unreadNotificationsCount) - storage.delete(storageKey.firebasePushToken) storage.delete(storageKey.blocked) storage.delete(storageKey.muted) storage.delete(storageKey.jwt.token) @@ -107,7 +117,6 @@ export const useAccountStore = create((set) => ({ set({ unreadNotificationsCount: 0, - firebasePushToken: "", blocked: false, muted: false, jwtToken: "", diff --git a/src/contexts/Persisted/types.ts b/src/contexts/Persisted/types.ts index 49d7d1b..3a47b8c 100644 --- a/src/contexts/Persisted/types.ts +++ b/src/contexts/Persisted/types.ts @@ -58,7 +58,6 @@ export type AccountDataType = { muted: boolean last_active_at: string last_login_at: string - firebasePushToken: string jwtToken: string jwtExpiration: string } From 0303f088dcd6839f57263049385650634d95d062 Mon Sep 17 00:00:00 2001 From: Tiago Savioli Date: Wed, 13 Nov 2024 03:00:15 -0300 Subject: [PATCH 02/14] add: useEffect set isValidPassword to false #35 --- src/components/auth/password_input.tsx | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/components/auth/password_input.tsx b/src/components/auth/password_input.tsx index e5209d1..ddad27d 100644 --- a/src/components/auth/password_input.tsx +++ b/src/components/auth/password_input.tsx @@ -1,16 +1,15 @@ -import React, { useState, useEffect } from "react" +import React, { useState } from "react" import { Pressable, TextInput, useColorScheme } from "react-native" -import ColorTheme, { colors } from "../../layout/constants/colors" -import fonts from "../../layout/constants/fonts" -import Icon from "../../assets/icons/svgs/lock.svg" -import { Text, View } from "../Themed" import CheckIcon from "../../assets/icons/svgs/check_circle.svg" import XIcon from "../../assets/icons/svgs/close.svg" import Eye from "../../assets/icons/svgs/eye.svg" import EyeSlash from "../../assets/icons/svgs/eye_slash.svg" -import sizes from "../../layout/constants/sizes" -import api from "../../services/Api" +import Icon from "../../assets/icons/svgs/lock.svg" import AuthContext from "../../contexts/auth" +import ColorTheme, { colors } from "../../layout/constants/colors" +import fonts from "../../layout/constants/fonts" +import sizes from "../../layout/constants/sizes" +import { Text, View } from "../Themed" export default function PasswordInput({ sign = true }: { sign?: boolean }) { const isDarkMode = useColorScheme() === "dark" @@ -18,7 +17,7 @@ export default function PasswordInput({ sign = true }: { sign?: boolean }) { const [password, setPassword] = useState("") const [showStatusMessage, setShowStatusMessage] = useState(false) const [statusMessage, setStatusMessage] = useState("") - const [isValidPassword, setIsValidPassword] = useState(true) + const [isValidPassword, setIsValidPassword] = useState(false) const [isVisible, setIsVisible] = useState(false) const inputRef = React.useRef(null) @@ -147,6 +146,15 @@ export default function PasswordInput({ sign = true }: { sign?: boolean }) { } }, [password, inputRef]) + React.useEffect(() => { + if (password.length <= 5) { + setIsValidPassword(false) + setStatusMessage("The Password needs least 6 characters.") + setShowStatusMessage(true) + setSignInputPassword("") + } + }) + return ( From 521b76764a627c0d56c47adea9224347b157593c Mon Sep 17 00:00:00 2001 From: Tiago Savioli Date: Wed, 13 Nov 2024 03:03:24 -0300 Subject: [PATCH 03/14] fix(android): change version name to 1.0.3 + version code to 4 #36 --- android/app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 182fcc0..042a5ff 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -83,8 +83,8 @@ android { applicationId "com.circlecompany.circleapp" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion - versionCode 3 - versionName "1.0.2" + versionCode 4 + versionName "1.0.3" } signingConfigs { release { From 87babdfa4f0288f8824e65662eefd79d6bfd03c6 Mon Sep 17 00:00:00 2001 From: Tiago Savioli Date: Wed, 13 Nov 2024 03:04:42 -0300 Subject: [PATCH 04/14] fix: remove type error using any --- src/features/list-notifications/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/list-notifications/index.tsx b/src/features/list-notifications/index.tsx index 229b443..a296767 100644 --- a/src/features/list-notifications/index.tsx +++ b/src/features/list-notifications/index.tsx @@ -15,7 +15,7 @@ import { ListNotificationsSkeleton } from "./skeleton" export default function ListNotifcations() { const { t } = React.useContext(LanguageContext) const { session } = React.useContext(PersistedContext) - const [notificationsData, setNotificationsData] = React.useState([]) + const [notificationsData, setNotificationsData]: any = React.useState([]) const [page, setPage] = React.useState(1) const [pageSize, setPageSize] = React.useState(6) From 7e8eb0aaa6a5808416347e33e38049e20022b07d Mon Sep 17 00:00:00 2001 From: Tiago Savioli Date: Wed, 13 Nov 2024 03:05:05 -0300 Subject: [PATCH 05/14] fix: remove firebasePushToken storage key --- src/store/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/store/index.ts b/src/store/index.ts index c5d3bc0..7583a31 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -12,7 +12,6 @@ export function storageKeys() { }, account: { unreadNotificationsCount: baseKey + "account:unreadnotificationscount", - firebasePushToken: baseKey + "account:firebasepushtoken", blocked: baseKey + "account:block", muted: baseKey + "account:mute", last_active_at: baseKey + "account:lastactive", From 8629ff5052844ad12df36f9b8c1a760d73c60c61 Mon Sep 17 00:00:00 2001 From: Tiago Savioli Date: Wed, 13 Nov 2024 03:05:55 -0300 Subject: [PATCH 06/14] fix: get authorization token directly from session --- src/services/Api/routes/moment/index.ts | 33 ++++++++++++------------- src/services/Api/routes/moment/types.ts | 3 +++ src/state/queries/follow.ts | 1 + 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/services/Api/routes/moment/index.ts b/src/services/Api/routes/moment/index.ts index 4a00739..262aff6 100644 --- a/src/services/Api/routes/moment/index.ts +++ b/src/services/Api/routes/moment/index.ts @@ -1,94 +1,93 @@ import api from "../.." -import { storage, storageKeys } from "../../../../store" import { PostLikeProps, PostStatisticsPreviewProps, PostUnlikeProps } from "./types" -async function like({ momentId }: PostLikeProps): Promise { +async function like({ momentId, authorizationToken }: PostLikeProps): Promise { await api.post( `/moments/${momentId}/like`, {}, { headers: { - authorization_token: storage.getString(storageKeys().account.jwt.token) || "", + authorization_token: authorizationToken, }, } ) } -async function unlike({ momentId }: PostUnlikeProps): Promise { +async function unlike({ momentId, authorizationToken }: PostUnlikeProps): Promise { await api.post( `/moments/${momentId}/unlike`, {}, { headers: { - authorization_token: storage.getString(storageKeys().account.jwt.token) || "", + authorization_token: authorizationToken, }, } ) } -async function view({ momentId }: PostLikeProps): Promise { +async function view({ momentId, authorizationToken }: PostLikeProps): Promise { await api.post( `/moments/${momentId}/view`, {}, { headers: { - authorization_token: storage.getString(storageKeys().account.jwt.token) || "", + authorization_token: authorizationToken, }, } ) } -async function hide({ momentId }: PostLikeProps): Promise { +async function hide({ momentId, authorizationToken }: PostLikeProps): Promise { await api.post( `/moments/${momentId}/hide`, {}, { headers: { - authorization_token: storage.getString(storageKeys().account.jwt.token) || "", + authorization_token: authorizationToken, }, } ) } -async function unhide({ momentId }: PostLikeProps): Promise { +async function unhide({ momentId, authorizationToken }: PostLikeProps): Promise { await api.post( `/moments/${momentId}/unhide`, {}, { headers: { - authorization_token: storage.getString(storageKeys().account.jwt.token) || "", + authorization_token: authorizationToken, }, } ) } -async function deleteMoment({ momentId }: PostLikeProps): Promise { +async function deleteMoment({ momentId, authorizationToken }: PostLikeProps): Promise { await api.post( `/moments/${momentId}/delete`, {}, { headers: { - authorization_token: storage.getString(storageKeys().account.jwt.token) || "", + authorization_token: authorizationToken, }, } ) } -async function undeleteMoment({ momentId }: PostLikeProps): Promise { +async function undeleteMoment({ momentId, authorizationToken }: PostLikeProps): Promise { await api.post( `/moments/${momentId}/undelete`, {}, { headers: { - authorization_token: storage.getString(storageKeys().account.jwt.token) || "", + authorization_token: authorizationToken, }, } ) } -async function statisticsPreview({ momentId }: PostStatisticsPreviewProps) { +async function statisticsPreview({ momentId, authorizationToken }: PostStatisticsPreviewProps) { return await api.get(`/moments/${momentId}/statistics/preview`, { - headers: { authorization_token: storage.getString(storageKeys().account.jwt.token) || "" }, + headers: { authorization_token: authorizationToken }, }) } diff --git a/src/services/Api/routes/moment/types.ts b/src/services/Api/routes/moment/types.ts index 1c1ebb9..14d362a 100644 --- a/src/services/Api/routes/moment/types.ts +++ b/src/services/Api/routes/moment/types.ts @@ -1,11 +1,14 @@ export type PostLikeProps = { momentId: number + authorizationToken: string } export type PostUnlikeProps = { momentId: number + authorizationToken: string } export type PostStatisticsPreviewProps = { momentId: number + authorizationToken: string } diff --git a/src/state/queries/follow.ts b/src/state/queries/follow.ts index dcc17b4..f548a82 100644 --- a/src/state/queries/follow.ts +++ b/src/state/queries/follow.ts @@ -4,6 +4,7 @@ import { apiRoutes } from "../../services/Api" type useFollowMutationProps = { userId: number followedUserId: number + authorizationToken: string } export function useFollowMutation({ followedUserId, userId }: useFollowMutationProps) { From eedaca21d29bacdb5e9412d9f07fc15cfbea13ea Mon Sep 17 00:00:00 2001 From: Tiago Savioli Date: Wed, 13 Nov 2024 03:06:46 -0300 Subject: [PATCH 07/14] fix: prevent loop finding user data --- src/contexts/Persisted/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/contexts/Persisted/index.tsx b/src/contexts/Persisted/index.tsx index a06d771..dc8fb56 100644 --- a/src/contexts/Persisted/index.tsx +++ b/src/contexts/Persisted/index.tsx @@ -67,7 +67,7 @@ export function Provider({ children }: PersistedProviderProps) { } } ) - }, [sessionAccount]) + }, []) React.useEffect(() => { const isSigned = checkIsSigned() From c06b484115b4275cb81cf3c3b44f60b58ab12a78 Mon Sep 17 00:00:00 2001 From: Tiago Savioli Date: Wed, 13 Nov 2024 03:07:23 -0300 Subject: [PATCH 08/14] fix: remove refreshPushToken function --- src/lib/notifications/index.ts | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/lib/notifications/index.ts b/src/lib/notifications/index.ts index 3f39bbb..6d8b0e1 100644 --- a/src/lib/notifications/index.ts +++ b/src/lib/notifications/index.ts @@ -1,15 +1,8 @@ -import React from "react" -import PersistedContext from "../../contexts/Persisted" import { apiRoutes } from "../../services/Api" -async function refreshPushToken(token: string) { - const { session } = React.useContext(PersistedContext) - if (token) session.account.setFirebasePushToken(token) -} - async function registerPushToken({ userId, token }: { userId: number; token: string }) { try { - if (!userId || !token) + if (!userId || (typeof token !== "string" && token !== "")) throw Error("session.user.id or session.account.firebasePushToken have a null value") await apiRoutes.notification.setToken({ userId, @@ -21,6 +14,5 @@ async function registerPushToken({ userId, token }: { userId: number; token: str } export const notification = { - refreshPushToken, registerPushToken, } From 2ad8bcf681268d620c2489895e9dd857d90f411b Mon Sep 17 00:00:00 2001 From: Tiago Savioli Date: Wed, 13 Nov 2024 03:33:56 -0300 Subject: [PATCH 09/14] fix: type error --- src/components/moment/components/moment-container.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/moment/components/moment-container.tsx b/src/components/moment/components/moment-container.tsx index e321121..70e7890 100644 --- a/src/components/moment/components/moment-container.tsx +++ b/src/components/moment/components/moment-container.tsx @@ -20,7 +20,7 @@ export default function Container({ React.useContext(MomentContext) const { session } = React.useContext(PersistedContext) const { commentEnabled, setFocusedMoment } = React.useContext(FeedContext) - const navigation = useNavigation() + const navigation: any = useNavigation() const container: any = { ...momentSize, From 9ba9b08466a7f3ad57830fe5f3d5be5ca292823a Mon Sep 17 00:00:00 2001 From: Tiago Savioli Date: Wed, 13 Nov 2024 03:34:17 -0300 Subject: [PATCH 10/14] add: authorizationToken requirement --- src/state/queries/like.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/state/queries/like.ts b/src/state/queries/like.ts index a175a4d..338235e 100644 --- a/src/state/queries/like.ts +++ b/src/state/queries/like.ts @@ -4,13 +4,15 @@ import { apiRoutes } from "../../services/Api" type useLikeMutationProps = { userId: number momentId: number + authorizationToken: string } -export function useLikeMutation({ momentId, userId }: useLikeMutationProps) { +export function useLikeMutation({ momentId, userId, authorizationToken }: useLikeMutationProps) { const mutation = useMutation({ mutationFn: async () => { await apiRoutes.moment.like({ userId, + authorizationToken, momentId, }) }, @@ -22,11 +24,12 @@ export function useLikeMutation({ momentId, userId }: useLikeMutationProps) { return mutation } -export function useUnlikeMutation({ momentId, userId }: useLikeMutationProps) { +export function useUnlikeMutation({ momentId, userId, authorizationToken }: useLikeMutationProps) { const mutation = useMutation({ mutationFn: async () => { await apiRoutes.moment.unlike({ userId, + authorizationToken, momentId, }) }, From 2c40220e7b62a829829fce2d57bcb2a122ad2e5b Mon Sep 17 00:00:00 2001 From: Tiago Savioli Date: Wed, 13 Nov 2024 03:41:41 -0300 Subject: [PATCH 11/14] fix(moment-like): remove mutations + change urls --- .../moment/components/moment-like.tsx | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/components/moment/components/moment-like.tsx b/src/components/moment/components/moment-like.tsx index 433faea..9a6bc14 100644 --- a/src/components/moment/components/moment-like.tsx +++ b/src/components/moment/components/moment-like.tsx @@ -8,7 +8,7 @@ import ColorTheme, { colors } from "../../../layout/constants/colors" import fonts from "../../../layout/constants/fonts" import sizes from "../../../layout/constants/sizes" import { Vibrate } from "../../../lib/hooks/useHapticFeedback" -import { useLikeMutation, useUnlikeMutation } from "../../../state/queries/like" +import api from "../../../services/Api" import { Text } from "../../Themed" import MomentContext from "../context" import { MomentLikeProps } from "../moment-types" @@ -28,9 +28,6 @@ export default function like({ var animatedScaleIconPressed = React.useRef(new Animated.Value(1)).current var animatedScaleIcon = React.useRef(new Animated.Value(1)).current - const likeMutation = useLikeMutation({ momentId: momentData.id, userId: session.user.id }) - const unlikeMutation = useUnlikeMutation({ momentId: momentData.id, userId: session.user.id }) - React.useEffect(() => { animatedScale.setValue(1) }, []) @@ -104,7 +101,7 @@ export default function like({ const blur_container_likePressed = { backgroundColor: ColorTheme().like, } - const pressable_container = { + const pressable_container: any = { overflow: "hidden", borderRadius: Number([sizes.buttons.width / 4]) / 2, } @@ -127,13 +124,29 @@ export default function like({ Vibrate("effectClick") HandleButtonAnimation() momentUserActions.handleLikeButtonPressed({ likedValue: true }) - likeMutation.mutate() + await api.post( + `/moments/${momentData.id}/like`, + {}, + { + headers: { + authorization_token: session.account.jwtToken, + }, + } + ) } async function onUnlikeAction() { Vibrate("effectTick") HandleButtonAnimation() momentUserActions.handleLikeButtonPressed({ likedValue: false }) - unlikeMutation.mutate() + await api.post( + `/moments/${momentData.id}/unlike`, + {}, + { + headers: { + authorization_token: session.account.jwtToken, + }, + } + ) } const like_fill: string = String(colors.gray.white) From 06713603725358cd67004e494fb5c270a45bae24 Mon Sep 17 00:00:00 2001 From: Tiago Savioli Date: Wed, 13 Nov 2024 03:41:59 -0300 Subject: [PATCH 12/14] fix: notification --- src/contexts/notification.tsx | 59 +++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/src/contexts/notification.tsx b/src/contexts/notification.tsx index 4d4ec6e..5fe1420 100644 --- a/src/contexts/notification.tsx +++ b/src/contexts/notification.tsx @@ -16,45 +16,56 @@ const NotificationContext = React.createContext( export function Provider({ children }: NotificationProviderProps) { const { session } = React.useContext(PersistedContext) - React.useEffect(() => { - async function requestUserPermission() { + const [enableRequestToken, setEnableRequestToken] = React.useState(false) + + async function requestUserPermission() { + console.log("requestUserPermission") + if (session.user.id && session.account.jwtToken) { useRequestPermission.postNotifications() const status: number = await messaging().requestPermission() const enabled = status === messaging.AuthorizationStatus.AUTHORIZED || status === messaging.AuthorizationStatus.PROVISIONAL - if (enabled) { - let token = await messaging().getToken() - session.account.setFirebasePushToken(token.toString()) - notification.registerPushToken({ userId: session.user.id, token }) - } + setEnableRequestToken(enabled) } - requestUserPermission() - }, []) + } - React.useEffect(() => { - async function refreshToken() { + async function refreshToken() { + console.log("refreshToken") + if (session.user.id && session.account.jwtToken) { let token = await messaging().getToken() - session.account.setFirebasePushToken(token.toString()) - notification.registerPushToken({ - userId: Number(storage.getNumber(storageKeys().user.id)), - token, - }) + if (typeof token == "string" && token !== "") { + notification.registerPushToken({ + userId: Number(storage.getNumber(storageKeys().user.id)), + token, + }) + } + } + } + React.useEffect(() => { + async function fetch() { + await requestUserPermission() + await refreshToken() } - refreshToken() + fetch() }, []) messaging().onTokenRefresh((token) => { - setTimeout(() => { - notification.refreshPushToken(token) - notification.registerPushToken({ - userId: Number(storage.getNumber(storageKeys().user.id)), - token, - }) - }, 10000) + console.log("messaging().onTokenRefresh") + if (enableRequestToken) { + setTimeout(() => { + if (typeof token == "string" && token !== "") { + notification.registerPushToken({ + userId: Number(storage.getNumber(storageKeys().user.id)), + token, + }) + } + }, 10000) + } }) messaging().onMessage(async (remoteMessage) => { + console.log("messaging().onMessage") const previousNotificationsNum = session.account.unreadNotificationsCount session.account.setUnreadNotificationsCount(previousNotificationsNum + 1) Vibrate("effectClick") From 020227855bbf6642884aae5694d5a1d58048bdd9 Mon Sep 17 00:00:00 2001 From: Tiago Savioli Date: Wed, 13 Nov 2024 03:42:14 -0300 Subject: [PATCH 13/14] fix: change app version --- package.json | 2 +- src/config/index.tsx | 14 ++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index a5778ba..1e23b31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "circle", - "version": "1.0.2", + "version": "1.0.3", "private": true, "scripts": { "android": "react-native run-android", diff --git a/src/config/index.tsx b/src/config/index.tsx index d81275d..8752120 100644 --- a/src/config/index.tsx +++ b/src/config/index.tsx @@ -1,14 +1,4 @@ -import { - API_VERSION, - APP_VERSION, - DEBUG, - DEVELOPMENT_API_ENDPOINT, - LOG_DEBUG, - LOG_LEVEL, - MIXPANEL_KEY, - NODE_ENV, - PRODUCTION_API_ENDPOINT, -} from "@env" +import { API_VERSION, APP_VERSION, DEBUG, LOG_DEBUG, LOG_LEVEL, MIXPANEL_KEY, NODE_ENV } from "@env" import emails from "./emails" import metadata from "./metadata" @@ -22,7 +12,7 @@ const environment = { const api = { API_VERSION: API_VERSION, - ENDPOINT: environment.PRODUCTION ? PRODUCTION_API_ENDPOINT : DEVELOPMENT_API_ENDPOINT, + ENDPOINT: "192.168.15.10:3000", //"52.202.133.96:3000", } const analytics = { From e3f5baebd17012acc9de48a96a948ec7189afa9c Mon Sep 17 00:00:00 2001 From: Tiago Savioli Date: Wed, 13 Nov 2024 03:42:45 -0300 Subject: [PATCH 14/14] fix: change app version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a5778ba..1e23b31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "circle", - "version": "1.0.2", + "version": "1.0.3", "private": true, "scripts": { "android": "react-native run-android",