implement js changes
This commit is contained in:
+6
-4
@@ -41,9 +41,9 @@ public class ExpoBackgroundNotificationHandlerModule: Module {
|
||||
SharedPrefs.shared.setValue(BadgeType.generic.toKeyName(), 0)
|
||||
}
|
||||
|
||||
AsyncFunction("incrementMessagesCountAsync") { (convoId: String) in
|
||||
AsyncFunction("maybeIncrementMessagesCountAsync") { (convoId: String) in
|
||||
guard !SharedPrefs.shared.setContains(INCREMENTED_FOR_KEY, convoId) else {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
var count = SharedPrefs.shared.getNumber(BadgeType.messages.toKeyName()) ?? 0
|
||||
@@ -51,11 +51,12 @@ public class ExpoBackgroundNotificationHandlerModule: Module {
|
||||
|
||||
SharedPrefs.shared.addToSet(INCREMENTED_FOR_KEY, convoId)
|
||||
SharedPrefs.shared.setValue(BadgeType.messages.toKeyName(), count)
|
||||
return true
|
||||
}
|
||||
|
||||
AsyncFunction("decrementMessagesCountAsync") { (convoId: String) in
|
||||
AsyncFunction("maybeDecrementMessagesCountAsync") { (convoId: String) in
|
||||
guard SharedPrefs.shared.setContains(INCREMENTED_FOR_KEY, convoId) else {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
var count = SharedPrefs.shared.getNumber(BadgeType.messages.toKeyName()) ?? 0
|
||||
@@ -63,6 +64,7 @@ public class ExpoBackgroundNotificationHandlerModule: Module {
|
||||
|
||||
SharedPrefs.shared.removeFromSet(INCREMENTED_FOR_KEY, convoId)
|
||||
SharedPrefs.shared.setValue(BadgeType.messages.toKeyName(), count)
|
||||
return true
|
||||
}
|
||||
|
||||
AsyncFunction("getPrefsAsync") {
|
||||
|
||||
@@ -4,22 +4,20 @@ import {BackgroundNotificationHandlerPreferences} from './ExpoBackgroundNotifica
|
||||
|
||||
const NativeModule = requireNativeModule('ExpoBackgroundNotificationHandler')
|
||||
|
||||
export function resetGenericCountAsync(count: number): Promise<void> {
|
||||
NativeModule.resetGenericCountAsync(count)
|
||||
export function resetGenericCountAsync(): Promise<void> {
|
||||
NativeModule.resetGenericCountAsync()
|
||||
}
|
||||
|
||||
export function incrementMessagesCountAsync(
|
||||
count: number,
|
||||
export function maybeIncrementMessagesCountAsync(
|
||||
convoId: string,
|
||||
): Promise<void> {
|
||||
NativeModule.incrementMessagesCountAsync(count, convoId)
|
||||
): Promise<boolean> {
|
||||
NativeModule.incrementMessagesCountAsync(convoId)
|
||||
}
|
||||
|
||||
export function decrementMessagesCountAsync(
|
||||
count: number,
|
||||
export function maybeDecrementMessagesCountAsync(
|
||||
convoId: string,
|
||||
): Promise<void> {
|
||||
NativeModule.decrementMessagesCountAsync(count, convoId)
|
||||
): Promise<boolean> {
|
||||
NativeModule.decrementMessagesCountAsync(convoId)
|
||||
}
|
||||
|
||||
export function getPrefsAsync(): Promise<BackgroundNotificationHandlerPreferences> {
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
import {NotImplementedError} from './NotImplemented'
|
||||
import {BackgroundNotificationHandlerPreferences} from './types'
|
||||
|
||||
export function resetGenericCountAsync(count: number): Promise<void> {
|
||||
throw new NotImplementedError({count})
|
||||
export function resetGenericCountAsync(): Promise<void> {
|
||||
throw new NotImplementedError()
|
||||
}
|
||||
|
||||
export function incrementMessagesCountAsync(
|
||||
count: number,
|
||||
export function maybeIncrementMessagesCountAsync(
|
||||
convoId: string,
|
||||
): Promise<void> {
|
||||
throw new NotImplementedError({count, convoId})
|
||||
): Promise<boolean> {
|
||||
throw new NotImplementedError({convoId})
|
||||
}
|
||||
|
||||
export function decrementMessagesCountAsync(
|
||||
count: number,
|
||||
export function maybeDecrementMessagesCountAsync(
|
||||
convoId: string,
|
||||
): Promise<void> {
|
||||
throw new NotImplementedError({count, convoId})
|
||||
): Promise<boolean> {
|
||||
throw new NotImplementedError({convoId})
|
||||
}
|
||||
|
||||
export function getPrefsAsync(): Promise<BackgroundNotificationHandlerPreferences | null> {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import React from 'react'
|
||||
import * as Notifications from 'expo-notifications'
|
||||
import {getBadgeCountAsync, setBadgeCountAsync} from 'expo-notifications'
|
||||
import {setBadgeCountAsync} from 'expo-notifications'
|
||||
import {BskyAgent} from '@atproto/api'
|
||||
|
||||
import {logger} from '#/logger'
|
||||
import {SessionAccount, useAgent, useSession} from '#/state/session'
|
||||
import {logEvent, useGate} from 'lib/statsig/statsig'
|
||||
import {devicePlatform, isAndroid, isNative} from 'platform/detection'
|
||||
import BackgroundNotificationHandler from '../../../modules/expo-background-notification-handler'
|
||||
import {BackgroundNotifications} from '../../../modules/expo-background-notification-handler'
|
||||
|
||||
const SERVICE_DID = (serviceUrl?: string) =>
|
||||
serviceUrl?.includes('staging')
|
||||
@@ -144,23 +144,7 @@ export function useRequestNotificationsPermission() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function decrementBadgeCount(
|
||||
type: 'generic' | 'messages',
|
||||
by: number,
|
||||
) {
|
||||
if (!isNative) return
|
||||
|
||||
let count = await getBadgeCountAsync()
|
||||
count -= by
|
||||
if (count < 0) {
|
||||
count = 0
|
||||
}
|
||||
|
||||
await BackgroundNotificationHandler.setBadgeCountAsync(type, count)
|
||||
await setBadgeCountAsync(count)
|
||||
}
|
||||
|
||||
export async function resetBadgeCount(type: 'generic' | 'messages') {
|
||||
await BackgroundNotificationHandler.setBadgeCountAsync(type, 0)
|
||||
export async function resetGenericBadgeCount() {
|
||||
await BackgroundNotifications.resetGenericCountAsync()
|
||||
await setBadgeCountAsync(0)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import {useProfileShadow} from '#/state/cache/profile-shadow'
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
import {useSession} from '#/state/session'
|
||||
import {useHaptics} from 'lib/haptics'
|
||||
import {decrementBadgeCount} from 'lib/notifications/notifications'
|
||||
import {logEvent} from 'lib/statsig/statsig'
|
||||
import {sanitizeDisplayName} from 'lib/strings/display-names'
|
||||
import {TimeElapsed} from '#/view/com/util/TimeElapsed'
|
||||
@@ -32,6 +31,7 @@ import {Link} from '#/components/Link'
|
||||
import {useMenuControl} from '#/components/Menu'
|
||||
import {PostAlerts} from '#/components/moderation/PostAlerts'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {BackgroundNotifications} from '../../../../modules/expo-background-notification-handler'
|
||||
|
||||
export let ChatListItem = ({
|
||||
convo,
|
||||
@@ -178,7 +178,7 @@ function ChatListItemReady({
|
||||
|
||||
const onPress = useCallback(
|
||||
(e: GestureResponderEvent) => {
|
||||
decrementBadgeCount(convo.unreadCount)
|
||||
BackgroundNotifications.maybeDecrementMessagesCountAsync(convo.id)
|
||||
if (isDeletedAccount) {
|
||||
e.preventDefault()
|
||||
menuControl.open()
|
||||
@@ -187,7 +187,7 @@ function ChatListItemReady({
|
||||
logEvent('chat:open', {logContext: 'ChatsList'})
|
||||
}
|
||||
},
|
||||
[convo.unreadCount, isDeletedAccount, menuControl],
|
||||
[convo.id, isDeletedAccount, menuControl],
|
||||
)
|
||||
|
||||
const onLongPress = useCallback(() => {
|
||||
|
||||
@@ -10,7 +10,7 @@ import EventEmitter from 'eventemitter3'
|
||||
import BroadcastChannel from '#/lib/broadcast'
|
||||
import {logger} from '#/logger'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {resetBadgeCount} from 'lib/notifications/notifications'
|
||||
import {resetGenericBadgeCount} from 'lib/notifications/notifications'
|
||||
import {useModerationOpts} from '../../preferences/moderation-opts'
|
||||
import {truncateAndInvalidate} from '../util'
|
||||
import {RQKEY as RQKEY_NOTIFS} from './feed'
|
||||
@@ -117,7 +117,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
// update & broadcast
|
||||
setNumUnread('')
|
||||
broadcast.postMessage({event: ''})
|
||||
resetBadgeCount('generic')
|
||||
resetGenericBadgeCount()
|
||||
},
|
||||
|
||||
async checkUnread({
|
||||
|
||||
Reference in New Issue
Block a user