chat + contacts: integrate managed groups with metadata

This commit is contained in:
Logan Allen 2020-03-01 15:35:44 -08:00
parent 3e235146ee
commit bb0f56f17a
17 changed files with 139 additions and 74 deletions

View File

@ -207,7 +207,13 @@
~
%- zing
:~ (create-chat app-path.act security.act allow-history.act)
(create-managed-group group-path.act security.act members.act)
%- create-managed-group
:* group-path.act
security.act
members.act
title.act
description.act
==
(create-metadata title.act description.act group-path.act app-path.act)
(create-security group-path.act security.act)
~[(permission-hook-poke [%add-owned group-path.act group-path.act])]
@ -248,7 +254,7 @@
==
::
++ create-managed-group
|= [=path security=rw-security ships=(set ship)]
|= [=path security=rw-security ships=(set ship) title=@t desc=@t]
^- (list card)
?^ (group-scry path) ~
:: do not create a managed group if this is a sig path or a blacklist
@ -256,7 +262,7 @@
?: =(security %channel)
~[(group-poke [%bundle path])]
?: (is-managed path)
~[(contact-view-poke [%create path ships])]
~[(contact-view-poke [%create path ships title desc])]
:~ (group-poke [%bundle path])
(group-poke [%add ships path])
==
@ -290,7 +296,7 @@
==
::
++ contact-view-poke
|= act=[%create =path ships=(set ship)]
|= act=[%create =path ships=(set ship) title=@t description=@t]
^- card
[%pass / %agent [our.bol %contact-view] %poke %contact-view-action !>(act)]
::

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,11 @@
:: contact-hook:
::
/- *group-store, *group-hook, *contact-hook, *invite-store
/- *group-store,
*group-hook,
*contact-hook,
*invite-store,
*metadata-hook,
*metadata-store
/+ *contact-json, default-agent
|%
+$ card card:agent:gall
@ -242,7 +247,10 @@
%delete
=. synced (~(del by synced) path.fact)
:_ state
[(group-poke [%unbundle path.fact])]~
:~ (group-poke [%unbundle path.fact])
(metadata-hook-poke [%remove path.fact])
(metadata-poke [%remove path.fact [%contacts path.fact]])
==
==
::
++ foreign
@ -352,7 +360,9 @@
(poke-hook-action [%add-synced ship.invite.fact path.invite.fact])
:-
%+ welp
[(group-hook-poke [%add ship.invite.fact path.invite.fact])]~
:~ (group-hook-poke [%add ship.invite.fact path.invite.fact])
(metadata-hook-poke [%add-synced ship.invite.fact path.invite.fact])
==
-.changes
+.changes
==
@ -377,6 +387,16 @@
^- card
[%pass / %agent [our.bol %group-store] %poke %group-action !>(act)]
::
++ metadata-poke
|= act=metadata-action
^- card
[%pass / %agent [our.bol %metadata-store] %poke %metadata-action !>(act)]
::
++ metadata-hook-poke
|= act=metadata-hook-action
^- card
[%pass / %agent [our.bol %metadata-hook] %poke %metadata-hook-action !>(act)]
::
++ contacts-scry
|= pax=path
^- (unit contacts)

View File

@ -1,7 +1,12 @@
:: contact-view: sets up contact JS client and combines commands
:: into semantic actions for the UI
::
/- *group-store, *group-hook, *invite-store, *contact-hook
/- *group-store,
*group-hook,
*invite-store,
*contact-hook,
*metadata-store,
*metadata-hook
/+ *server, *contact-json, base64, default-agent
/= index
/^ octs
@ -126,18 +131,22 @@
?- -.act
%create
?> ?=([@ *] path.act)
%+ weld
:~ (group-poke [%bundle path.act])
(contact-poke [%create path.act])
(contact-hook-poke [%add-owned path.act])
(group-hook-poke [%add our.bol path.act])
(group-poke [%add (~(put in ships.act) our.bol) path.act])
==
(create-metadata path.act title.act description.act)
::
%delete
%+ weld
:~ (group-poke [%unbundle path.act])
(contact-poke [%delete path.act])
(contact-hook-poke [%remove path.act])
==
(delete-metadata path.act)
::
%remove
:~ (group-poke [%remove [ship.act ~ ~] path.act])
@ -218,6 +227,37 @@
^- card
[%pass / %agent [our.bol %group-hook] %poke %group-hook-action !>(act)]
::
++ metadata-poke
|= act=metadata-action
^- card
[%pass / %agent [our.bol %metadata-store] %poke %metadata-action !>(act)]
::
++ metadata-hook-poke
|= act=metadata-hook-action
^- card
[%pass / %agent [our.bol %metadata-hook] %poke %metadata-hook-action !>(act)]
::
++ create-metadata
|= [=path title=@t description=@t]
^- (list card)
=/ =metadata
%* . *metadata
title title
description description
date-created now.bol
creator our.bol
==
:~ (metadata-poke [%add path [%contacts path] metadata])
(metadata-hook-poke [%add-owned path])
==
::
++ delete-metadata
|= =path
^- (list card)
:~ (metadata-poke [%remove path [%contacts path]])
(metadata-hook-poke [%remove path])
==
::
++ all-scry
^- rolodex
.^(rolodex %gx /=contact-store/(scot %da now.bol)/all/noun)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -196,7 +196,7 @@
=/ book=notebook-info
[title.old '' =(%open comments.old) / /]
=+ ^- [grp-car=(list card) write-pax=path read-pax=path]
(make-groups:main book-name group-pax ~ %.n %.n)
(make-groups:main book-name [group-pax ~ %.n %.n] '' '')
=. writers.book write-pax
=. subscribers.book read-pax
=/ inv-car (send-invites book-name (~(get ju old-subs) book-name))
@ -563,7 +563,7 @@
=+ ^- [grp-car=(list card) write-pax=path read-pax=path]
?: =(writers.new-book /)
=/ group-path /~/publish/(scot %p our.bol)/[book-name]
(make-groups book-name group-path ~ %.n %.n)
(make-groups book-name [group-path ~ %.n %.n] '' '')
[~ writers.info subscribers.info]
=. writers.new-book write-pax
=. subscribers.new-book read-pax
@ -876,7 +876,8 @@
[%pass / %agent [our.bol %group-hook] %poke %group-hook-action !>(act)]
::
++ contact-view-create
|= act=[%create path (set ship)]
|= [=path ships=(set ship) title=@t description=@t]
=/ act [%create path ships title description]
^- card
[%pass / %agent [our.bol %contact-view] %poke %contact-view-action !>(act)]
::
@ -923,18 +924,6 @@
(perm-group-hook-poke [%associate write [[write write-type] ~ ~]])
==
::
++ create-managed-group
|= [pax=path security=rw-security ships=(set ship)]
^- (list card)
=/ grp
.^((unit group) %gx ;:(weld /=group-store/(scot %da now.bol) pax /noun))
?^ grp
~
?> ?=(^ pax)
?: |(=('~' i.pax) !=(%village security))
[(group-poke [%bundle pax])]~
[(contact-view-create [%create pax ships])]~
::
++ generate-invites
|= [book=@tas invitees=(set ship)]
^- (list card)
@ -949,7 +938,7 @@
[%pass / %agent [our.bol %invite-hook] %poke %invite-action !>(act)]
::
++ make-groups
|= [book=@tas group=group-info]
|= [book=@tas group=group-info title=@t about=@t]
^- [(list card) write=path read=path]
?> ?=(^ group-path.group)
?: use-preexisting.group
@ -976,7 +965,7 @@
=/ whole-grp (~(put in invitees.group) our.bol)
:_ [group-path.group group-path.group]
%- zing
:~ [(contact-view-create [%create group-path.group whole-grp])]~
:~ [(contact-view-create [group-path.group whole-grp title about])]~
(create-security group-path.group group-path.group %village)
[(perm-hook-poke [%add-owned group-path.group group-path.group])]~
(generate-invites book (~(del in invitees.group) our.bol))
@ -1013,7 +1002,7 @@
?: (~(has by books) book.act)
~|("notebook already exists: {<book.act>}" !!)
=+ ^- [cards=(list card) write-pax=path read-pax=path]
(make-groups book.act group.act)
(make-groups book.act group.act title.act about.act)
=/ new-book=notebook-info
:* title.act
about.act
@ -1086,7 +1075,7 @@
=+ ^- [cards=(list card) write-pax=path read-pax=path]
?~ group.act
[~ writers.u.book subscribers.u.book]
(make-groups book.act u.group.act)
(make-groups book.act u.group.act title.act about.act)
=/ new-info=notebook-info
:* title.act
about.act

View File

@ -109,6 +109,8 @@
%- ot
:~ [%path pa]
[%ships (as (su ;~(pfix sig fed:ag)))]
[%title so]
[%description so]
==
::
++ delete (ot [%path pa]~)

View File

@ -3,7 +3,7 @@
+$ contact-view-action
$% :: %create: create in both groups and contacts
::
[%create =path ships=(set ship)]
[%create =path ships=(set ship) title=@t description=@t]
:: %remove: remove from both groups and contacts
::
[%remove =path =ship]

View File

@ -69,7 +69,14 @@ class UrbitApi {
}
contactCreate(path, ships = []) {
return this.contactViewAction({ create: { path, ships }});
return this.contactViewAction({
create: {
path,
ships,
title: '',
description: ''
}
});
}
groupAdd(path, ships = []) {

View File

@ -10,36 +10,35 @@ export class GroupDetail extends Component {
props.activeDrawer === "detail" ? "db" : "dn db-ns";
let groupPath = props.path || "";
let channelsForGroup = (groupPath in props.associations) ?
props.associations[groupPath] : {};
let groupChannels = props.associations.get(groupPath) || {};
let isEmpty = Object.keys(channelsForGroup).length === 0;
let channelList = (<div />);
let isEmpty = Object.entries(groupChannels).length === 0 &&
groupChannels.constructor === Object;
let channelList = <div/>
channelList = Object.keys(groupChannels).map((channel) => {
let channelObj = groupChannels[channel];
if (!channelObj) {
return false;
channelList = Object.keys(channelsForGroup).map((key) => {
let channel = channelsForGroup[key];
console.log(key, channel);
if (!('metadata' in channel)) {
return (<div />);
}
let title = channelObj.metadata.title || channelObj["app-path"] || "";
let color = uxToHex(channelObj.metadata.color) || "000000";
let app = channelObj["app-name"] || "Unknown";
let channelPath = channelObj["app-path"];
let title = channel.metadata.title || channel["app-path"] || "";
let color = uxToHex(channel.metadata.color) || "000000";
let app = channel["app-name"] || "Unknown";
let channelPath = channel["app-path"];
let link = `/~${app}/join${channelPath}`
app = app.charAt(0).toUpperCase() + app.slice(1)
return(
<li
key={channel}
className="f9 list flex pv2 w-100">
<li key={channel} className="f9 list flex pv2 w-100">
<div className="dib"
style={{backgroundColor: `#${color}`, height: 32, width: 32}}
></div>
<div className="flex flex-column flex-auto">
<p className="f9 inter ml2 w-100">{title}</p>
<p className="f9 inter ml2 w-100"
style={{marginTop: "0.35rem"}}>
style={{marginTop: "0.35rem"}}>
<span className="f9 di mr2 inter">{app}</span>
<a className="f9 di green2" href={link}>Open</a>
</p>
@ -51,9 +50,13 @@ export class GroupDetail extends Component {
let backLink = props.location.pathname;
backLink = backLink.slice(0, props.location.pathname.indexOf("/detail"));
let emptyGroup = <div className={isEmpty ? "dt w-100 h-100" : "dn"}>
<p className="gray2 f9 tc v-mid dtc">This group has no channels. To add a channel, invite this group using any application.</p>
</div>
let emptyGroup = (
<div className={isEmpty ? "dt w-100 h-100" : "dn"}>
<p className="gray2 f9 tc v-mid dtc">
This group has no channels. To add a channel, invite this group using any application.
</p>
</div>
);
return (
<div className={"h-100 w-100 overflow-x-hidden bg-white bg-gray0-d white-d pa4 "

View File

@ -34,7 +34,7 @@ export class Root extends Component {
let invites =
(!!state.invites && '/contacts' in state.invites) ?
state.invites['/contacts'] : {};
let associations = !! state.associations ? state.associations : new Map;
let associations = !! state.associations ? state.associations : {};
return (
<BrowserRouter>

View File

@ -12,17 +12,15 @@ export class MetadataReducer {
associations(json, state) {
let data = _.get(json, 'associations', false);
if (data) {
let metadata = new Map;
Object.keys(data).map((channel) => {
let channelObj = data[channel];
if (metadata.has(channelObj["group-path"])) {
let groupMetadata = metadata.get(channelObj["group-path"]);
groupMetadata[channel] = channelObj;
metadata.set(channelObj["group-path"], groupMetadata);
} else {
metadata.set(channelObj["group-path"], {[channel]: channelObj});
let metadata = {};
Object.keys(data).forEach((key) => {
let val = data[key];
let groupPath = val['group-path'];
if (!(groupPath in metadata)) {
metadata[groupPath] = {};
}
})
metadata[groupPath][key] = val;
});
state.associations = metadata;
}
}
@ -31,13 +29,13 @@ export class MetadataReducer {
let data = _.get(json, 'add', false);
if (data) {
let metadata = state.associations;
if (metadata.has(data["group-path"])) {
let groupMetadata = metadata.get(data["group-path"]);
groupMetadata[`${data["group-path"]}/${data["app-name"]}${data["app-path"]}`] = data;
} else {
metadata.set(data["group-path"], data);
if (!(data['group-path'] in metadata)) {
metadata[data['group-path']] = {};
}
metadata[data['group-path']]
[`${data["group-path"]}/${data["app-name"]}${data["app-path"]}`] = data;
state.associations = metadata;
}
}
}
}

View File

@ -12,7 +12,7 @@ class Store {
this.state = {
contacts: {},
groups: {},
associations: new Map,
associations: {},
permissions: {},
invites: {},
spinner: false