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

@@ -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';