From 2f7e8fd8116dc0c8b20bc7282784fa35bc51901d Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Tue, 21 Apr 2020 15:29:47 -0400 Subject: [PATCH 1/3] contacts: added "url" avatar support and finished "octet" avatar fetching support --- pkg/arvo/app/contact-store.hoon | 32 +++++++-- pkg/arvo/lib/contact-json.hoon | 72 +++++++++++++------ pkg/arvo/sur/contact-store.hoon | 22 +++++- .../src/js/components/lib/contact-card.js | 10 --- 4 files changed, 96 insertions(+), 40 deletions(-) diff --git a/pkg/arvo/app/contact-store.hoon b/pkg/arvo/app/contact-store.hoon index 7792e7918..c151f7121 100644 --- a/pkg/arvo/app/contact-store.hoon +++ b/pkg/arvo/app/contact-store.hoon @@ -5,18 +5,20 @@ +$ card card:agent:gall +$ versioned-state $% state-zero + state-one == :: +$ state-zero $: %0 - =rolodex + rolodex=rolodex-0 == -+$ diff - $% [%contact-update contact-update] ++$ state-one + $: %1 + =rolodex == -- :: -=| state-zero +=| state-one =* state - %- agent:dbug ^- agent:gall @@ -30,8 +32,26 @@ ++ on-init on-init:def ++ on-save !>(state) ++ on-load - |= old=vase - `this(state !<(state-zero old)) + |= old-vase=vase + =/ old !<(versioned-state old-vase) + ?: ?=(%1 -.old) + [~ this(state old)] + =/ new-rolodex=^rolodex + %- ~(run by rolodex.old) + |= cons=contacts-0 + ^- contacts + %- ~(run by cons) + |= con=contact-0 + ^- contact + :* nickname.con + email.con + phone.con + website.con + notes.con + color.con + ~ + == + [~ this(state [%1 new-rolodex])] :: ++ on-poke |= [=mark =vase] diff --git a/pkg/arvo/lib/contact-json.hoon b/pkg/arvo/lib/contact-json.hoon index c212e2708..2be8a96cf 100644 --- a/pkg/arvo/lib/contact-json.hoon +++ b/pkg/arvo/lib/contact-json.hoon @@ -15,38 +15,34 @@ |= [pax=^path =contacts] ^- [cord json] :- (spat pax) - (contacts-to-json contacts) + (contacts-to-json pax contacts) :: ++ contacts-to-json - |= con=contacts + |= [=path con=contacts] ^- json - =, enjs:format - %- pairs + %- pairs:enjs:format %+ turn ~(tap by con) - |= [shp=^ship =contact] + |= [=ship =contact] ^- [cord json] - :- (crip (slag 1 (scow %p shp))) - (contact-to-json contact) + [(crip (slag 1 (scow %p ship))) (contact-to-json path ship contact)] :: ++ contact-to-json - |= con=contact + |= [=path =ship con=contact] ^- json - =, enjs:format - %- pairs + %- pairs:enjs:format :~ [%nickname s+nickname.con] [%email s+email.con] [%phone s+phone.con] [%website s+website.con] [%notes s+notes.con] [%color s+(scot %ux color.con)] - [%avatar s+'TODO'] + [%avatar (avatar-to-json path ship avatar.con)] == :: ++ edit-to-json - |= edit=edit-field + |= [=path =ship edit=edit-field] ^- json - =, enjs:format - %+ frond -.edit + %+ frond:enjs:format -.edit ?- -.edit %nickname s+nickname.edit %email s+email.edit @@ -54,7 +50,27 @@ %website s+website.edit %notes s+notes.edit %color s+(scot %ux color.edit) - %avatar s+'TODO' + %avatar (avatar-to-json path ship avatar.edit) + == +:: +++ avatar-to-json + |= [=path =ship avat=(unit avatar)] + ^- json + ?~ avat ~ + ?- -.u.avat + %octt + :- %s + %- crip + %- zing + :~ "/~groups/img" + (trip (spat path)) + "/" + (trip (scot %p ship)) + "." + (trip file-extension.u.avat) + == + :: + %url s+url.u.avat == :: ++ update-to-json @@ -73,7 +89,7 @@ %- pairs :~ [%path (path path.upd)] [%ship (ship ship.upd)] - [%contact (contact-to-json contact.upd)] + [%contact (contact-to-json path.upd ship.upd contact.upd)] == ?: ?=(%remove -.upd) :- %remove @@ -86,7 +102,7 @@ %- pairs :~ [%path (path path.upd)] [%ship (ship ship.upd)] - [%edit-field (edit-to-json edit-field.upd)] + [%edit-field (edit-to-json path.upd ship.upd edit-field.upd)] == [*@t *^json] == @@ -179,10 +195,24 @@ == :: ++ avat - %- ot:dejs:format - :~ [%content-type so:dejs:format] - [%octs octet] - == + |= jon=json + ^- avatar + =< (parse-json jon) + |% + ++ parse-json + %- of:dejs:format + :~ [%octt octt] + [%url url] + == + :: + ++ octt + %- ot:dejs:format + :~ [%file-extension so:dejs:format] + [%octs octet] + == + :: + ++ url so:dejs:format + -- :: ++ cont %- ot:dejs:format diff --git a/pkg/arvo/sur/contact-store.hoon b/pkg/arvo/sur/contact-store.hoon index 7c5bae968..706ed3e63 100644 --- a/pkg/arvo/sur/contact-store.hoon +++ b/pkg/arvo/sur/contact-store.hoon @@ -1,10 +1,26 @@ /- *identity |% -+$ rolodex (map path contacts) ++$ rolodex-0 (map path contacts-0) ++$ rolodex (map path contacts) :: -+$ contacts (map ship contact) ++$ contacts-0 (map ship contact-0) ++$ contacts (map ship contact) :: -+$ avatar [content-type=@t octs=[p=@ud q=@t]] ++$ avatar-0 [content-type=@t octs=[p=@ud q=@t]] ++$ avatar + $% [%octt [file-extension=@t octs=[p=@ud q=@t]]] + [%url url=@t] + == +:: ++$ contact-0 + $: nickname=@t + email=@t + phone=@t + website=@t + notes=@t + color=@ux + avatar=(unit avatar-0) + == :: +$ contact $: nickname=@t diff --git a/pkg/interface/groups/src/js/components/lib/contact-card.js b/pkg/interface/groups/src/js/components/lib/contact-card.js index d02e5ddb4..b8ddee177 100644 --- a/pkg/interface/groups/src/js/components/lib/contact-card.js +++ b/pkg/interface/groups/src/js/components/lib/contact-card.js @@ -379,15 +379,6 @@ export class ContactCard extends Component { ); } - let removeImage = hasAvatar ? ( -
- -
- ) : ""; - let avatar = (hasAvatar) ? : {avatar} {sigilColor} - {removeImage}

Ship Name

~{props.ship}

From f6a2f7f83c084019cdc4df5b80e1531512fd3159 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Tue, 21 Apr 2020 19:59:03 -0400 Subject: [PATCH 2/3] contact: finish %octt implementation --- pkg/arvo/app/contact-store.hoon | 13 +++++++++++++ pkg/arvo/app/contact-view.hoon | 25 ++++++++++--------------- pkg/arvo/lib/contact-json.hoon | 18 ++++++++++++------ pkg/arvo/sur/contact-store.hoon | 17 +---------------- 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/pkg/arvo/app/contact-store.hoon b/pkg/arvo/app/contact-store.hoon index c151f7121..e6c8933e4 100644 --- a/pkg/arvo/app/contact-store.hoon +++ b/pkg/arvo/app/contact-store.hoon @@ -8,6 +8,19 @@ state-one == :: ++$ rolodex-0 (map path contacts-0) ++$ contacts-0 (map ship contact-0) ++$ avatar-0 [content-type=@t octs=[p=@ud q=@t]] ++$ contact-0 + $: nickname=@t + email=@t + phone=@t + website=@t + notes=@t + color=@ux + avatar=(unit avatar-0) + == +:: +$ state-zero $: %0 rolodex=rolodex-0 diff --git a/pkg/arvo/app/contact-view.hoon b/pkg/arvo/app/contact-view.hoon index 9c85c135d..2c65674a3 100644 --- a/pkg/arvo/app/contact-view.hoon +++ b/pkg/arvo/app/contact-view.hoon @@ -181,21 +181,16 @@ :: :: avatar images :: -:: [%'~groups' %avatar @ *] -:: =/ pax=path `path`t.t.site.url -:: ?~ pax not-found:gen -:: =/ pas `path`(flop pax) -:: ?~ pas not-found:gen -:: =/ pav `path`(flop t.pas) -:: ~& pav+pav -:: ~& name+name -:: =/ contact (contact-scry `path`(weld pav [name]~)) -:: ?~ contact not-found:gen -:: ?~ avatar.u.contact not-found:gen -:: =* avatar u.avatar.u.contact -:: =/ decoded (de:base64 q.octs.avatar) -:: ?~ decoded not-found:gen -:: [[200 ['content-type' content-type.avatar]~] `u.decoded] + [%'~groups' %avatar @ *] + =/ =path (flop t.t.site.url) + ?~ path not-found:gen + =/ contact (contact-scry `^path`(snoc (flop t.path) name)) + ?~ contact not-found:gen + ?~ avatar.u.contact not-found:gen + ?. ?=(%octt -.u.avatar.u.contact) not-found:gen + =/ max-3-days ['cache-control' 'max-age=259200'] + =/ content-type ['content-type' content-type.u.avatar.u.contact] + [[200 [content-type max-3-days ~]] `octs.u.avatar.u.contact] :: [%'~groups' *] (html-response:gen index) == diff --git a/pkg/arvo/lib/contact-json.hoon b/pkg/arvo/lib/contact-json.hoon index 2be8a96cf..3c9b18c6b 100644 --- a/pkg/arvo/lib/contact-json.hoon +++ b/pkg/arvo/lib/contact-json.hoon @@ -1,4 +1,5 @@ /- *contact-view +/+ base64 |% ++ nu :: parse number as hex |= jon/json @@ -62,12 +63,10 @@ :- %s %- crip %- zing - :~ "/~groups/img" + :~ "/~groups/avatar" (trip (spat path)) "/" (trip (scot %p ship)) - "." - (trip file-extension.u.avat) == :: %url s+url.u.avat @@ -197,8 +196,15 @@ ++ avat |= jon=json ^- avatar - =< (parse-json jon) - |% + |^ + =/ =avatar (parse-json jon) + ?- -.avatar + %url avatar + %octt + =. octs.avatar (need (de:base64 q.octs.avatar)) + avatar + == + :: ++ parse-json %- of:dejs:format :~ [%octt octt] @@ -207,7 +213,7 @@ :: ++ octt %- ot:dejs:format - :~ [%file-extension so:dejs:format] + :~ [%content-type so:dejs:format] [%octs octet] == :: diff --git a/pkg/arvo/sur/contact-store.hoon b/pkg/arvo/sur/contact-store.hoon index 706ed3e63..d7f93d9a3 100644 --- a/pkg/arvo/sur/contact-store.hoon +++ b/pkg/arvo/sur/contact-store.hoon @@ -1,27 +1,12 @@ /- *identity |% -+$ rolodex-0 (map path contacts-0) +$ rolodex (map path contacts) -:: -+$ contacts-0 (map ship contact-0) +$ contacts (map ship contact) -:: -+$ avatar-0 [content-type=@t octs=[p=@ud q=@t]] +$ avatar - $% [%octt [file-extension=@t octs=[p=@ud q=@t]]] + $% [%octt content-type=@t octs=[p=@ud q=@t]] [%url url=@t] == :: -+$ contact-0 - $: nickname=@t - email=@t - phone=@t - website=@t - notes=@t - color=@ux - avatar=(unit avatar-0) - == -:: +$ contact $: nickname=@t email=@t From c374e17ba5387d3f9beea7555aa6ca1977f4f54f Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Wed, 22 Apr 2020 18:08:59 -0400 Subject: [PATCH 3/3] contact-view: redirect upon url case of avatar --- pkg/arvo/app/contact-view.hoon | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/arvo/app/contact-view.hoon b/pkg/arvo/app/contact-view.hoon index 9fdeebb6c..97aa15729 100644 --- a/pkg/arvo/app/contact-view.hoon +++ b/pkg/arvo/app/contact-view.hoon @@ -187,10 +187,13 @@ =/ contact (contact-scry `^path`(snoc (flop t.path) name)) ?~ contact not-found:gen ?~ avatar.u.contact not-found:gen - ?. ?=(%octt -.u.avatar.u.contact) not-found:gen - =/ max-3-days ['cache-control' 'max-age=259200'] - =/ content-type ['content-type' content-type.u.avatar.u.contact] - [[200 [content-type max-3-days ~]] `octs.u.avatar.u.contact] + ?- -.u.avatar.u.contact + %url [[307 ['location' url.u.avatar.u.contact]~] ~] + %octt + =/ max-3-days ['cache-control' 'max-age=259200'] + =/ content-type ['content-type' content-type.u.avatar.u.contact] + [[200 [content-type max-3-days ~]] `octs.u.avatar.u.contact] + == :: [%'~groups' *] (html-response:gen index) ==