mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-13 20:04:35 +03:00
hark: update FE for per-index granularity
This commit is contained in:
parent
9eec477e0e
commit
39caa57308
@ -1,8 +1,9 @@
|
||||
import BaseApi from "./base";
|
||||
import { StoreState } from "../store/type";
|
||||
import { dateToDa, decToUd } from "../lib/util";
|
||||
import {NotifIndex} from "~/types";
|
||||
import {NotifIndex, IndexedNotification} from "~/types";
|
||||
import { BigInteger } from 'big-integer';
|
||||
import {getParentIndex} from "../lib/notification";
|
||||
|
||||
export class HarkApi extends BaseApi<StoreState> {
|
||||
private harkAction(action: any): Promise<any> {
|
||||
@ -68,30 +69,39 @@ export class HarkApi extends BaseApi<StoreState> {
|
||||
return this.harkAction({ seen: null });
|
||||
}
|
||||
|
||||
mute(index: NotifIndex) {
|
||||
if('graph' in index) {
|
||||
const { graph } = index.graph;
|
||||
return this.ignoreGraph(graph);
|
||||
mute(notif: IndexedNotification) {
|
||||
if('graph' in notif.index && 'graph' in notif.notification.contents) {
|
||||
const { index } = notif;
|
||||
const parentIndex = getParentIndex(index.graph, notif.notification.contents.graph)
|
||||
if(!parentIndex) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return this.ignoreGraph(index.graph.graph, parentIndex);
|
||||
}
|
||||
if('group' in index) {
|
||||
const { group } = index.group;
|
||||
if('group' in notif.index) {
|
||||
const { group } = notif.index.group;
|
||||
return this.ignoreGroup(group);
|
||||
}
|
||||
if('chat' in index) {
|
||||
return this.ignoreChat(index.chat);
|
||||
if('chat' in notif.index) {
|
||||
return this.ignoreChat(notif.index.chat.chat);
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
unmute(index: NotifIndex) {
|
||||
if('graph' in index) {
|
||||
return this.listenGraph(index.graph.graph);
|
||||
unmute(notif: IndexedNotification) {
|
||||
if('graph' in notif.index && 'graph' in notif.notification.contents) {
|
||||
const { index } = notif;
|
||||
const parentIndex = getParentIndex(index.graph, notif.notification.contents.graph)
|
||||
if(!parentIndex) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return this.listenGraph(index.graph.graph, parentIndex);
|
||||
}
|
||||
if('group' in index) {
|
||||
return this.listenGroup(index.group.group);
|
||||
if('group' in notif.index) {
|
||||
return this.listenGroup(notif.index.group.group);
|
||||
}
|
||||
if('chat' in index) {
|
||||
return this.listenChat(index.chat);
|
||||
if('chat' in notif.index) {
|
||||
return this.listenChat(notif.index.chat.chat);
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
@ -102,9 +112,12 @@ export class HarkApi extends BaseApi<StoreState> {
|
||||
})
|
||||
}
|
||||
|
||||
ignoreGraph(graph: string) {
|
||||
ignoreGraph(graph: string, index: string) {
|
||||
return this.graphHookAction({
|
||||
ignore: graph
|
||||
ignore: {
|
||||
graph,
|
||||
index
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -121,9 +134,12 @@ export class HarkApi extends BaseApi<StoreState> {
|
||||
})
|
||||
}
|
||||
|
||||
listenGraph(graph: string) {
|
||||
listenGraph(graph: string, index: string) {
|
||||
return this.graphHookAction({
|
||||
listen: graph
|
||||
listen: {
|
||||
graph,
|
||||
index
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
21
pkg/interface/src/logic/lib/notification.ts
Normal file
21
pkg/interface/src/logic/lib/notification.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { GraphNotifIndex, GraphNotificationContents } from "~/types";
|
||||
|
||||
export function getParentIndex(
|
||||
idx: GraphNotifIndex,
|
||||
contents: GraphNotificationContents
|
||||
) {
|
||||
const origIndex = contents[0].index.slice(1).split("/");
|
||||
const ret = (i: string[]) => `/${i.join("/")}`;
|
||||
switch (idx.description) {
|
||||
case "link":
|
||||
return "/";
|
||||
case "comment":
|
||||
return ret(origIndex.slice(0, 1));
|
||||
case "note":
|
||||
return "/";
|
||||
case "mention":
|
||||
return undefined;
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
@ -97,7 +97,7 @@ function graphIgnore(json: any, state: HarkState) {
|
||||
const data = _.get(json, "ignore", false);
|
||||
if (data) {
|
||||
state.notificationsGraphConfig.watching = state.notificationsGraphConfig.watching.filter(
|
||||
(n) => n !== data
|
||||
({ graph, index }) => !(graph === data.graph && index === data.index)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import { GroupUpdate } from "./group-update";
|
||||
import { BigIntOrderedMap } from "~/logic/lib/BigIntOrderedMap";
|
||||
import { Envelope } from './chat-update';
|
||||
|
||||
type GraphNotifDescription = "link" | "comment";
|
||||
type GraphNotifDescription = "link" | "comment" | "note" | "mention";
|
||||
|
||||
export interface GraphNotifIndex {
|
||||
graph: string;
|
||||
@ -39,7 +39,7 @@ export type NotificationContents =
|
||||
| { group: GroupNotificationContents }
|
||||
| { chat: ChatNotificationContents };
|
||||
|
||||
interface Notification {
|
||||
export interface Notification {
|
||||
read: boolean;
|
||||
time: number;
|
||||
contents: NotificationContents;
|
||||
@ -57,7 +57,12 @@ export type Notifications = BigIntOrderedMap<Timebox>;
|
||||
export interface NotificationGraphConfig {
|
||||
watchOnSelf: boolean;
|
||||
mentions: boolean;
|
||||
watching: string[];
|
||||
watching: WatchedIndex[]
|
||||
}
|
||||
|
||||
|
||||
interface WatchedIndex {
|
||||
graph: string;
|
||||
index: string;
|
||||
}
|
||||
export type GroupNotificationsConfig = string[];
|
||||
|
@ -11,6 +11,7 @@ import {
|
||||
Associations,
|
||||
} from "~/types";
|
||||
import GlobalApi from "~/logic/api/global";
|
||||
import { getParentIndex } from "~/logic/lib/notification";
|
||||
import { StatelessAsyncAction } from "~/views/components/StatelessAsyncAction";
|
||||
import { GroupNotification } from "./group";
|
||||
import { GraphNotification } from "./graph";
|
||||
@ -29,20 +30,29 @@ interface NotificationProps {
|
||||
}
|
||||
|
||||
function getMuted(
|
||||
idx: NotifIndex,
|
||||
idxNotif: IndexedNotification,
|
||||
groups: GroupNotificationsConfig,
|
||||
graphs: NotificationGraphConfig,
|
||||
chat: string[]
|
||||
) {
|
||||
if ("graph" in idx) {
|
||||
const { graph } = idx.graph;
|
||||
return _.findIndex(graphs?.watching || [], (g) => g === graph) === -1;
|
||||
const { index, notification } = idxNotif;
|
||||
if ("graph" in idxNotif.index) {
|
||||
const { graph } = idxNotif.index.graph;
|
||||
if(!('graph' in notification.contents)) {
|
||||
throw new Error();
|
||||
}
|
||||
const parent = getParentIndex(index.graph, notification.contents.graph);
|
||||
|
||||
return _.findIndex(
|
||||
graphs?.watching || [],
|
||||
(g) => g.graph === graph && g.index === parent
|
||||
) === -1;
|
||||
}
|
||||
if ("group" in idx) {
|
||||
return _.findIndex(groups || [], (g) => g === idx.group.group) === -1;
|
||||
if ("group" in index) {
|
||||
return _.findIndex(groups || [], (g) => g === index.group.group) === -1;
|
||||
}
|
||||
if ("chat" in idx) {
|
||||
return _.findIndex(chat || [], (c) => c === idx.chat) === -1;
|
||||
if ("chat" in index) {
|
||||
return _.findIndex(chat || [], (c) => c === index.chat.chat) === -1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -64,7 +74,7 @@ function NotificationWrapper(props: {
|
||||
}, [time, notif]);
|
||||
|
||||
const isMuted = getMuted(
|
||||
notif.index,
|
||||
notif,
|
||||
props.groupConfig,
|
||||
props.graphConfig,
|
||||
props.chatConfig
|
||||
@ -72,7 +82,7 @@ function NotificationWrapper(props: {
|
||||
|
||||
const onChangeMute = useCallback(async () => {
|
||||
const func = isMuted ? "unmute" : "mute";
|
||||
return api.hark[func](notif.index);
|
||||
return api.hark[func](notif);
|
||||
}, [notif, api, isMuted]);
|
||||
|
||||
const changeMuteDesc = isMuted ? "Unmute" : "Mute";
|
||||
|
@ -51,19 +51,18 @@ export function ChannelMenu(props: ChannelMenuProps) {
|
||||
const isOurs = ship.slice(1) === window.ship;
|
||||
|
||||
const isMuted = appIsGraph(app)
|
||||
? props.graphNotificationConfig.watching.findIndex((a) => a === appPath) ===
|
||||
-1
|
||||
? props.graphNotificationConfig.watching.findIndex(
|
||||
(a) => a.graph === appPath && a.index === "/"
|
||||
) === -1
|
||||
: props.chatNotificationConfig.findIndex((a) => a === appPath) === -1;
|
||||
|
||||
const onChangeMute = async () => {
|
||||
const func =
|
||||
association["app-name"] === "chat"
|
||||
? isMuted
|
||||
? "listenChat"
|
||||
: "ignoreChat"
|
||||
: isMuted
|
||||
? "listenGraph"
|
||||
: "ignoreGraph";
|
||||
await api.hark[func](appPath);
|
||||
if (association["app-name"] === "chat") {
|
||||
const func = isMuted ? "listenChat" : "ignoreChat";
|
||||
return api.hark[func](appPath);
|
||||
}
|
||||
const func = isMuted ? "listenGraph" : "ignoreGraph";
|
||||
await api.hark[func](appPath, "/");
|
||||
};
|
||||
const onUnsubscribe = useCallback(async () => {
|
||||
const app = metadata.module || association["app-name"];
|
||||
|
Loading…
Reference in New Issue
Block a user