notifications: cleaned up

This commit is contained in:
Tyler Brown Cifu Shuster 2021-05-13 05:36:05 -07:00
parent 3699f72f83
commit bd05760e9a
4 changed files with 18 additions and 19 deletions

View File

@ -1,8 +1,8 @@
import { GraphNotifIndex, GroupNotifIndex, IndexedNotification, NotificationGraphConfig, NotifIndex, Post, Unreads } from '@urbit/api';
import { GraphNotifIndex, GroupNotifIndex, IndexedNotification, NotificationGraphConfig, Post, Unreads } from '@urbit/api';
import bigInt, { BigInteger } from 'big-integer';
import f from 'lodash/fp';
import {pluralize} from './util';
import _ from 'lodash';
import f from 'lodash/fp';
import { pluralize } from './util';
export function getLastSeen(
unreads: Unreads,

View File

@ -438,6 +438,10 @@ export function getItemTitle(association: Association): string {
return association.metadata.title ?? association.resource ?? '';
}
export const svgDataURL = (svg) => 'data:image/svg+xml;base64,' + btoa(svg);
export const svgBlobURL = (svg) => URL.createObjectURL(new Blob([svg], { type: 'image/svg+xml' }));
export const favicon = () => {
let background = '#ffffff';
const contacts = useContactState.getState().contacts;
@ -451,7 +455,5 @@ export const favicon = () => {
size: 16,
colors: [background, foreground]
});
const dataurl = 'data:image/svg+xml;base64,' + btoa(svg);
console.log(dataurl);
return dataurl;
return svg;
}

View File

@ -6,8 +6,8 @@ import BigIntOrderedMap from '@urbit/api/lib/BigIntOrderedMap';
import { BigInteger } from 'big-integer';
import _ from 'lodash';
import { compose } from 'lodash/fp';
import { favicon, makePatDa } from '~/logic/lib/util';
import {describeNotification, notificationReferent} from '../lib/hark';
import { makePatDa } from '~/logic/lib/util';
import { describeNotification } from '../lib/hark';
import { reduceState } from '../state/base';
import useHarkState, { HarkState } from '../state/hark';
import useMetadataState from '../state/metadata';
@ -38,7 +38,6 @@ export const HarkReducer = (json: any) => {
};
function reduce(data, state) {
console.log(data);
const reducers = [
calculateCount,
unread,
@ -321,22 +320,20 @@ function updateNotificationStats(state: HarkState, index: NotifIndex, statField:
function added(json: any, state: HarkState): HarkState {
const data = _.get(json, 'added', false);
if (data) {
console.log('adding')
const { index, notification } = data;
const time = makePatDa(data.time);
if (true || !useHarkState.getState().doNotDisturb) {
console.log('showing');
if (!useHarkState.getState().doNotDisturb) {
const description = describeNotification(data);
const meta = useMetadataState.getState();
const referent = 'graph' in data.index ? meta.associations.graph[data.index.graph.graph]?.metadata?.title ?? data.index.graph : meta.associations.groups[data.index.group.group]?.metadata?.title ?? data.index.group;
new Notification(`${description} ${referent}`, {
tag: 'landscape',
image: 'https://media.urbit.org/logo/logo-black-600x600.jpg',
icon: 'https://media.urbit.org/logo/logo-black-600x600.jpg',
badge: 'https://media.urbit.org/logo/logo-black-600x600.jpg',
image: '/img/favicon.png',
icon: '/img/favicon.png',
badge: '/img/favicon.png',
renotify: true
});
console.log('showed');
}
const timebox = state.notifications.get(time) || [];

View File

@ -10,7 +10,7 @@ import { BrowserRouter as Router, withRouter } from 'react-router-dom';
import styled, { ThemeProvider } from 'styled-components';
import GlobalApi from '~/logic/api/global';
import gcpManager from '~/logic/lib/gcpManager';
import { favicon } from '~/logic/lib/util';
import { favicon, svgDataURL } from '~/logic/lib/util';
import withState from '~/logic/lib/withState';
import useContactState from '~/logic/state/contact';
import useGroupState from '~/logic/state/group';
@ -142,7 +142,7 @@ class App extends React.Component {
<ThemeProvider theme={theme}>
<Helmet>
{window.ship.length < 14
? <link rel="icon" type="image/svg+xml" href={favicon()} />
? <link rel="icon" type="image/svg+xml" href={svgDataURL(favicon())} />
: null}
</Helmet>
<Root>