diff --git a/pkg/interface/src/logic/api/contacts.ts b/pkg/interface/src/logic/api/contacts.ts index 3049442f5a..2874ba0ef0 100644 --- a/pkg/interface/src/logic/api/contacts.ts +++ b/pkg/interface/src/logic/api/contacts.ts @@ -5,74 +5,41 @@ import { Contact, ContactEdit } from '~/types/contact-update'; import { GroupPolicy, Resource } from '~/types/group-update'; export default class ContactsApi extends BaseApi { - create( - name: string, - policy: Enc, - title: string, - description: string - ) { - return this.viewAction({ - create: { - name, - policy, - title, - description, - }, - }); + add(ship: Patp, contact: any) { + return this.storeAction({ add: { ship, contact } }); } - share(recipient: Patp, path: Patp, ship: Patp, contact: Contact) { - return this.viewAction({ - share: { - recipient, - path, - ship, - contact, - }, - }); + remove(ship: Patp) { + return this.storeAction({ remove: { ship } }); } - remove(path: Path, ship: Patp) { - return this.viewAction({ remove: { path, ship } }); - } - - edit(path: Path, ship: Patp, editField: ContactEdit) { + edit(ship: Patp, editField: ContactEdit) { /* editField can be... {nickname: ''} {email: ''} {phone: ''} {website: ''} - {notes: ''} {color: 'fff'} // with no 0x prefix {avatar: null} - {avatar: {url: ''}} + {avatar: ''} */ - return this.hookAction({ + return this.storeAction({ edit: { - path, ship, 'edit-field': editField, }, }); } - invite(resource: Resource, ship: Patp, text = '') { - return this.viewAction({ - invite: { resource, ship, text }, - }); + private storeAction(action: any): Promise { + return this.action('contact-store', 'contact-update', action) } - join(resource: Resource) { - return this.viewAction({ - join: resource, - }); + private viewAction(threadName: string, action: any) { + return this.spider('contact-view-action', 'json', threadName, action); } - private hookAction(data) { - return this.action('contact-hook', 'contact-action', data); - } - - private viewAction(data) { - return this.action('contact-view', 'json', data); + private hookAction(ship: Patp, action: any): Promise { + return this.action('contact-push-hook', 'contact-update', action); } } diff --git a/pkg/interface/src/logic/reducers/contact-update.ts b/pkg/interface/src/logic/reducers/contact-update.ts index 88a527ed1e..2ba1da1d0c 100644 --- a/pkg/interface/src/logic/reducers/contact-update.ts +++ b/pkg/interface/src/logic/reducers/contact-update.ts @@ -10,8 +10,6 @@ export default class ContactReducer { const data = _.get(json, 'contact-update', false); if (data) { this.initial(data, state); - this.create(data, state); - this.delete(data, state); this.add(data, state); this.remove(data, state); this.edit(data, state); @@ -25,27 +23,10 @@ export default class ContactReducer { } } - create(json: ContactUpdate, state: S) { - const data = _.get(json, 'create', false); - if (data) { - state.contacts[data.path] = {}; - } - } - - delete(json: ContactUpdate, state: S) { - const data = _.get(json, 'delete', false); - if (data) { - delete state.contacts[data.path]; - } - } - add(json: ContactUpdate, state: S) { const data = _.get(json, 'add', false); - if ( - data && - (data.path in state.contacts) - ) { - state.contacts[data.path][data.ship] = data.contact; + if (data) { + state.contacts[data.ship] = data.contact; } } @@ -53,10 +34,9 @@ export default class ContactReducer { const data = _.get(json, 'remove', false); if ( data && - (data.path in state.contacts) && - (data.ship in state.contacts[data.path]) + (data.ship in state.contacts) ) { - delete state.contacts[data.path][data.ship]; + delete state.contacts[data.ship]; } } @@ -64,15 +44,13 @@ export default class ContactReducer { const data = _.get(json, 'edit', false); if ( data && - (data.path in state.contacts) && - (data.ship in state.contacts[data.path]) + (data.ship in state.contacts) ) { const edit = Object.keys(data['edit-field']); if (edit.length !== 1) { return; } - state.contacts[data.path][data.ship][edit[0]] = - data['edit-field'][edit[0]]; + state.contacts[data.ship][edit[0]] = data['edit-field'][edit[0]]; } } } diff --git a/pkg/interface/src/logic/subscription/global.ts b/pkg/interface/src/logic/subscription/global.ts index ed4a2c94c8..d6af894282 100644 --- a/pkg/interface/src/logic/subscription/global.ts +++ b/pkg/interface/src/logic/subscription/global.ts @@ -10,7 +10,6 @@ import _ from 'lodash'; type AppSubscription = [Path, string]; const groupSubscriptions: AppSubscription[] = [ - ['/synced', 'contact-hook'] ]; const graphSubscriptions: AppSubscription[] = [ @@ -37,8 +36,7 @@ export default class GlobalSubscription extends BaseSubscription { this.subscribe('/groups', 'group-store'); this.clearQueue(); - - this.subscribe('/primary', 'contact-view'); + this.subscribe('/updates', 'contact-store'); this.subscribe('/all', 's3-store'); this.subscribe('/keys', 'graph-store'); this.subscribe('/updates', 'hark-store');