interface: remove chat special-casing

This commit is contained in:
Liam Fitzgerald 2020-12-07 14:02:02 +10:00
parent 5cef1cfe70
commit b516926510
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
3 changed files with 14 additions and 45 deletions

View File

@ -50,53 +50,22 @@ export function ChannelMenu(props: ChannelMenuProps) {
const isOurs = ship.slice(1) === window.ship;
const isMuted = appIsGraph(app)
? props.graphNotificationConfig.watching.findIndex(
const isMuted =
props.graphNotificationConfig.watching.findIndex(
(a) => a.graph === appPath && a.index === "/"
) === -1
: props.chatNotificationConfig.findIndex((a) => a === appPath) === -1;
) === -1;
const onChangeMute = async () => {
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"];
switch (app) {
case "chat":
await api.chat.delete(appPath);
break;
case "publish":
await api.graph.leaveGraph(ship, name);
break;
case "link":
await api.graph.leaveGraph(ship, name);
break;
default:
throw new Error("Invalid app name");
}
await api.graph.leaveGraph(ship, name);
history.push(`/~landscape${workspace}`);
}, [api, association]);
const onDelete = useCallback(async () => {
const app = metadata.module || association["app-name"];
switch (app) {
case "chat":
await api.chat.delete(appPath);
break;
case "publish":
await api.graph.deleteGraph(name);
break;
case "link":
await api.graph.deleteGraph(name);
break;
default:
throw new Error("Invalid app name");
}
await api.graph.deleteGraph(name);
history.push(`/~landscape${workspace}`);
}, [api, association]);

View File

@ -14,7 +14,7 @@ import GlobalApi from '~/logic/api/global';
import { AsyncButton } from '~/views/components/AsyncButton';
import { FormError } from '~/views/components/FormError';
import { RouteComponentProps } from 'react-router-dom';
import { stringToSymbol, parentPath } from '~/logic/lib/util';
import { stringToSymbol, parentPath, deSig } from '~/logic/lib/util';
import { resourceFromPath } from '~/logic/lib/group';
import { Associations } from '~/types/metadata-update';
import { useWaitForProps } from '~/logic/lib/useWaitForProps';
@ -81,7 +81,7 @@ export function NewChannel(props: NewChannelProps & RouteComponentProps) {
resId,
name,
description,
{ invite: { pending: ships.map(s => `~${s}`) } },
{ invite: { pending: ships.map(s => `~${deSig(s)}`) } },
moduleType
);
}

View File

@ -3,11 +3,11 @@ import _ from 'lodash';
import { Icon, Row, Box, Text } from "@tlon/indigo-react";
import { Association } from "~/types/metadata-update";
import { SidebarAppConfigs, SidebarItemStatus } from "./Sidebar";
import { HoverBoxLink } from "~/views/components/HoverBox";
import { Groups } from "~/types";
import { Groups, Association } from "~/types";
import { cite } from "~/logic/lib/util";
function SidebarItemIndicator(props: { status?: SidebarItemStatus }) {
switch (props.status) {
@ -34,14 +34,14 @@ const getAppIcon = (app: string, mod: string) => {
return _.capitalize(app);
};
const DM_REGEX = /\/~([a-z]|-)*\/dm--/;
const DM_REGEX = /ship\/~([a-z]|-)*\/dm--/;
function getItemTitle(association: Association) {
if(DM_REGEX.test(association['app-path'])) {
const [,ship,name] = association['app-path'].split('/');
const [,,ship,name] = association['app-path'].split('/');
if(ship.slice(1) === window.ship) {
return `~${name.slice(4)}`;
return cite(`~${name.slice(4)}`);
}
return ship;
return cite(ship);
}
return association.metadata.title || association['app-path'];