Remove notification features

Notifications will not be implemented in Resin for the foreseeable future
This commit is contained in:
Nat 2022-05-30 15:12:12 -07:00
parent eb9f047a04
commit 7f99ac8845
6 changed files with 2 additions and 487 deletions

View File

@ -25,7 +25,6 @@ import Search from 'src/components/pages/discover/search';
import ViewHashtag from 'src/components/pages/discover/view-hashtag';
import Direct from "src/components/pages/direct";
import Conversation, { Compose } from "src/components/pages/direct/conversation";
import Notifications from 'src/components/pages/profile/notifications';
import UserList from "src/components/pages/user-list.js";
import Settings from "src/components/pages/profile/settings.js";

View File

@ -125,16 +125,7 @@ const Authenticate = ({navigation}) => {
token.access_token
).then(resp => resp.json());
await AsyncStorage.multiSet([
[ "@user_profile", JSON.stringify(profile), ],
[ // TODO: Enable storing notifications
"@user_notifications",
JSON.stringify({
unread: false,
memory: []
}),
],
]);
await AsyncStorage.setItem("@user_profile", JSON.stringify(profile));
navigation.replace("Main");
};

View File

@ -191,18 +191,15 @@ const Profile = ({ navigation }) => {
const init = async () => {
const [
profilePair,
notifPair,
instancePair,
tokenPair
] = await AsyncStorage.multiGet([
"@user_profile",
"@user_notifications",
"@user_instance",
"@user_token",
]);
const profile = JSON.parse(profilePair[1]);
const notifs = JSON.parse(notifPair[1]);
const instance = instancePair[1];
const accessToken = JSON.parse(tokenPair[1]).access_token;
@ -225,7 +222,6 @@ const Profile = ({ navigation }) => {
setState({...state,
profile: latestProfile,
notifs: notifs,
posts: posts,
listedUsers: followers,
loaded: true,
@ -244,8 +240,7 @@ const Profile = ({ navigation }) => {
own = { true }
profile = { state.profile }
posts = { state.posts }
listedUsers = { state.listedUsers }
notifs = { state.notifs }/>
listedUsers = { state.listedUsers }/>
</ScrollView>
: <></>
}

View File

@ -1,440 +0,0 @@
import React, { useState, useEffect } from "react";
import {
Dimensions,
View,
TouchableOpacity,
Image,
Text,
} from "react-native";
import { FontAwesome } from "@expo/vector-icons";
import AsyncStorage from "@react-native-async-storage/async-storage";
const TEST_IMAGE = "https://cache.desktopnexus.com/thumbseg/2255/2255124-bigthumbnail.jpg";
const TEST_NOTIFICATIONS = [
{
id: 1,
type: "follow",
account: {
acct: "njms",
avatar: TEST_IMAGE,
},
},
{
id: 2,
type: "follow_request",
account: {
acct: "njms",
avatar: TEST_IMAGE,
},
},
{
id: 3,
type: "mention",
account: {
acct: "njms",
avatar: TEST_IMAGE,
},
status: {
id: 1,
media_attachments: [],
content: "This is a message",
}
},
{
id: 4,
type: "mention",
account: {
acct: "njms",
avatar: TEST_IMAGE,
},
status: {
id: 1,
media_attachments: [
{ url: TEST_IMAGE }
],
content: "This is a message",
}
},
{
id: 5,
type: "mention",
account: {
acct: "njms",
avatar: TEST_IMAGE,
},
status: {
id: 1,
media_attachments: [
{ url: TEST_IMAGE }
],
content: "This is a really really really really really really"
+ " really really really really really really long message",
}
},
{
id: 6,
type: "reblog",
account: {
acct: "njms",
avatar: TEST_IMAGE,
},
status: {
id: 1,
media_attachments: [
{ url: TEST_IMAGE }
],
}
},
{
id: 7,
type: "favourite",
account: {
acct: "njms",
avatar: TEST_IMAGE,
},
status: {
id: 1,
media_attachments: [
{ url: TEST_IMAGE }
],
}
},
{
id: 8,
type: "status",
account: {
acct: "njms",
avatar: TEST_IMAGE,
},
status: {
id: 1,
media_attachments: [
{ url: TEST_IMAGE }
],
}
},
]
function navigateProfileFactory(nav, acct) {
return () => {
nav.navigate("ViewProfile", {
acct: acct,
});
};
}
function navigatePostFactory(nav, id) {
return () => {
nav.navigate("ViewPost", {
originTab: "Profile",
id: id,
});
}
}
function renderNotification(notif, navigation) {
switch(notif.type) {
case "follow":
return <Follow
data = { notif }
key = { notif.id }
navigation = { navigation } />
case "follow_request":
return <FollowRequest
data = { notif }
key = { notif.id }
navigation = { navigation } />
case "mention":
return <Mention
data = { notif }
key = { notif.id }
navigation = { navigation } />
case "reblog":
return <Reblog
data = { notif }
key = { notif.id }
navigation = { navigation } />
case "favourite":
return <Favourite
data = { notif }
key = { notif.id }
navigation = { navigation } />
case "status":
return <Status
data = { notif }
key = { notif.id }
navigation = { navigation } />
default:
// We're not expecting polls to be super popular on Pixelfed
return <></>
}
}
const UserText = (props) => {
return (
<Text
style = { styles.bold }
onPress = {
() => {
props.navigation.navigate("ViewProfile", {
acct: props.acct
});
}
}>
{ props.acct }&nbsp;
</Text>
);
};
const Notification = (props) => {
return (
<View style = { styles.notif.container }>
<View style = { styles.notif.thumbnailContainer }>
<TouchableOpacity
onPress = { props.thumbnailPressCallback }>
<Image
style = {
[
styles.notif.thumbnail,
props.thumbnailStyles
]
}
source = { { uri: props.thumbnail } } />
</TouchableOpacity>
</View>
<View style = { styles.notif.contentContainer }>
{ props.children }
</View>
{ props.button ?
<View style = { styles.notif.buttonContainer }>
<TouchableOpacity
style = { styles.notif.button }
onPress = { props.buttonCallback }>
<Text>{ props.buttonLabel }</Text>
</TouchableOpacity>
</View>
: <></>
}
</View>
);
};
const Follow = (props) => {
return (
<Notification
thumbnail = { props.data.account.avatar }
thumbnailStyles = { styles.notif.circularThumbnail }
thumbnailPressCallback = {
navigateProfileFactory(props.navigation, props.data.account.acct)
}>
<Text style = { styles.notif.content }>
<UserText acct = { props.data.account.acct } />
has followed you.
</Text>
</Notification>
);
};
const FollowRequest = (props) => {
return (
<Notification
thumbnail = { props.data.account.avatar }
thumbnailStyles = { styles.notif.circularThumbnail }
thumbnailPressCallback = {
navigateProfileFactory(props.navigation, props.data.account.acct)
}
button = { true }
buttonLabel = { "Accept" }
buttonCallback = { () => console.log("Request accepted") }>
<Text style = { styles.notif.content }>
<UserText acct = { props.data.account.acct } />
has requested to follow you.
</Text>
</Notification>
);
};
const Mention = (props) => {
let uri;
let imageStyle;
let thumbnailCallback;
if (props.data.status.media_attachments.length > 0) {
// If it's a comment...
uri = props.data.status.media_attachments[0].url;
imageStyle = {};
thumbnailCallback = navigatePostFactory(
props.navigation,
props.data.status.id
);
} else {
// If it's a reply to your comment...
uri = props.data.account.avatar;
imageStyle = styles.notif.circularThumbnail;
thumbnailCallback = navigateProfileFactory(
props.navigation,
props.data.account.acct
);
}
return (
<Notification
thumbnail = { uri }
thumbnailStyles = { imageStyle }i
thumbnailPressCallback = { thumbnailCallback }>
<Text style = { styles.notif.content }>
<UserText acct = { props.data.account.acct } />
mentioned you:
<Text style = { styles.notif.status }>
"{ props.data.status.content }"
</Text>
</Text>
</Notification>
);
};
const Reblog = (props) => {
return (
<Notification
thumbnail = { props.data.status.media_attachments[0].url }
thumbnailPressCallback = {
navigatePostFactory(props.navigation, props.data.status.id)
}>
<FontAwesome
name = "retweet"
color = "#000"
size = { 20 }
style = { styles.notif.inlineIcon }/>
<Text style = { styles.notif.content }>
<UserText acct = { props.data.account.acct } />
shared your post.
</Text>
</Notification>
);
};
const Favourite = (props) => {
return (
<Notification
thumbnail = { props.data.status.media_attachments[0].url }
thumbnailPressCallback = {
navigatePostFactory(props.navigation, props.data.status.id)
}>
<FontAwesome
name = "heart"
size = { 20 }
color = "black"
style = { styles.notif.inlineIcon }/>
<Text style = { styles.notif.content }>
<UserText acct = { props.data.account.acct } />
liked your post.
</Text>
</Notification>
);
};
const Status = (props) => {
return (
<Notification
thumbnail = { props.data.status.media_attachments[0].url }
thumbnailPressCallback = {
navigatePostFactory(props.navigation, props.data.status.id)
}>
<Text style = { styles.notif.content }>
<UserText acct = { props.data.account.acct } />
just posted.
</Text>
</Notification>
);
};
const Notifications = ({navigation}) => {
const [state, setState] = useState({
loaded: false,
});
useEffect(() => {
const read = JSON.stringify({
unread: false,
memory: [
{ id: 1 },
{ id: 2 },
{ id: 3 },
]
});
AsyncStorage.mergeItem("@user_notifications", read)
.then(() => {
setState({...state,
notifications: TEST_NOTIFICATIONS,
loaded: true
})
});
}, []);
return (
<>
navigation = { navigation }>
{ state.loaded ?
<View>
{
state.notifications.map(notif =>
renderNotification(notif, navigation)
)
}
</View>
: <></>
}
</>
);
}
const SCREEN_WIDTH = Dimensions.get("window").width;
const styles = {
notif: {
container: {
flexDirection: "row",
alignItems: "center",
paddingLeft: 20,
marginTop: 10,
marginBottom: 10,
},
circularThumbnail: { borderRadius: SCREEN_WIDTH / 16 },
thumbnailContainer: {
marginRight: 10,
},
thumbnail: {
width: SCREEN_WIDTH / 8,
height: SCREEN_WIDTH / 8,
},
contentContainer: {
flexShrink: 1,
flexDirection: "row",
alignItems: "center",
},
inlineIcon: {
marginRight: 10,
},
status: { fontStyle: "italic" },
buttonContainer: {
marginLeft: "auto",
marginRight: 10,
},
button: {
borderWidth: 1,
borderColor: "#888",
borderRadius: 10,
padding: 10,
},
},
bold: { fontWeight: "bold" },
};
export default Notifications;

View File

@ -37,7 +37,6 @@ const Settings = (props) => {
await AsyncStorage.multiRemove([
"@user_profile",
"@user_notifications",
"@user_instance",
"@user_token",
]);

View File

@ -1,9 +1,5 @@
import AsyncStorage from "@react-native-async-storage/async-storage";
const TEST_NOTIFICATIONS = [{ id: 1 }, { id: 2 }];
const TEST_NEW_NOTIFICATIONS_1 = [{ id: 1 }, { id: 2 }];
const TEST_NEW_NOTIFICATIONS_2 = [{ id: 1 }, { id: 2 }, { id: 3 }];
export function objectToForm(obj) {
let form = new FormData();
@ -14,31 +10,6 @@ export function objectToForm(obj) {
return form;
}
export async function checkUnreadNotifications() {
// If the check has already been made since the last time notifications.js
// has been opened
const notifications = JSON.parse(await AsyncStorage.getItem("@user_notifications"));
if (notifications.unread) {
return true;
} else {
// Some promise to get new notifications
const newNotifs = await Promise.resolve(TEST_NEW_NOTIFICATIONS_2);
const isUnread = JSON.stringify(newNotifs) != JSON.stringify(notifications.memory);
// Update stored notifications
await AsyncStorage.setItem(
"@user_notifications",
JSON.stringify({...notifications,
unread: isUnread,
})
);
return isUnread;
}
}
export async function postForm(url, data = false, token = false, contentType = false) {
// Send a POST request with data formatted with FormData returning JSON
let headers = {};