Adapt to new changes in group notifications API
Reference: https://github.com/mastodon/mastodon/pull/31214
This commit is contained in:
parent
9806d8ae9d
commit
57db8778a4
3 changed files with 23 additions and 4 deletions
|
@ -12,7 +12,7 @@ import Loader from '../components/loader';
|
||||||
import Notification from '../components/notification';
|
import Notification from '../components/notification';
|
||||||
import { api } from '../utils/api';
|
import { api } from '../utils/api';
|
||||||
import db from '../utils/db';
|
import db from '../utils/db';
|
||||||
import groupNotifications from '../utils/group-notifications';
|
import { massageNotifications2 } from '../utils/group-notifications';
|
||||||
import states, { saveStatus } from '../utils/states';
|
import states, { saveStatus } from '../utils/states';
|
||||||
import { getCurrentAccountNS } from '../utils/store-utils';
|
import { getCurrentAccountNS } from '../utils/store-utils';
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ function NotificationsMenu({ anchorRef, state, onClose }) {
|
||||||
|
|
||||||
async function fetchNotifications() {
|
async function fetchNotifications() {
|
||||||
const allNotifications = await notificationsIterator.next();
|
const allNotifications = await notificationsIterator.next();
|
||||||
const notifications = allNotifications.value;
|
const notifications = massageNotifications2(allNotifications.value);
|
||||||
|
|
||||||
if (notifications?.length) {
|
if (notifications?.length) {
|
||||||
notifications.forEach((notification) => {
|
notifications.forEach((notification) => {
|
||||||
|
|
|
@ -22,6 +22,7 @@ import { api } from '../utils/api';
|
||||||
import enhanceContent from '../utils/enhance-content';
|
import enhanceContent from '../utils/enhance-content';
|
||||||
import groupNotifications, {
|
import groupNotifications, {
|
||||||
groupNotifications2,
|
groupNotifications2,
|
||||||
|
massageNotifications2,
|
||||||
} from '../utils/group-notifications';
|
} from '../utils/group-notifications';
|
||||||
import handleContentLinks from '../utils/handle-content-links';
|
import handleContentLinks from '../utils/handle-content-links';
|
||||||
import mem from '../utils/mem';
|
import mem from '../utils/mem';
|
||||||
|
@ -120,7 +121,7 @@ function Notifications({ columnMode }) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const allNotifications = await notificationsIterator.current.next();
|
const allNotifications = await notificationsIterator.current.next();
|
||||||
const notifications = allNotifications.value;
|
const notifications = massageNotifications2(allNotifications.value);
|
||||||
|
|
||||||
if (notifications?.length) {
|
if (notifications?.length) {
|
||||||
notifications.forEach((notification) => {
|
notifications.forEach((notification) => {
|
||||||
|
|
|
@ -28,8 +28,26 @@ export function fixNotifications(notifications) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function massageNotifications2(notifications) {
|
||||||
|
if (notifications?.accounts) {
|
||||||
|
const { accounts, notificationGroups, statuses } = notifications;
|
||||||
|
return notificationGroups.map((group) => {
|
||||||
|
const { sampleAccountIds, statusId } = group;
|
||||||
|
const sampleAccounts =
|
||||||
|
sampleAccountIds?.map((id) => accounts.find((a) => a.id === id)) || [];
|
||||||
|
const status = statuses?.find((s) => s.id === statusId) || null;
|
||||||
|
return {
|
||||||
|
...group,
|
||||||
|
sampleAccounts,
|
||||||
|
status,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return notifications;
|
||||||
|
}
|
||||||
|
|
||||||
export function groupNotifications2(groupNotifications) {
|
export function groupNotifications2(groupNotifications) {
|
||||||
// Massage grouped notifications to look like faux grouped notifications above
|
// Make grouped notifications to look like faux grouped notifications
|
||||||
const newGroupNotifications = groupNotifications.map((gn) => {
|
const newGroupNotifications = groupNotifications.map((gn) => {
|
||||||
const {
|
const {
|
||||||
latestPageNotificationAt,
|
latestPageNotificationAt,
|
||||||
|
|
Loading…
Add table
Reference in a new issue