diff --git a/pkg/interface/src/logic/api/graph.ts b/pkg/interface/src/logic/api/graph.ts index d3638a1f7..aba70dacf 100644 --- a/pkg/interface/src/logic/api/graph.ts +++ b/pkg/interface/src/logic/api/graph.ts @@ -274,7 +274,7 @@ export default class GraphApi extends BaseApi { async disableGroupFeed(group: Resource): Promise { await this.spider( 'graph-view-action', - 'resource', + 'json', 'graph-disable-group-feed', { "disable-group-feed": { resource: group } diff --git a/pkg/interface/src/views/landscape/components/GroupSettings/Channels.tsx b/pkg/interface/src/views/landscape/components/GroupSettings/Channels.tsx index f2ae0f217..47a25addd 100644 --- a/pkg/interface/src/views/landscape/components/GroupSettings/Channels.tsx +++ b/pkg/interface/src/views/landscape/components/GroupSettings/Channels.tsx @@ -47,7 +47,7 @@ export function GroupChannelSettings(props: GroupChannelSettingsProps) { Pinning a channel marks it as featured when joining or previewing a group. - {channels.map(({ resource, metadata }) => ( + {channels.filter(({ metadata }) => !metadata.hidden).map(({ resource, metadata }) => ( diff --git a/pkg/interface/src/views/landscape/components/GroupSettings/GroupFeed.tsx b/pkg/interface/src/views/landscape/components/GroupSettings/GroupFeed.tsx index a0a2cc514..f4ca2a692 100644 --- a/pkg/interface/src/views/landscape/components/GroupSettings/GroupFeed.tsx +++ b/pkg/interface/src/views/landscape/components/GroupSettings/GroupFeed.tsx @@ -1,6 +1,6 @@ import React from "react"; import { Box, Col, Row, Text, BaseLabel, Label } from "@tlon/indigo-react"; -import { Association, resourceFromPath, Group } from "@urbit/api"; +import { Association, resourceFromPath, Group, PermVariation } from "@urbit/api"; import GlobalApi from "~/logic/api/global"; import { Formik, Form, FormikHelpers } from "formik"; import { @@ -9,9 +9,10 @@ import { } from "../Home/Post/GroupFeedPerms"; import { FormSubmit } from "~/views/components/FormSubmit"; import { StatelessAsyncToggle } from "~/views/components/StatelessAsyncToggle"; +import useMetadataState from "~/logic/state/metadata"; interface FormSchema { - permissions: GroupFeedPermissions; + permissions: PermVariation; } export function GroupFeedSettings(props: { @@ -23,6 +24,7 @@ export function GroupFeedSettings(props: { const isEnabled = !!association?.metadata?.config?.group; const resource = resourceFromPath(association.group); const feedResource = association?.metadata.config?.group?.resource; + const feedAssoc = useMetadataState(s => s.associations.graph[feedResource]); const toggleFeed = async () => { if (isEnabled) { await api.graph.disableGroupFeed(resource); @@ -30,33 +32,17 @@ export function GroupFeedSettings(props: { await api.graph.enableGroupFeed(resource); } }; - const writers: Set | undefined = - group.tags.graph?.[feedResource]?.writers; + const vip = feedAssoc?.metadata?.vip || " "; const initialValues: FormSchema = { - permissions: !writers - ? "everyone" - : writers.size === 1 && writers.has(window.ship) - ? "host" - : "admins", + permissions: vip }; + const onSubmit = async ( values: FormSchema, actions: FormikHelpers ) => { - const tag = { - app: "graph", - resource: association.metadata.config?.group.resource, - tag: "writers", - }; + await api.metadata.update(feedAssoc, { vip: values.permissions.trim() }); - if (values.permissions === "admins") { - const admins = - Array.from(group.tags?.role?.admin).map((s) => `~${s}`) ?? []; - - await api.groups.addTag(resource, tag, admins); - } else if (values.permissions === "host") { - await api.groups.addTag(resource, tag, [`~${window.ship}`]); - } actions.setStatus({ success: null }); }; return ( diff --git a/pkg/interface/src/views/landscape/components/Home/EnableGroupFeed.tsx b/pkg/interface/src/views/landscape/components/Home/EnableGroupFeed.tsx index 985eed3a2..e5e983654 100644 --- a/pkg/interface/src/views/landscape/components/Home/EnableGroupFeed.tsx +++ b/pkg/interface/src/views/landscape/components/Home/EnableGroupFeed.tsx @@ -11,6 +11,7 @@ import GlobalApi from "~/logic/api/global"; import { resourceFromPath, Tag, resourceAsPath } from "@urbit/api"; import useGroupState, { useGroup } from "~/logic/state/group"; import { useHistory } from 'react-router-dom'; +import useMetadataState from "~/logic/state/metadata"; interface FormSchema { @@ -32,33 +33,15 @@ export function EnableGroupFeed(props: { const initialValues: FormSchema = { permissions: "everyone", }; - const group = useGroup(groupPath); - const onSubmit = useCallback( + const onSubmit = async (values: FormSchema, actions: FormikHelpers) => { const resource = resourceFromPath(groupPath); - const vip = ( - values.permissions === 'host' || values.permissions === 'admins' - ) ? 'reader-comments' : ''; const feed = resourceAsPath( - await api.graph.enableGroupFeed(resource, vip) + await api.graph.enableGroupFeed(resource, values.permissions.trim()) ); - const tag: Tag = { - app: "graph", - resource: feed, - tag: "writers", - }; - if (values.permissions === "admins") { - const admins = - Array.from(group.tags?.role?.admin).map((s) => `~${s}`) ?? []; - await api.groups.addTag(resource, tag, admins); - } else if (values.permissions === "host") { - await api.groups.addTag(resource, tag, [`~${window.ship}`]); - } actions.setStatus({ success: null }); history.replace(`${baseUrl}/feed`); - }, - [groupPath, baseUrl] - ); + }; return ( diff --git a/pkg/interface/src/views/landscape/components/Home/GroupFeedHeader.js b/pkg/interface/src/views/landscape/components/Home/GroupFeedHeader.js index 87f40a14f..ddd80476d 100644 --- a/pkg/interface/src/views/landscape/components/Home/GroupFeedHeader.js +++ b/pkg/interface/src/views/landscape/components/Home/GroupFeedHeader.js @@ -37,9 +37,11 @@ export function GroupFeedHeader(props) { authorText = node.post.author; } - const permText = ( - vip === 'reader-comments' - ) ? 'Select ships can post' : 'Everyone can post'; + const permText = (vip === 'host-feed') + ? 'Only host can post' + : vip === 'admin-feed' + ? 'Only admins can post' + : 'Everyone can post'; return ( Permissions diff --git a/pkg/interface/src/views/landscape/components/Home/Post/PostInput.js b/pkg/interface/src/views/landscape/components/Home/Post/PostInput.js index dff2abd30..047d3b177 100644 --- a/pkg/interface/src/views/landscape/components/Home/Post/PostInput.js +++ b/pkg/interface/src/views/landscape/components/Home/Post/PostInput.js @@ -7,7 +7,7 @@ import tokenizeMessage from '~/logic/lib/tokenizeMessage'; import { useToggleState } from '~/logic/lib/useToggleState'; import { createPost } from '~/logic/api/graph'; import useStorage from '~/logic/lib/useStorage'; -import { resourceFromPath, isWriter } from '~/logic/lib/group'; +import { resourceFromPath, isWriter, isChannelAdmin, isHost } from '~/logic/lib/group'; function canWrite(props) { const { group, association, vip, index } = props; @@ -15,8 +15,11 @@ function canWrite(props) { return true; } - if (!!index) { - return true; + if(vip === 'admin-feed') { + return isChannelAdmin(group, association.group); + } + if(vip === 'host-feed') { + return isHost(association.group); } return isWriter(group, association.resource); diff --git a/pkg/npm/api/metadata/types.ts b/pkg/npm/api/metadata/types.ts index 4bcd07691..32211e037 100644 --- a/pkg/npm/api/metadata/types.ts +++ b/pkg/npm/api/metadata/types.ts @@ -73,4 +73,4 @@ export interface Metadata { vip: PermVariation; } -export type PermVariation = '' | 'reader-comments' | 'member-metadata'; +export type PermVariation = '' | 'reader-comments' | 'member-metadata' | 'host-feed' | 'admin-feed';