Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.

Commit

Permalink
Delete same notification if enter the channel. (#476)
Browse files Browse the repository at this point in the history
* Delete same notification if enter the channel.

* Delete notification if user is in channel

Delete notification if user is in channel, but not alert.

* Format eslint

* Rename function `camelCase`
  • Loading branch information
SimYunSup authored Dec 25, 2021
1 parent 271f6c0 commit e53ce36
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions client/src/components/pages/Message.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as Notifications from 'expo-notifications';

import {
ActivityIndicator,
Alert,
Expand Down Expand Up @@ -636,6 +638,51 @@ const MessageScreen: FC = () => {
params: {channelId},
} = useRoute<RouteProp<MainStackParamList, 'Message'>>();

// Delete notification if user is foreground in channel.
useEffect(() => {
const subscription = Notifications.addNotificationReceivedListener(
(notification) => {
const parsedNotificationData = JSON.parse(
notification.request.content.data.data as string,
);

if (parsedNotificationData.channelId === channelId) {
Notifications.dismissNotificationAsync(
notification.request.identifier,
);
}
},
);

return () => subscription.remove();
}, [channelId]);

useEffect(() => {
async function deleteSameChannelNotification(): Promise<void> {
const notifications =
await Notifications.getPresentedNotificationsAsync();

notifications.forEach((notificationData) => {
const {data: jsonString} = notificationData.request.content.data;

if (typeof jsonString === 'string') {
const {channelId: notificationChannelId} = JSON.parse(jsonString);

if (
typeof notificationChannelId === 'string' &&
notificationChannelId === channelId
) {
Notifications.dismissNotificationAsync(
notificationData.request.identifier,
);
}
}
});
}

deleteSameChannelNotification();
}, [channelId]);

const searchArgs: MessagesQueryVariables = {
first: ITEM_CNT,
channelId,
Expand Down

0 comments on commit e53ce36

Please sign in to comment.