chat: associations data structure -> nested object

Before this, it was a Map. But because we want to store multiple app
metadata stores -- and because maps are specialised objects -- this
commit restructures the store, reducers, and rewrites behaviour first.
This commit is contained in:
Matilde Park 2020-03-05 17:42:46 -05:00
parent a16e40228d
commit 1dd78ef413
4 changed files with 32 additions and 16 deletions

View File

@ -45,7 +45,7 @@ export class Root extends Component {
state.invites['/chat'] : {};
let contacts = !!state.contacts ? state.contacts : {};
let associations = !!state.associations ? state.associations : new Map;
let associations = !!state.associations ? state.associations : {chat: {}, contacts: {}};
const renderChannelSidebar = (props, station) => (
<Sidebar
@ -154,11 +154,11 @@ export class Root extends Component {
};
let roomContacts = {};
let associatedGroup = ((associations.has(station)) &&
(associations.get(station)["group-path"]))
? associations.get(station)["group-path"] : "";
let associatedGroup = ((associations.chat[station]) &&
(associations.chat[station]["group-path"]))
? associations.chat[station]["group-path"] : "";
if ((associations.has(station)) && (associatedGroup in contacts)) {
if ((associations.chat[station]) && (associatedGroup in contacts)) {
roomContacts = contacts[associatedGroup]
}
@ -247,8 +247,8 @@ export class Root extends Component {
let popout = props.match.url.includes("/popout/");
let association = (associations.has(station))
? associations.get(station) : {};
let association = (associations.chat[station])
? associations.chat[station] : {};
return (
<Skeleton

View File

@ -40,9 +40,9 @@ export class Sidebar extends Component {
let when = !!msg ? msg.when : 0;
let title = box;
if ((props.associations.has(box)) && (props.associations.get(box).metadata)) {
title = (props.associations.get(box).metadata.title)
? props.associations.get(box).metadata.title : box;
if ((props.associations.chat[box]) && (props.associations.chat[box].metadata)) {
title = (props.associations.chat[box].metadata.title)
? props.associations.chat[box].metadata.title : box;
}
let nickname = author;

View File

@ -14,10 +14,14 @@ export class MetadataReducer {
associations(json, state) {
let data = _.get(json, 'associations', false);
if (data) {
let metadata = new Map;
let metadata = state.associations;
Object.keys(data).map((channel) => {
let channelObj = data[channel];
metadata.set(channelObj["app-path"], channelObj);
let app = data[channel]["app-name"];
if (!metadata[app]) {
metadata[app] = {};
}
metadata[app][channelObj["app-path"]] = channelObj;
})
state.associations = metadata;
}
@ -27,7 +31,11 @@ export class MetadataReducer {
let data = _.get(json, 'add', false);
if (data) {
let metadata = state.associations;
metadata.set(data["app-path"], data);
let app = data["app-name"];
if (!metadata[app]) {
metadata[app] = {};
}
metadata[app][data["app-path"]] = data;
state.associations = metadata;
}
}
@ -36,7 +44,8 @@ export class MetadataReducer {
let data = _.get(json, 'update-metadata', false);
if (data) {
let metadata = state.associations;
metadata.set(data["app-path"], data);
let app = data["app-name"];
metadata[app][data["app-path"]] = data;
state.associations = metadata;
}
}
@ -45,7 +54,11 @@ export class MetadataReducer {
let data = _.get(json, 'remove', false);
if (data) {
let metadata = state.associations;
metadata.delete(data["app-path"]);
let app = data["app-name"];
if (!metadata[app]) {
return false;
}
delete metadata[app][data["app-path"]];
state.associations = metadata;
}
}

View File

@ -16,7 +16,10 @@ class Store {
contacts: {},
permissions: {},
invites: {},
associations: new Map,
associations: {
chat: {},
contacts: {}
},
spinner: false,
sidebarShown: true,
pendingMessages: new Map([]),