mirror of
https://github.com/urbit/shrub.git
synced 2025-01-04 18:43:46 +03:00
Merge pull request #2356 from urbit/os1-chat-integration
apps: main backend integration between metadata and chat
This commit is contained in:
commit
c5f1f0f7d2
@ -47,7 +47,7 @@
|
||||
::
|
||||
::
|
||||
:: create chat
|
||||
[%create nu-security path (unit glyph) (unit ?)]
|
||||
::[%create nu-security path (unit glyph) (unit ?)]
|
||||
[%delete path] :: delete chat
|
||||
[%invite path (set ship)] :: allow
|
||||
[%banish path (set ship)] :: disallow
|
||||
@ -368,7 +368,7 @@
|
||||
[%join leaf+";join ~ship/chat-name (glyph)"]
|
||||
[%leave leaf+";leave ~ship/chat-name"]
|
||||
::
|
||||
[%create leaf+";create [type] /chat-name (glyph)"]
|
||||
::[%create leaf+";create [type] /chat-name (glyph)"]
|
||||
[%delete leaf+";delete /chat-name"]
|
||||
[%invite leaf+";invite /chat-name ~ships"]
|
||||
[%banish leaf+";banish /chat-name ~ships"]
|
||||
@ -477,18 +477,18 @@
|
||||
;~ pose
|
||||
(stag %target tars)
|
||||
::
|
||||
;~ (glue ace)
|
||||
(tag %create)
|
||||
security
|
||||
;~ plug
|
||||
path
|
||||
(punt ;~(pfix ace glyph))
|
||||
(punt ;~(pfix ace (fuss 'y' 'n')))
|
||||
==
|
||||
==
|
||||
;~((glue ace) (tag %delete) path)
|
||||
;~((glue ace) (tag %invite) path ships)
|
||||
;~((glue ace) (tag %banish) path ships)
|
||||
:: ;~ (glue ace)
|
||||
:: (tag %create)
|
||||
:: security
|
||||
:: ;~ plug
|
||||
:: path
|
||||
:: (punt ;~(pfix ace glyph))
|
||||
:: (punt ;~(pfix ace (fuss 'y' 'n')))
|
||||
:: ==
|
||||
:: ==
|
||||
:: ;~((glue ace) (tag %delete) path)
|
||||
:: ;~((glue ace) (tag %invite) path ships)
|
||||
:: ;~((glue ace) (tag %banish) path ships)
|
||||
::
|
||||
;~ (glue ace)
|
||||
(tag %join)
|
||||
@ -683,7 +683,7 @@
|
||||
%say (say +.job)
|
||||
%eval (eval +.job)
|
||||
::
|
||||
%create (create +.job)
|
||||
:: %create (create +.job)
|
||||
%delete (delete +.job)
|
||||
%invite (change-permission & +.job)
|
||||
%banish (change-permission | +.job)
|
||||
@ -750,30 +750,30 @@
|
||||
[[prompt:sh-out ~] all-state]
|
||||
:: +create: new local mailbox
|
||||
::
|
||||
++ create
|
||||
|= [security=nu-security =path gyf=(unit char) allow-history=(unit ?)]
|
||||
^- (quip card state)
|
||||
::TODO check if already exists
|
||||
=/ =target [our-self path]
|
||||
=. audience [target ~ ~]
|
||||
=^ moz all-state
|
||||
?. ?=(^ gyf) [~ all-state]
|
||||
(bind-glyph u.gyf target)
|
||||
=- [[- moz] all-state]
|
||||
%^ act %do-create %chat-view
|
||||
:- %chat-view-action
|
||||
!> ^- chat-view-action
|
||||
:* %create
|
||||
path
|
||||
security
|
||||
:: ensure we can read from/write to our own chats
|
||||
::
|
||||
?- security
|
||||
%channel ~
|
||||
%village [our-self ~ ~]
|
||||
==
|
||||
(fall allow-history %.y)
|
||||
==
|
||||
::++ create
|
||||
:: |= [security=nu-security =path gyf=(unit char) allow-history=(unit ?)]
|
||||
:: ^- (quip card state)
|
||||
:: ::TODO check if already exists
|
||||
:: =/ =target [our-self path]
|
||||
:: =. audience [target ~ ~]
|
||||
:: =^ moz all-state
|
||||
:: ?. ?=(^ gyf) [~ all-state]
|
||||
:: (bind-glyph u.gyf target)
|
||||
:: =- [[- moz] all-state]
|
||||
:: %^ act %do-create %chat-view
|
||||
:: :- %chat-view-action
|
||||
:: !> ^- chat-view-action
|
||||
:: :* %create
|
||||
:: path
|
||||
:: security
|
||||
:: :: ensure we can read from/write to our own chats
|
||||
:: ::
|
||||
:: ?- security
|
||||
:: %channel ~
|
||||
:: %village [our-self ~ ~]
|
||||
:: ==
|
||||
:: (fall allow-history %.y)
|
||||
:: ==
|
||||
:: +delete: delete local chats
|
||||
::
|
||||
++ delete
|
||||
|
@ -413,14 +413,15 @@
|
||||
++ fact-invite-update
|
||||
|= [wir=wire fact=invite-update]
|
||||
^- (quip card _state)
|
||||
?+ -.fact
|
||||
[~ state]
|
||||
:_ state
|
||||
?+ -.fact ~
|
||||
::
|
||||
%accepted
|
||||
=/ ask-history ?~((chat-scry path.invite.fact) %.y %.n)
|
||||
:_ state
|
||||
[(chat-view-poke [%join ship.invite.fact path.invite.fact ask-history])]~
|
||||
==
|
||||
=* shp ship.invite.fact
|
||||
=* app-path path.invite.fact
|
||||
~[(chat-view-poke [%join shp app-path ask-history])]
|
||||
==
|
||||
::
|
||||
++ fact-permission-update
|
||||
|= [wir=wire fact=permission-update]
|
||||
|
@ -5,8 +5,10 @@
|
||||
*permission-hook,
|
||||
*group-store,
|
||||
*invite-store,
|
||||
*metadata-store,
|
||||
*permission-group-hook,
|
||||
*chat-hook
|
||||
*chat-hook,
|
||||
*metadata-hook
|
||||
/+ *server, *chat-json, default-agent, verb, dbug
|
||||
/= index
|
||||
/^ octs
|
||||
@ -52,8 +54,8 @@
|
||||
[%permission-group-hook-action permission-group-hook-action]
|
||||
==
|
||||
--
|
||||
%- agent:dbug
|
||||
%+ verb |
|
||||
%- agent:dbug
|
||||
^- agent:gall
|
||||
=<
|
||||
|_ bol=bowl:gall
|
||||
@ -199,39 +201,49 @@
|
||||
?> (team:title our.bol src.bol)
|
||||
?- -.act
|
||||
%create
|
||||
?> ?=(^ path.act)
|
||||
?^ (chat-scry path.act)
|
||||
?> ?=(^ app-path.act)
|
||||
?^ (chat-scry app-path.act)
|
||||
~& %chat-already-exists
|
||||
~
|
||||
%- zing
|
||||
:~ (create-chat path.act security.act allow-history.act)
|
||||
(create-managed-group path.act security.act members.act)
|
||||
(create-security path.act security.act)
|
||||
~[(permission-hook-poke [%add-owned path.act path.act])]
|
||||
:~ (create-chat app-path.act security.act allow-history.act)
|
||||
(create-managed-group group-path.act security.act members.act)
|
||||
(create-security group-path.act security.act)
|
||||
(create-metadata group-path.act app-path.act)
|
||||
~[(permission-hook-poke [%add-owned group-path.act group-path.act])]
|
||||
==
|
||||
::
|
||||
%delete
|
||||
?> ?=(^ path.act)
|
||||
=/ group-path (group-from-chat app-path.act)
|
||||
?> ?=(^ app-path.act)
|
||||
%- zing
|
||||
:~ :~ (chat-hook-poke [%remove path.act])
|
||||
(permission-hook-poke [%remove path.act])
|
||||
(chat-poke [%delete path.act])
|
||||
:~ :~ (chat-hook-poke [%remove app-path.act])
|
||||
(metadata-store-poke [%remove group-path [%chat app-path.act]])
|
||||
(chat-poke [%delete app-path.act])
|
||||
==
|
||||
::
|
||||
?: (is-managed group-path) ~
|
||||
:~ (permission-hook-poke [%remove group-path])
|
||||
(group-poke [%unbundle group-path])
|
||||
(metadata-hook-poke [%remove group-path])
|
||||
==
|
||||
?. =(i.path.act '~') ~
|
||||
~[(group-poke [%unbundle path.act])]
|
||||
==
|
||||
::
|
||||
%join
|
||||
:~ (chat-hook-poke [%add-synced ship.act path.act ask-history.act])
|
||||
(permission-hook-poke [%add-synced ship.act path.act])
|
||||
=/ group-path
|
||||
?. (is-managed app-path.act) app-path.act
|
||||
(group-from-chat app-path.act)
|
||||
:~ (chat-hook-poke [%add-synced ship.act app-path.act ask-history.act])
|
||||
(permission-hook-poke [%add-synced ship.act group-path])
|
||||
(metadata-hook-poke [%add-synced ship.act group-path])
|
||||
==
|
||||
==
|
||||
::
|
||||
++ create-chat
|
||||
|= [=path security=rw-security history=?]
|
||||
^- (list card)
|
||||
:~ [(chat-poke [%create path])]
|
||||
[(chat-hook-poke [%add-owned path security history])]
|
||||
:~ (chat-poke [%create path])
|
||||
(chat-hook-poke [%add-owned path security history])
|
||||
==
|
||||
::
|
||||
++ create-managed-group
|
||||
@ -249,6 +261,24 @@
|
||||
==
|
||||
~[(contact-view-poke [%create path ships])]
|
||||
::
|
||||
++ create-metadata
|
||||
|= [group-path=path app-path=path]
|
||||
^- (list card)
|
||||
~& group-path+group-path
|
||||
~& app-path+app-path
|
||||
~& is-managed+(is-managed app-path)
|
||||
=/ =metadata
|
||||
%* . *metadata
|
||||
date-created now.bol
|
||||
creator
|
||||
%+ slav %p
|
||||
?: (is-managed app-path) (snag 0 app-path)
|
||||
(snag 1 app-path)
|
||||
==
|
||||
:~ (metadata-store-poke [%add group-path [%chat app-path] metadata])
|
||||
(metadata-hook-poke [%add-owned group-path])
|
||||
==
|
||||
::
|
||||
++ create-security
|
||||
|= [pax=path sec=rw-security]
|
||||
^- (list card)
|
||||
@ -265,6 +295,20 @@
|
||||
^- card
|
||||
[%pass / %agent [our.bol %contact-view] %poke %contact-view-action !>(act)]
|
||||
::
|
||||
++ metadata-store-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)
|
||||
==
|
||||
::
|
||||
++ send-invite-poke
|
||||
|= [=path =ship]
|
||||
^- card
|
||||
@ -280,6 +324,32 @@
|
||||
^- (unit mailbox)
|
||||
=. pax ;:(weld /=chat-store/(scot %da now.bol)/mailbox pax /noun)
|
||||
.^((unit mailbox) %gx pax)
|
||||
::
|
||||
++ group-from-chat
|
||||
|= app-path=path
|
||||
^- path
|
||||
?. .^(? %gu (scot %p our.bol) %metadata-store (scot %da now.bol) ~)
|
||||
?: ?=([@ ^] app-path)
|
||||
~& [%assuming-ported-legacy-chat app-path]
|
||||
[%'~' app-path]
|
||||
~& [%weird-chat app-path]
|
||||
!!
|
||||
=/ resource-indices
|
||||
.^ (jug resource group-path)
|
||||
%gy
|
||||
(scot %p our.bol)
|
||||
%metadata-store
|
||||
(scot %da now.bol)
|
||||
/resource-indices
|
||||
==
|
||||
=/ groups=(set path) (~(got by resource-indices) [%chat app-path])
|
||||
(snag 0 ~(tap in groups))
|
||||
::
|
||||
++ is-managed
|
||||
|= =path
|
||||
^- ?
|
||||
?> ?=(^ path)
|
||||
!=(i.path '~')
|
||||
--
|
||||
::
|
||||
++ diff-chat-update
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -21,8 +21,7 @@
|
||||
:: /app-name/%app-name associations for app
|
||||
:: /group/%group-path associations for group
|
||||
::
|
||||
/- *metadata-store
|
||||
/+ default-agent, dbug
|
||||
/+ *metadata-json, default-agent, verb, dbug
|
||||
|%
|
||||
+$ card card:agent:gall
|
||||
::
|
||||
@ -41,6 +40,7 @@
|
||||
::
|
||||
=| state-zero
|
||||
=* state -
|
||||
%+ verb |
|
||||
%- agent:dbug
|
||||
^- agent:gall
|
||||
=<
|
||||
|
@ -224,19 +224,20 @@
|
||||
::
|
||||
++ create
|
||||
%- ot
|
||||
:~ [%path pa]
|
||||
:~ [%app-path pa]
|
||||
[%group-path pa]
|
||||
[%security sec]
|
||||
[%members (as (su ;~(pfix sig fed:ag)))]
|
||||
[%allow-history bo]
|
||||
==
|
||||
::
|
||||
++ delete
|
||||
(ot [%path pa]~)
|
||||
(ot [%app-path pa]~)
|
||||
::
|
||||
++ join
|
||||
%- ot
|
||||
:~ [%ship (su ;~(pfix sig fed:ag))]
|
||||
[%path pa]
|
||||
[%app-path pa]
|
||||
[%ask-history bo]
|
||||
==
|
||||
::
|
||||
|
73
pkg/arvo/lib/metadata-json.hoon
Normal file
73
pkg/arvo/lib/metadata-json.hoon
Normal file
@ -0,0 +1,73 @@
|
||||
/- *metadata-store
|
||||
|%
|
||||
++ associations-to-json
|
||||
|= =associations
|
||||
=, enjs:format
|
||||
^- json
|
||||
%- pairs
|
||||
%+ turn ~(tap by associations)
|
||||
|= [[=group-path =resource] =metadata]
|
||||
^- [cord json]
|
||||
:-
|
||||
%- crip
|
||||
;: weld
|
||||
(trip (spat group-path))
|
||||
(weld "/" (trip app-name.resource))
|
||||
(trip (spat app-path.resource))
|
||||
==
|
||||
%- pairs
|
||||
:~ [%group-path (path group-path)]
|
||||
[%app-name s+app-name.resource]
|
||||
[%app-path (path app-path.resource)]
|
||||
[%metadata (metadata-to-json metadata)]
|
||||
==
|
||||
::
|
||||
++ metadata-to-json
|
||||
|= met=metadata
|
||||
^- json
|
||||
=, enjs:format
|
||||
%- pairs
|
||||
:~ [%title s+title.met]
|
||||
[%description s+description.met]
|
||||
[%color s+(scot %ux color.met)]
|
||||
[%date-created s+(scot %da date-created.met)]
|
||||
[%creator s+(scot %p creator.met)]
|
||||
==
|
||||
::
|
||||
++ update-to-json
|
||||
|= upd=metadata-update
|
||||
=, enjs:format
|
||||
^- json
|
||||
%+ frond %metadata-update
|
||||
%- pairs
|
||||
:~ ?- -.upd
|
||||
%add
|
||||
:- %add
|
||||
%- pairs
|
||||
:~ [%group-path (path group-path.upd)]
|
||||
[%app-name s+app-name.resource.upd]
|
||||
[%app-path (path app-path.resource.upd)]
|
||||
[%metadata (metadata-to-json metadata.upd)]
|
||||
==
|
||||
::
|
||||
%update-metadata
|
||||
:- %update-metadata
|
||||
%- pairs
|
||||
:~ [%group-path (path group-path.upd)]
|
||||
[%app-name s+app-name.resource.upd]
|
||||
[%app-path (path app-path.resource.upd)]
|
||||
[%metadata (metadata-to-json metadata.upd)]
|
||||
==
|
||||
::
|
||||
%remove
|
||||
:- %remove
|
||||
%- pairs
|
||||
:~ [%group-path (path group-path.upd)]
|
||||
[%app-name s+app-name.resource.upd]
|
||||
[%app-path (path app-path.resource.upd)]
|
||||
==
|
||||
::
|
||||
%associations
|
||||
[%associations (associations-to-json associations.upd)]
|
||||
== ==
|
||||
--
|
13
pkg/arvo/mar/metadata/update.hoon
Normal file
13
pkg/arvo/mar/metadata/update.hoon
Normal file
@ -0,0 +1,13 @@
|
||||
/+ *metadata-json
|
||||
|_ upd=metadata-update
|
||||
++ grow
|
||||
|%
|
||||
++ json (update-to-json upd)
|
||||
--
|
||||
::
|
||||
++ grab
|
||||
|%
|
||||
++ noun metadata-update
|
||||
--
|
||||
::
|
||||
--
|
@ -2,12 +2,13 @@
|
||||
|%
|
||||
+$ chat-view-action
|
||||
$% $: %create
|
||||
=path
|
||||
app-path=path
|
||||
group-path=path
|
||||
security=rw-security
|
||||
members=(set ship)
|
||||
allow-history=?
|
||||
==
|
||||
[%delete =path]
|
||||
[%join =ship =path ask-history=?]
|
||||
[%delete app-path=path]
|
||||
[%join =ship app-path=path ask-history=?]
|
||||
==
|
||||
--
|
||||
|
@ -128,23 +128,27 @@ class UrbitApi {
|
||||
return this.action("chat-view", "json", data);
|
||||
}
|
||||
|
||||
chatViewCreate(path, security, members, allowHistory) {
|
||||
chatViewCreate(appPath, groupPath, security, members, allowHistory) {
|
||||
return this.chatViewAction({
|
||||
create: {
|
||||
path, security, members,
|
||||
'app-path': appPath,
|
||||
'group-path': groupPath,
|
||||
security,
|
||||
members,
|
||||
'allow-history': allowHistory
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
chatViewDelete(path) {
|
||||
this.chatViewAction({ delete: { path } });
|
||||
this.chatViewAction({ delete: { 'app-path': path } });
|
||||
}
|
||||
|
||||
chatViewJoin(ship, path, askHistory) {
|
||||
this.chatViewAction({
|
||||
join: {
|
||||
ship, path,
|
||||
ship,
|
||||
'app-path': path,
|
||||
'ask-history': askHistory
|
||||
}
|
||||
});
|
||||
|
@ -20,7 +20,6 @@ export class NewScreen extends Component {
|
||||
createGroup: true
|
||||
};
|
||||
|
||||
this.idName = React.createRef();
|
||||
this.idChange = this.idChange.bind(this);
|
||||
this.securityChange = this.securityChange.bind(this);
|
||||
this.allowHistoryChange = this.allowHistoryChange.bind(this);
|
||||
@ -46,20 +45,10 @@ export class NewScreen extends Component {
|
||||
}
|
||||
|
||||
setInvite(value) {
|
||||
if (value.groups.length > 0) {
|
||||
let idName = value.groups[0].split('/')[2];
|
||||
this.idName.current.value = idName;
|
||||
this.setState({
|
||||
idName,
|
||||
groups: value.groups,
|
||||
ships: value.ships
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
groups: value.groups,
|
||||
ships: value.ships
|
||||
});
|
||||
}
|
||||
this.setState({
|
||||
groups: value.groups,
|
||||
ships: value.ships
|
||||
});
|
||||
}
|
||||
|
||||
securityChange(event) {
|
||||
@ -149,17 +138,25 @@ export class NewScreen extends Component {
|
||||
// if we want a "proper group" that can be managed from the contacts UI,
|
||||
// we make a path of the form /~zod/cool-group
|
||||
// if not, we make a path of the form /~/~zod/free-chat
|
||||
let chatPath = `/~${window.ship}${station}`;
|
||||
let appPath = `/~${window.ship}${station}`;
|
||||
if (!state.createGroup && state.groups.length === 0) {
|
||||
chatPath = `/~${chatPath}`;
|
||||
appPath = `/~${appPath}`;
|
||||
}
|
||||
let groupPath = appPath;
|
||||
if (state.groups.length > 0) {
|
||||
groupPath = state.groups[0];
|
||||
}
|
||||
let submit = props.api.chatView.create(
|
||||
chatPath, state.security, aud, state.allowHistory
|
||||
);
|
||||
submit.then(() => {
|
||||
props.api.setSpinner(false);
|
||||
props.history.push(`/~chat/room${chatPath}`);
|
||||
})
|
||||
appPath,
|
||||
groupPath,
|
||||
state.security,
|
||||
aud,
|
||||
state.allowHistory
|
||||
);
|
||||
submit.then(() => {
|
||||
props.api.setSpinner(false);
|
||||
props.history.push(`/~chat/room${appPath}`);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
@ -183,9 +180,6 @@ export class NewScreen extends Component {
|
||||
let idClasses =
|
||||
"f7 ba b--gray3 b--gray2-d bg-gray0-d white-d pa3 db w-100 " +
|
||||
"focus-b--black focus-b--white-d ";
|
||||
if (state.groups.length > 0) {
|
||||
idClasses = idClasses + " o-40";
|
||||
}
|
||||
|
||||
let idErrElem = (<span />);
|
||||
if (state.idError) {
|
||||
@ -237,8 +231,6 @@ export class NewScreen extends Component {
|
||||
resize: "none"
|
||||
}}
|
||||
onChange={this.idChange}
|
||||
ref={this.idName}
|
||||
disabled={(state.groups.length > 0) ? "disabled" : false}
|
||||
/>
|
||||
{idErrElem}
|
||||
<p className="f8 mt4 lh-copy db">
|
||||
|
@ -34,6 +34,10 @@ export class Subscription {
|
||||
this.handleEvent.bind(this),
|
||||
this.handleError.bind(this),
|
||||
this.handleQuitAndResubscribe.bind(this));
|
||||
api.bind('/app-name/chat', 'PUT', api.authTokens.ship, 'metadata-store',
|
||||
this.handleEvent.bind(this),
|
||||
this.handleError.bind(this),
|
||||
this.handleQuitAndResubscribe.bind(this));
|
||||
}
|
||||
|
||||
handleEvent(diff) {
|
||||
|
Loading…
Reference in New Issue
Block a user