hark: optimistic archive

This commit is contained in:
Liam Fitzgerald 2021-05-13 09:57:52 +10:00
parent a8581ed81e
commit a40ca44050
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
3 changed files with 15 additions and 5 deletions

View File

@ -1,7 +1,10 @@
import { Association, GraphNotifDescription, IndexedNotification, NotifIndex } from '@urbit/api';
import BigIntOrderedMap from '@urbit/api/lib/BigIntOrderedMap';
import { BigInteger } from 'big-integer';
import { getParentIndex } from '../lib/notification';
import { dateToDa, decToUd } from '../lib/util';
import {reduce} from '../reducers/hark-update';
import {doOptimistically, optReduceState} from '../state/base';
import useHarkState from '../state/hark';
import { StoreState } from '../store/type';
import BaseApi from './base';
@ -51,8 +54,15 @@ export class HarkApi extends BaseApi<StoreState> {
});
}
archive(time: BigInteger, index: NotifIndex) {
return this.actOnNotification('archive', time, index);
async archive(intTime: BigInteger, index: NotifIndex) {
const time = decToUd(intTime.toString());
const action = {
archive: {
time,
index
}
};
await doOptimistically(useHarkState, action, this.harkAction.bind(this), [reduce])
}
read(time: BigInteger, index: NotifIndex) {

View File

@ -35,7 +35,7 @@ export const HarkReducer = (json: any) => {
}
};
function reduce(data, state) {
export function reduce(data, state) {
const reducers = [
calculateCount,
unread,

View File

@ -1,11 +1,11 @@
import { NotificationGraphConfig, Timebox, Unreads } from '@urbit/api';
import BigIntOrderedMap from '@urbit/api/lib/BigIntOrderedMap';
// import { harkGraphHookReducer, harkGroupHookReducer, harkReducer } from "~/logic/subscription/hark";
import { BaseState, createState } from './base';
import { createState } from './base';
export const HARK_FETCH_MORE_COUNT = 3;
export interface HarkState extends BaseState<HarkState> {
export interface HarkState {
archivedNotifications: BigIntOrderedMap<Timebox>;
doNotDisturb: boolean;
// getMore: () => Promise<boolean>;