mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-11-10 18:21:34 +03:00
hark-fe: integrate hooks into state
This commit is contained in:
parent
cf4f0f302e
commit
ec5804bb3c
5
pkg/interface/package-lock.json
generated
5
pkg/interface/package-lock.json
generated
@ -2682,6 +2682,11 @@
|
||||
"integrity": "sha1-3DQxT05nkxgJP8dgJyUl+UvyXBY=",
|
||||
"dev": true
|
||||
},
|
||||
"big-integer": {
|
||||
"version": "1.6.48",
|
||||
"resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.48.tgz",
|
||||
"integrity": "sha512-j51egjPa7/i+RdiRuJbPdJ2FIUYYPhvYLjzoYbcMMm62ooO6F94fETG4MTs46zPAF9Brs04OajboA/qTGuz78w=="
|
||||
},
|
||||
"big.js": {
|
||||
"version": "5.2.2",
|
||||
"resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz",
|
||||
|
@ -12,6 +12,7 @@
|
||||
"@tlon/indigo-react": "urbit/indigo-react#lf/1.2.9",
|
||||
"@tlon/sigil-js": "^1.4.2",
|
||||
"aws-sdk": "^2.726.0",
|
||||
"big-integer": "^1.6.48",
|
||||
"classnames": "^2.2.6",
|
||||
"codemirror": "^5.55.0",
|
||||
"css-loader": "^3.5.3",
|
||||
|
@ -12,6 +12,7 @@ import LaunchApi from './launch';
|
||||
import PublishApi from './publish';
|
||||
import GraphApi from './graph';
|
||||
import S3Api from './s3';
|
||||
import {HarkApi} from './hark';
|
||||
|
||||
export default class GlobalApi extends BaseApi<StoreState> {
|
||||
chat = new ChatApi(this.ship, this.channel, this.store);
|
||||
@ -24,6 +25,7 @@ export default class GlobalApi extends BaseApi<StoreState> {
|
||||
publish = new PublishApi(this.ship, this.channel, this.store);
|
||||
s3 = new S3Api(this.ship, this.channel, this.store);
|
||||
graph = new GraphApi(this.ship, this.channel, this.store);
|
||||
hark = new HarkApi(this.ship, this.channel, this.store);
|
||||
|
||||
|
||||
constructor(
|
||||
|
@ -8,6 +8,14 @@ export class HarkApi extends BaseApi<StoreState> {
|
||||
return this.action("hark-store", "hark-action", action);
|
||||
}
|
||||
|
||||
private graphHookAction(action: any) {
|
||||
return this.action("hark-graph-hook", "hark-graph-hook-action", action);
|
||||
}
|
||||
|
||||
private groupHookAction(action: any) {
|
||||
return this.action("hark-group-hook", "hark-group-hook-action", action);
|
||||
}
|
||||
|
||||
private actOnNotification(frond: string, intTime: BigInteger, index: NotifIndex) {
|
||||
const time = decToUd(intTime.toString());
|
||||
return this.harkAction({
|
||||
@ -56,6 +64,53 @@ 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);
|
||||
}
|
||||
if('group' in index) {
|
||||
const { group } = index.group;
|
||||
return this.ignoreGroup(group);
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
unmute(index: NotifIndex) {
|
||||
if('graph' in index) {
|
||||
return this.listenGraph(index.graph.graph);
|
||||
}
|
||||
if('group' in index) {
|
||||
return this.listenGroup(index.group.group);
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
ignoreGroup(group: string) {
|
||||
return this.groupHookAction({
|
||||
ignore: group
|
||||
})
|
||||
}
|
||||
|
||||
ignoreGraph(graph: string) {
|
||||
return this.graphHookAction({
|
||||
ignore: graph
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
listenGroup(group: string) {
|
||||
return this.groupHookAction({
|
||||
listen: group
|
||||
})
|
||||
}
|
||||
|
||||
listenGraph(graph: string) {
|
||||
return this.graphHookAction({
|
||||
listen: graph
|
||||
})
|
||||
}
|
||||
|
||||
async getTimeSubset(start?: Date, end?: Date) {
|
||||
const s = start ? dateToDa(start) : "-";
|
||||
const e = end ? dateToDa(end) : "-";
|
||||
|
@ -167,8 +167,8 @@ export class BigIntOrderedMap<V> implements Iterable<[BigInteger, V]> {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
result.push(node.n);
|
||||
inner(node.l);
|
||||
result.push(node.n);
|
||||
inner(node.r);
|
||||
};
|
||||
inner(this.root);
|
||||
|
@ -1,4 +1,10 @@
|
||||
import { Notifications, Notification, NotifIndex, NotificationGraphConfig, GroupNotificationsConfig } from "~/types";
|
||||
import {
|
||||
Notifications,
|
||||
Notification,
|
||||
NotifIndex,
|
||||
NotificationGraphConfig,
|
||||
GroupNotificationsConfig,
|
||||
} from "~/types";
|
||||
import { makePatDa } from "~/logic/lib/util";
|
||||
import _ from "lodash";
|
||||
|
||||
@ -7,7 +13,7 @@ type HarkState = {
|
||||
archivedNotifications: Notifications;
|
||||
notificationsCount: number;
|
||||
notificationsGraphConfig: NotificationGraphConfig;
|
||||
groupNotifications: GroupNotificationsConfig;
|
||||
notificationsGroupConfig: GroupNotificationsConfig;
|
||||
};
|
||||
|
||||
export const HarkReducer = (json: any, state: HarkState) => {
|
||||
@ -19,11 +25,13 @@ export const HarkReducer = (json: any, state: HarkState) => {
|
||||
if (graphHookData) {
|
||||
console.log(graphHookData);
|
||||
graphInitial(graphHookData, state);
|
||||
graphIgnore(graphHookData, state);
|
||||
graphListen(graphHookData, state);
|
||||
graphWatchSelf(graphHookData, state);
|
||||
graphMentions(graphHookData, state);
|
||||
}
|
||||
const groupHookData = _.get(json, "hark-group-hook-update", false);
|
||||
if(groupHookData) {
|
||||
if (groupHookData) {
|
||||
groupInitial(groupHookData, state);
|
||||
groupListen(groupHookData, state);
|
||||
groupIgnore(groupHookData, state);
|
||||
@ -31,9 +39,9 @@ export const HarkReducer = (json: any, state: HarkState) => {
|
||||
};
|
||||
|
||||
function groupInitial(json: any, state: HarkState) {
|
||||
const data = _.get(json, 'initial', false);
|
||||
if(data) {
|
||||
state.groupNotifications = data;
|
||||
const data = _.get(json, "initial", false);
|
||||
if (data) {
|
||||
state.notificationsGroupConfig = data;
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,17 +52,38 @@ function graphInitial(json: any, state: HarkState) {
|
||||
}
|
||||
}
|
||||
|
||||
function graphListen(json: any, state: HarkState) {
|
||||
const data = _.get(json, "listen", false);
|
||||
if (data) {
|
||||
state.notificationsGraphConfig.watching = [
|
||||
...state.notificationsGraphConfig.watching,
|
||||
data,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
function graphIgnore(json: any, state: HarkState) {
|
||||
const data = _.get(json, "ignore", false);
|
||||
if (data) {
|
||||
state.notificationsGraphConfig.watching = state.notificationsGraphConfig.watching.filter(
|
||||
(n) => n !== data
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function groupListen(json: any, state: HarkState) {
|
||||
const data = _.get(json, "listen", false);
|
||||
if (data) {
|
||||
state.groupNotifications = [...state.groupNotifications, data];
|
||||
state.notificationsGroupConfig = [...state.notificationsGroupConfig, data];
|
||||
}
|
||||
}
|
||||
|
||||
function groupIgnore(json: any, state: HarkState) {
|
||||
const data = _.get(json, "ignore", false);
|
||||
if (data) {
|
||||
state.groupNotifications = state.groupNotifications.filter(n => n!== data);
|
||||
state.notificationsGroupConfig = state.notificationsGroupConfig.filter(
|
||||
(n) => n !== data
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,6 +109,26 @@ function reduce(data: any, state: HarkState) {
|
||||
more(data, state);
|
||||
dnd(data, state);
|
||||
count(data, state);
|
||||
added(data, state);
|
||||
}
|
||||
|
||||
function added(json: any, state: HarkState) {
|
||||
const data = _.get(json, "added", false);
|
||||
if (data) {
|
||||
const { index, notification } = data;
|
||||
const time = makePatDa(data.time);
|
||||
const timebox = state.notifications.get(time) || [];
|
||||
const arrIdx = timebox.findIndex((idxNotif) =>
|
||||
notifIdxEqual(index, idxNotif.index)
|
||||
);
|
||||
if (arrIdx !== -1) {
|
||||
timebox[arrIdx] = { index, notification };
|
||||
state.notifications.set(time, timebox);
|
||||
} else {
|
||||
state.notifications.set(time, [...timebox, { index, notification }]);
|
||||
state.notificationsCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function count(json: any, state: HarkState) {
|
||||
|
@ -104,11 +104,11 @@ export default class GlobalStore extends BaseStore<StoreState> {
|
||||
chatSynced: null,
|
||||
notifications: new BigIntOrderedMap<Timebox>(),
|
||||
archivedNotifications: new BigIntOrderedMap<Timebox>(),
|
||||
notificationsGroupConfig: [],
|
||||
notificationsGraphConfig: {
|
||||
watchOnSelf: false,
|
||||
mentions: false,
|
||||
watching: [],
|
||||
watchingIndices: {}
|
||||
},
|
||||
notificationsCount: 0
|
||||
};
|
||||
|
@ -11,7 +11,7 @@ import { LaunchState, WeatherState } from '~/types/launch-update';
|
||||
import { ConnectionStatus } from '~/types/connection';
|
||||
import { BackgroundConfig, LocalUpdateRemoteContentPolicy } from '~/types/local-update';
|
||||
import {Graphs} from '~/types/graph-update';
|
||||
import { Notifications, NotificationGraphConfig } from "~/types";
|
||||
import { Notifications, NotificationGraphConfig, GroupNotificationsConfig } from "~/types";
|
||||
|
||||
export interface StoreState {
|
||||
// local state
|
||||
@ -57,6 +57,7 @@ export interface StoreState {
|
||||
|
||||
notifications: Notifications;
|
||||
notificationsGraphConfig: NotificationGraphConfig;
|
||||
notificationsGroupConfig: GroupNotificationsConfig;
|
||||
notificationsCount: number,
|
||||
doNotDisturb: boolean;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import _ from "lodash";
|
||||
import { Post } from "./graph-update";
|
||||
import { GroupUpdate } from "./group-update";
|
||||
import { BigIntOrderedMap } from "~/logic/lib/BigIntOrderedMapCustom";
|
||||
import { BigIntOrderedMap } from "~/logic/lib/BigIntOrderedMap";
|
||||
|
||||
type GraphNotifDescription = "link" | "comment";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user