Feature/Twitter Notification Filters (#147)

Feature: Twitter notification update
This commit is contained in:
Erik authored and GitHub committed 2021-03-07 16:25:10 +01:00
1 parent 21152fa38a
commit 0203ebbe51
15 files changed
+85 -23

No files matched your search

@@ -11,6 +11,7 @@ import { SettingItem, SettingItemIconAction, SettingItemSlider } from './Setting
import { useTranslation } from 'react-i18next';
import {
FilterList,
Brush,
Wallpaper,
Phone,
@@ -23,7 +24,6 @@ import {
import { ListSubheader } from '@material-ui/core';
import { useSettings } from '../hooks/useSettings';
// import { useSnackbar } from '../../../ui/hooks/useSnackbar';
const SubHeaderComp = (props: { text: string }) => (
<ListSubheader color="primary" component="div" disableSticky>
@@ -73,6 +73,12 @@ export const SettingsApp = () => {
),
);
const twitterNotificationFilters = config.notiFilters.map(
MapSettingItem(settings.TWITTER_notiFilter, (val: SettingOption) =>
handleSettingChange('TWITTER_notiFilter', val),
),
);
const handleCopyPhoneNumber = () => {
// TODO: Dependent on #132 merge
// setClipboard(simcard.number)
@@ -159,6 +165,13 @@ export const SettingsApp = () => {
/>
</List>
<List disablePadding subheader={<SubHeaderComp text={t('APPS_TWITTER')} />}>
<SettingItem
label={t('APPS_SETTINGS_OPTION_NOTIFICATION_FILTER')}
value={settings.TWITTER_notiFilter.label}
options={twitterNotificationFilters}
onClick={openMenu}
icon={<FilterList />}
/>
<SettingItem
label={t('APPS_SETTINGS_OPTION_NOTIFICATION')}
value={settings.TWITTER_notiSound.label}
+5 -2
View File
@@ -1,4 +1,6 @@
import { atom, DefaultValue, useRecoilState } from 'recoil';
import { atom, DefaultValue, SetterOrUpdater, useRecoilState } from 'recoil';
import { SETTINGS_ALL_TWEETS, SETTING_MENTIONS } from '../../../common/typings/twitter';
import config from '../../../config/default.json';
import { SettingOption } from '../../../ui/hooks/useContextMenu';
@@ -32,11 +34,12 @@ export interface IPhoneSettings {
ringtoneVol: number;
notiSound: SettingOption;
notiSoundVol: number;
TWITTER_notiFilter: SettingOption<SETTING_MENTIONS | SETTINGS_ALL_TWEETS>;
TWITTER_notiSound: SettingOption;
TWITTER_notiSoundVol: number;
TWITTER_notifyNewFeedTweet: boolean;
}
export const useSettings = () => {
export const useSettings = (): [IPhoneSettings, SetterOrUpdater<any>] => {
return useRecoilState(settingsState);
};
@@ -43,7 +43,6 @@ export const TwitterApp = () => {
const { profile } = useProfile();
useEffect(() => {
Nui.send('phone:getOrCreateTwitterProfile', {});
// this is a polling implementation. It is possible that
// there is some interaction where, on a new tweet, all
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { useTranslation } from 'react-i18next';
+1 -1
View File
@@ -3,7 +3,7 @@ import { atom } from 'recoil';
export const twitterState = {
profile: atom({
key: 'profile',
default: {},
default: null,
}),
tweets: atom({
key: 'tweets',
@@ -1,32 +1,49 @@
import { useTranslation } from 'react-i18next';
import { useHistory } from 'react-router-dom';
import { useRecoilState } from 'recoil';
import { Tweet } from '../../../common/typings/twitter';
import { useRecoilState, useRecoilValue } from 'recoil';
import { useApp } from '../../../os/apps/hooks/useApps';
import { useNotifications } from '../../../os/notifications/hooks/useNotifications';
import { useSettings } from '../../settings/hooks/useSettings';
import { SETTING_MENTIONS } from '../utils/constants';
import { twitterState } from './state';
const NOTIFICATION_ID = 'twitter:broadcast';
function isMentioned(profileName: string, message: string) {
return !message.toLowerCase().includes(profileName.toLowerCase());
}
export const useTwitterNotifications = () => {
const [settings] = useSettings();
const { t } = useTranslation();
const history = useHistory();
const {
addNotificationAlert,
addNotification,
hasNotification,
removeId,
} = useNotifications();
const { addNotificationAlert, addNotification, hasNotification, removeId } = useNotifications();
const { icon, notificationIcon } = useApp('TWITTER');
const [unreadCount, setUnreadCount] = useRecoilState(twitterState.unreadTweetsCount);
const profile = useRecoilValue(twitterState.profile);
const setNotification = ({ profile_name, message, isRetweet }) => {
const titleStr = isRetweet
const titleStr = isRetweet
? 'APPS_TWITTER_NEW_RETWEET_BROADCAST'
: 'APPS_TWITTER_NEW_BROADCAST';
const currentProfileName = profile.profile_name;
// we don't want notifications of our own tweets
if (currentProfileName === profile_name) return;
// if the player only wants notifications on tweets they are
// mentioned in
if (
settings.TWITTER_notiFilter.value === SETTING_MENTIONS &&
isMentioned(currentProfileName, message)
)
return;
const notification = {
app: 'TWITTER',
id: NOTIFICATION_ID,
@@ -1,7 +1,9 @@
import { useEffect } from 'react';
import { useSetRecoilState } from 'recoil';
import { v4 as uuidv4 } from 'uuid';
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
import Nui from '../../../os/nui-events/utils/Nui';
import { IMAGE_DELIMITER } from '../utils/images';
import { APP_TWITTER } from '../utils/constants';
import { twitterState } from './state';
@@ -64,5 +66,5 @@ export const useTwitterService = () => {
useNuiEvent(APP_TWITTER, 'createTweetLoading', setCreateLoading);
useNuiEvent(APP_TWITTER, 'createTweetResult', handleAddAlert);
useNuiEvent(APP_TWITTER, 'createTweetBroadcast', setNotification);
useNuiEvent(APP_TWITTER, 'phone:retweetExists', handleAddAlert)
useNuiEvent(APP_TWITTER, 'phone:retweetExists', handleAddAlert);
};
@@ -1,3 +1,6 @@
export const IMG_DEFAULT_AVATAR = './media/twitter/egg.png';
export const IMG_INVALID_AVATAR = './media/twitter/invalid.png';
export const APP_TWITTER = 'TWITTER';
export const SETTING_MENTIONS = 'mentions';
export const SETTINGS_ALL_TWEETS = 'all';