import './notifications.css'; import { Link } from 'preact-router/match'; import { memo } from 'preact/compat'; import { useEffect, useRef, useState } from 'preact/hooks'; import { useSnapshot } from 'valtio'; import Avatar from '../components/avatar'; import Icon from '../components/icon'; import Loader from '../components/loader'; import NameText from '../components/name-text'; import RelativeTime from '../components/relative-time'; import Status from '../components/status'; import states from '../utils/states'; import store from '../utils/store'; import useTitle from '../utils/useTitle'; /* Notification types ================== mention = Someone mentioned you in their status status = Someone you enabled notifications for has posted a status reblog = Someone boosted one of your statuses follow = Someone followed you follow_request = Someone requested to follow you favourite = Someone favourited one of your statuses poll = A poll you have voted in or created has ended update = A status you interacted with has been edited admin.sign_up = Someone signed up (optionally sent to admins) admin.report = A new report has been filed */ const contentText = { mention: 'mentioned you in their status.', status: 'posted a status.', reblog: 'boosted your status.', follow: 'followed you.', follow_request: 'requested to follow you.', favourite: 'favourited your status.', poll: 'A poll you have voted in or created has ended.', 'poll-self': 'A poll you have created has ended.', 'poll-voted': 'A poll you have voted in has ended.', update: 'A status you interacted with has been edited.', }; const LIMIT = 30; // 30 is the maximum limit :( function Notification({ notification }) { const { id, type, status, account, _accounts } = notification; // status = Attached when type of the notification is favourite, reblog, status, mention, poll, or update const actualStatusID = status?.reblog?.id || status?.id; const currentAccount = store.session.get('currentAccount'); const isSelf = currentAccount === account?.id; const isVoted = status?.poll?.voted; const text = type === 'poll' ? contentText[isSelf ? 'poll-self' : isVoted ? 'poll-voted' : 'poll'] : contentText[type]; return ( <>
{!/poll|update/i.test(type) && (
<>
{_accounts?.length > 1 ? (
<>
{_accounts.length} people{' '}
>
) : (
<>
{_accounts.map((account, i) => (
<>
{
e.preventDefault();
states.showAccount = account;
}}
>
{emptyCopy}
; } // Create new flat list of notifications // Combine sibling notifications based on type and status id, ignore the id // Concat all notification.account into an array of _accounts const notificationsMap = {}; const cleanNotifications = []; for (let i = 0, j = 0; i < notifications.length; i++) { const notification = notifications[i]; // const cleanNotification = cleanNotifications[j]; const { status, account, type, created_at } = notification; const createdAt = new Date(created_at).toLocaleDateString(); const key = `${status?.id}-${type}-${createdAt}`; const mappedNotification = notificationsMap[key]; if (mappedNotification?.account) { mappedNotification._accounts.push(account); } else { let n = (notificationsMap[key] = { ...notification, _accounts: [account], }); cleanNotifications[j++] = n; } } // console.log({ notifications, cleanNotifications }); return (███████████ ████
Unable to load notifications