2021-09-06 06:59:15 +03:00
|
|
|
import { BigInteger } from 'big-integer';
|
2021-02-25 06:54:00 +03:00
|
|
|
|
|
|
|
import { Poke } from '../lib/types';
|
2021-09-06 06:59:15 +03:00
|
|
|
import {
|
|
|
|
HarkBin,
|
|
|
|
HarkBinId,
|
2021-09-17 03:49:31 +03:00
|
|
|
HarkLid,
|
2021-09-06 07:29:43 +03:00
|
|
|
HarkPlace
|
2021-09-06 06:59:15 +03:00
|
|
|
} from './types';
|
2021-02-25 06:54:00 +03:00
|
|
|
import { decToUd } from '../lib';
|
|
|
|
|
|
|
|
export const harkAction = <T>(data: T): Poke<T> => ({
|
|
|
|
app: 'hark-store',
|
|
|
|
mark: 'hark-action',
|
|
|
|
json: data
|
|
|
|
});
|
|
|
|
|
|
|
|
const graphHookAction = <T>(data: T): Poke<T> => ({
|
|
|
|
app: 'hark-graph-hook',
|
|
|
|
mark: 'hark-graph-hook-action',
|
|
|
|
json: data
|
|
|
|
});
|
|
|
|
|
|
|
|
export { graphHookAction as harkGraphHookAction };
|
|
|
|
|
|
|
|
const groupHookAction = <T>(data: T): Poke<T> => ({
|
|
|
|
app: 'hark-group-hook',
|
|
|
|
mark: 'hark-group-hook-action',
|
|
|
|
json: data
|
|
|
|
});
|
|
|
|
|
|
|
|
export { groupHookAction as harkGroupHookAction };
|
|
|
|
|
|
|
|
export const actOnNotification = (
|
|
|
|
frond: string,
|
|
|
|
intTime: BigInteger,
|
2021-09-06 07:29:43 +03:00
|
|
|
bin: HarkBin
|
2021-09-06 06:59:15 +03:00
|
|
|
): Poke<unknown> =>
|
|
|
|
harkAction({
|
|
|
|
[frond]: {
|
|
|
|
time: decToUd(intTime.toString()),
|
2021-09-06 07:29:43 +03:00
|
|
|
bin
|
2021-09-06 06:59:15 +03:00
|
|
|
}
|
|
|
|
});
|
2021-02-25 06:54:00 +03:00
|
|
|
|
2021-09-06 06:59:15 +03:00
|
|
|
export const setMentions = (mentions: boolean): Poke<unknown> =>
|
|
|
|
graphHookAction({
|
|
|
|
'set-mentions': mentions
|
|
|
|
});
|
2021-02-25 06:54:00 +03:00
|
|
|
|
2021-09-06 06:59:15 +03:00
|
|
|
export const setWatchOnSelf = (watchSelf: boolean): Poke<unknown> =>
|
|
|
|
graphHookAction({
|
|
|
|
'set-watch-on-self': watchSelf
|
|
|
|
});
|
2021-02-25 06:54:00 +03:00
|
|
|
|
2021-09-06 06:59:15 +03:00
|
|
|
export const setDoNotDisturb = (dnd: boolean): Poke<unknown> =>
|
|
|
|
harkAction({
|
|
|
|
'set-dnd': dnd
|
|
|
|
});
|
2021-02-25 06:54:00 +03:00
|
|
|
|
2021-09-17 03:49:31 +03:00
|
|
|
export const archive = (bin: HarkBin, lid: HarkLid): Poke<unknown> =>
|
2021-09-06 06:59:15 +03:00
|
|
|
harkAction({
|
|
|
|
archive: {
|
2021-09-17 03:49:31 +03:00
|
|
|
lid,
|
2021-09-06 06:59:15 +03:00
|
|
|
bin
|
|
|
|
}
|
|
|
|
});
|
2021-02-25 06:54:00 +03:00
|
|
|
|
2021-09-17 03:49:31 +03:00
|
|
|
export const opened = harkAction({
|
|
|
|
opened: null
|
|
|
|
});
|
|
|
|
|
2021-02-25 06:54:00 +03:00
|
|
|
|
|
|
|
|
2021-09-06 06:59:15 +03:00
|
|
|
export const markCountAsRead = (place: HarkPlace): Poke<unknown> =>
|
|
|
|
harkAction({
|
|
|
|
'read-count': place
|
|
|
|
});
|
2021-02-25 06:54:00 +03:00
|
|
|
|
|
|
|
export const markEachAsRead = (
|
2021-09-06 06:59:15 +03:00
|
|
|
place: HarkPlace,
|
|
|
|
path: string
|
|
|
|
): Poke<unknown> =>
|
|
|
|
harkAction({
|
|
|
|
'read-each': {
|
|
|
|
place,
|
|
|
|
path
|
|
|
|
}
|
|
|
|
});
|
2021-02-25 06:54:00 +03:00
|
|
|
|
|
|
|
export const seen = () => harkAction({ seen: null });
|
|
|
|
|
2021-09-06 06:59:15 +03:00
|
|
|
export const readAll = harkAction({ 'read-all': null });
|
|
|
|
export const archiveAll = harkAction({ 'archive-all': null });
|
2021-02-25 06:54:00 +03:00
|
|
|
|
2021-09-06 06:59:15 +03:00
|
|
|
export const ignoreGroup = (group: string): Poke<unknown> =>
|
|
|
|
groupHookAction({
|
|
|
|
ignore: group
|
|
|
|
});
|
2021-02-25 06:54:00 +03:00
|
|
|
|
2021-09-06 06:59:15 +03:00
|
|
|
export const ignoreGraph = (graph: string, index: string): Poke<unknown> =>
|
|
|
|
graphHookAction({
|
|
|
|
ignore: {
|
|
|
|
graph,
|
|
|
|
index
|
2021-02-25 06:54:00 +03:00
|
|
|
}
|
2021-09-06 06:59:15 +03:00
|
|
|
});
|
2021-02-25 06:54:00 +03:00
|
|
|
|
2021-09-06 06:59:15 +03:00
|
|
|
export const listenGroup = (group: string): Poke<unknown> =>
|
|
|
|
groupHookAction({
|
|
|
|
listen: group
|
|
|
|
});
|
2021-02-25 06:54:00 +03:00
|
|
|
|
2021-09-06 06:59:15 +03:00
|
|
|
export const listenGraph = (graph: string, index: string): Poke<unknown> =>
|
|
|
|
graphHookAction({
|
|
|
|
listen: {
|
|
|
|
graph,
|
|
|
|
index
|
|
|
|
}
|
|
|
|
});
|
2021-06-14 04:59:22 +03:00
|
|
|
|
2021-09-06 06:59:15 +03:00
|
|
|
/**
|
2021-06-14 04:59:22 +03:00
|
|
|
* Read all graphs belonging to a particular group
|
|
|
|
*/
|
2021-09-06 06:59:15 +03:00
|
|
|
export const readGroup = (group: string) =>
|
2021-06-14 04:59:22 +03:00
|
|
|
harkAction({
|
|
|
|
'read-group': group
|
|
|
|
});
|
|
|
|
|
2021-09-06 06:59:15 +03:00
|
|
|
/**
|
2021-06-14 04:59:22 +03:00
|
|
|
* Read all unreads in a graph
|
|
|
|
*/
|
2021-09-06 06:59:15 +03:00
|
|
|
export const readGraph = (graph: string) =>
|
2021-06-14 04:59:22 +03:00
|
|
|
harkAction({
|
|
|
|
'read-graph': graph
|
|
|
|
});
|
|
|
|
|
2021-09-06 06:59:15 +03:00
|
|
|
export function harkBinToId(bin: HarkBin): HarkBinId {
|
|
|
|
const { place, path } = bin;
|
|
|
|
return `${place.desk}${place.path}${path}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function harkBinEq(a: HarkBin, b: HarkBin): boolean {
|
|
|
|
return (
|
|
|
|
a.place.path === b.place.path &&
|
|
|
|
a.place.desk === b.place.desk &&
|
|
|
|
a.path === b.path
|
|
|
|
);
|
|
|
|
}
|