mirror of
https://github.com/urbit/shrub.git
synced 2024-12-01 14:42:02 +03:00
Merge pull request #2973 from urbit/la/spa-metadata-fix
chat: fix %initial response and metadata reducer
This commit is contained in:
commit
4c34b2993a
@ -56,26 +56,23 @@
|
||||
[%read (numb read.config)]
|
||||
==
|
||||
::
|
||||
++ inbox
|
||||
|= box=^inbox
|
||||
^- json
|
||||
%+ frond %chat-initial
|
||||
%- pairs
|
||||
%+ turn ~(tap by box)
|
||||
|= [pax=^path =mailbox]
|
||||
^- [cord json]
|
||||
:- (spat pax)
|
||||
%- pairs
|
||||
:~ [%envelopes [%a (turn envelopes.mailbox envelope)]]
|
||||
[%config (config config.mailbox)]
|
||||
==
|
||||
::
|
||||
++ update
|
||||
|= upd=^update
|
||||
^- json
|
||||
%+ frond %chat-update
|
||||
%- pairs
|
||||
:~
|
||||
?: ?=(%initial -.upd)
|
||||
:- %initial
|
||||
%- pairs
|
||||
%+ turn ~(tap by inbox.upd)
|
||||
|= [pax=^path =mailbox]
|
||||
^- [cord json]
|
||||
:- (spat pax)
|
||||
%- pairs
|
||||
:~ [%envelopes [%a (turn envelopes.mailbox envelope)]]
|
||||
[%config (config config.mailbox)]
|
||||
==
|
||||
?: ?=(%message -.upd)
|
||||
:- %message
|
||||
%- pairs
|
||||
|
@ -14,6 +14,7 @@ export class Sidebar extends Component {
|
||||
dmOverlay: false
|
||||
};
|
||||
}
|
||||
|
||||
onClickNew() {
|
||||
this.props.history.push('/~chat/new');
|
||||
}
|
||||
@ -37,10 +38,14 @@ export class Sidebar extends Component {
|
||||
|
||||
const selectedGroups = props.selectedGroups ? props.selectedGroups : [];
|
||||
|
||||
const associations =
|
||||
const contactAssoc =
|
||||
(props.associations && 'contacts' in props.associations)
|
||||
? alphabetiseAssociations(props.associations.contacts) : {};
|
||||
|
||||
const chatAssoc =
|
||||
(props.associations && 'chat' in props.associations)
|
||||
? alphabetiseAssociations(props.associations.chat) : {};
|
||||
|
||||
const groupedChannels = {};
|
||||
Object.keys(props.inbox).map((box) => {
|
||||
if (box.startsWith('/~/')) {
|
||||
@ -51,16 +56,18 @@ export class Sidebar extends Component {
|
||||
} else {
|
||||
groupedChannels['/~/'] = [box];
|
||||
}
|
||||
}
|
||||
const path = props.associations.chat[box]
|
||||
? props.associations.chat[box]['group-path'] : box;
|
||||
if (path in associations) {
|
||||
if (groupedChannels[path]) {
|
||||
const array = groupedChannels[path];
|
||||
array.push(box);
|
||||
groupedChannels[path] = array;
|
||||
} else {
|
||||
groupedChannels[path] = [box];
|
||||
} else {
|
||||
const path = chatAssoc[box]
|
||||
? chatAssoc[box]['group-path'] : box;
|
||||
|
||||
if (path in contactAssoc) {
|
||||
if (groupedChannels[path]) {
|
||||
const array = groupedChannels[path];
|
||||
array.push(box);
|
||||
groupedChannels[path] = array;
|
||||
} else {
|
||||
groupedChannels[path] = [box];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -77,7 +84,7 @@ export class Sidebar extends Component {
|
||||
);
|
||||
});
|
||||
|
||||
const groupedItems = Object.keys(associations)
|
||||
const groupedItems = Object.keys(contactAssoc)
|
||||
.filter(each => (groupedChannels[each] || []).length !== 0)
|
||||
.filter((each) => {
|
||||
if (selectedGroups.length === 0) {
|
||||
@ -94,8 +101,8 @@ export class Sidebar extends Component {
|
||||
<GroupItem
|
||||
key={i}
|
||||
index={i}
|
||||
association={associations[each]}
|
||||
chatMetadata={props.associations['chat']}
|
||||
association={contactAssoc[each]}
|
||||
chatMetadata={chatAssoc}
|
||||
channels={channels}
|
||||
inbox={props.inbox}
|
||||
station={props.station}
|
||||
@ -108,7 +115,7 @@ export class Sidebar extends Component {
|
||||
groupedItems.push(
|
||||
<GroupItem
|
||||
association={'/~/'}
|
||||
chatMetadata={props.associations['chat']}
|
||||
chatMetadata={chatAssoc}
|
||||
channels={groupedChannels['/~/']}
|
||||
inbox={props.inbox}
|
||||
station={props.station}
|
||||
|
@ -4,11 +4,12 @@ export default class MetadataReducer {
|
||||
reduce(json, state) {
|
||||
let data = _.get(json, 'metadata-update', false);
|
||||
if (data) {
|
||||
console.log(data);
|
||||
console.log('data: ', data);
|
||||
this.associations(data, state);
|
||||
this.add(data, state);
|
||||
this.update(data, state);
|
||||
this.remove(data, state);
|
||||
console.log('state: ', state);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,15 +20,16 @@ export default class MetadataReducer {
|
||||
Object.keys(data).forEach((key) => {
|
||||
let val = data[key];
|
||||
let appName = val['app-name'];
|
||||
let groupPath = val['group-path'];
|
||||
let appPath = val['app-path'];
|
||||
if (!(appName in metadata)) {
|
||||
metadata[appName] = {};
|
||||
}
|
||||
if (!(groupPath in metadata[appName])) {
|
||||
metadata[appName][groupPath] = {};
|
||||
if (!(appPath in metadata[appName])) {
|
||||
metadata[appName][appPath] = {};
|
||||
}
|
||||
metadata[appName][groupPath] = val;
|
||||
metadata[appName][appPath] = val;
|
||||
});
|
||||
|
||||
state.associations = metadata;
|
||||
}
|
||||
}
|
||||
@ -36,13 +38,16 @@ export default class MetadataReducer {
|
||||
let data = _.get(json, 'add', false);
|
||||
if (data) {
|
||||
let metadata = state.associations;
|
||||
if (!(data['app-name'] in metadata)) {
|
||||
metadata[data['app-name']] = {};
|
||||
let appName = data['app-name'];
|
||||
let appPath = data['app-path'];
|
||||
|
||||
if (!(appName in metadata)) {
|
||||
metadata[appName] = {};
|
||||
}
|
||||
if (!(data['group-path'] in metadata[data['app-name']])) {
|
||||
metadata[data['app-name']][data['group-path']] = {};
|
||||
if (!(appPath in metadata[appName])) {
|
||||
metadata[appName][appPath] = {};
|
||||
}
|
||||
metadata[data['app-name']][data['group-path']] = data;
|
||||
metadata[appName][appPath] = data;
|
||||
|
||||
state.associations = metadata;
|
||||
}
|
||||
@ -52,13 +57,16 @@ export default class MetadataReducer {
|
||||
let data = _.get(json, 'update-metadata', false);
|
||||
if (data) {
|
||||
let metadata = state.associations;
|
||||
if (!(data['app-name'] in metadata)) {
|
||||
metadata[data['app-name']] = {};
|
||||
let appName = data['app-name'];
|
||||
let appPath = data['app-path'];
|
||||
|
||||
if (!(appName in metadata)) {
|
||||
metadata[appName] = {};
|
||||
}
|
||||
if (!(data['group-path'] in metadata[data['app-name']])) {
|
||||
metadata[data['app-name']][data['group-path']] = {};
|
||||
if (!(appPath in metadata[appName])) {
|
||||
metadata[appName][appPath] = {};
|
||||
}
|
||||
metadata[data['app-name']][data['group-path']] = data;
|
||||
metadata[appName][appPath] = data;
|
||||
|
||||
state.associations = metadata;
|
||||
}
|
||||
@ -68,12 +76,13 @@ export default class MetadataReducer {
|
||||
let data = _.get(json, 'remove', false);
|
||||
if (data) {
|
||||
let metadata = state.associations;
|
||||
if (data['group-path'] in metadata) {
|
||||
let path =
|
||||
`${data['group-path']}/${data['app-name']}${data['app-path']}`
|
||||
delete metadata[data["group-path"]][path];
|
||||
state.associations = metadata;
|
||||
let appName = data['app-name'];
|
||||
let appPath = data['app-path'];
|
||||
|
||||
if (appName in metadata && appPath in metadata[appName]) {
|
||||
delete metadata[appName][appPath];
|
||||
}
|
||||
state.associations = metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user