forked from Ivasoft/mattermost-mobile
Update icon badge on Notification (#6823)
* Update icon badge when receiving a notification while the app is in the foreground * update app badge when sending the app to the background
This commit is contained in:
@@ -10,6 +10,7 @@ import CompassIcon from '@components/compass_icon';
|
||||
import {BOTTOM_TAB_ICON_SIZE} from '@constants/view';
|
||||
import {subscribeAllServers} from '@database/subscription/servers';
|
||||
import {subscribeUnreadAndMentionsByServer, UnreadObserverArgs} from '@database/subscription/unreads';
|
||||
import {useAppState} from '@hooks/device';
|
||||
import NativeNotification from '@notifications';
|
||||
import {changeOpacity} from '@utils/theme';
|
||||
|
||||
@@ -41,6 +42,7 @@ const style = StyleSheet.create({
|
||||
|
||||
const Home = ({isFocused, theme}: Props) => {
|
||||
const [total, setTotal] = useState<UnreadMessages>({mentions: 0, unread: false});
|
||||
const appState = useAppState();
|
||||
|
||||
const updateTotal = () => {
|
||||
let unread = false;
|
||||
@@ -119,6 +121,12 @@ const Home = ({isFocused, theme}: Props) => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (appState === 'background') {
|
||||
updateTotal();
|
||||
}
|
||||
}, [appState]);
|
||||
|
||||
let unreadStyle;
|
||||
if (total.mentions) {
|
||||
unreadStyle = style.mentionsOneDigit;
|
||||
|
||||
@@ -45,6 +45,7 @@ class NotificationService: UNNotificationServiceExtension {
|
||||
if (preferences.object(forKey: "ApplicationIsForeground") as? String != "true") {
|
||||
Network.default.fetchAndStoreDataForPushNotification(bestAttemptContent, withContentHandler: contentHandler)
|
||||
} else if let contentHandler = contentHandler {
|
||||
bestAttemptContent.badge = Gekidou.Database.default.getTotalMentions() as NSNumber
|
||||
contentHandler(bestAttemptContent)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user