mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-30 18:31:36 +03:00
deleted old reducers
This commit is contained in:
parent
8a4abe282a
commit
6f61d57383
@ -1,19 +0,0 @@
|
||||
export class CirclesReducer {
|
||||
reduce(reports, store) {
|
||||
reports.forEach((rep) => {
|
||||
switch (rep.type) {
|
||||
case "circles":
|
||||
if (rep.data.add) {
|
||||
store.circles = [...store.circles, rep.data.cir]
|
||||
} else {
|
||||
store.circles = rep.data
|
||||
}
|
||||
break;
|
||||
|
||||
case "landscape.prize":
|
||||
store.circles = [...store.circles, rep.data["circles-our"]];
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
import { isAggregator } from '/lib/util';
|
||||
|
||||
export class ConfigsReducer {
|
||||
reduce(reports, store) {
|
||||
reports.forEach(rep => {
|
||||
let stationName;
|
||||
let stations = {};
|
||||
|
||||
switch (rep.type) {
|
||||
case "circle.gram":
|
||||
this.processGramConfigs([rep.data], store.configs);
|
||||
break;
|
||||
case "circle.nes":
|
||||
this.processGramConfigs(rep.data, store.configs);
|
||||
break;
|
||||
case "circle.cos.loc":
|
||||
stationName = `~${rep.from.ship}/${rep.from.path.split("/")[2]}`;
|
||||
stations[stationName] = rep.data;
|
||||
this.addConfigs(stations, store.configs);
|
||||
break;
|
||||
case "circle.cos.rem":
|
||||
this.addConfigs(rep.data, store.configs);
|
||||
break;
|
||||
case "circle.pes.loc":
|
||||
stationName = `~${rep.from.ship}/${rep.from.path.split("/")[2]}`;
|
||||
this.updateConfig({pes: rep.data}, store.configs[stationName]);
|
||||
break;
|
||||
case "circle.config.dif.source":
|
||||
stationName = `~${rep.from.ship}/${rep.from.path.split("/")[2]}`;
|
||||
this.updateConfig(rep.data, store.configs[stationName]);
|
||||
break;
|
||||
case "circle.config.dif.full":
|
||||
stationName = rep.data.src[0]; // TODO: API weirdness; we have to get name of new station from new station config's src property. Should maybe return a dict.
|
||||
stations[stationName] = rep.data;
|
||||
this.addConfigs(stations, store.configs);
|
||||
break;
|
||||
case "circle.config.dif.permit": // TODO: This is very wonky, should be fixed with API discussion
|
||||
stationName = rep.data.cir;
|
||||
this.updateConfig(rep.data.dif.permit, store.configs[stationName]);
|
||||
break;
|
||||
case "circle.config.dif.remove":
|
||||
delete store.configs[rep.data.cir];
|
||||
break;
|
||||
case "config.ext":
|
||||
store.configs[rep.data.station] = store.configs[rep.data.station] || {};
|
||||
store.configs[rep.data.station].extConf = rep.data.extConf;
|
||||
break;
|
||||
case "circle.read":
|
||||
store.configs[rep.data.station] = store.configs[rep.data.station] || {};
|
||||
store.configs[rep.data.station].lastReadNum = rep.data.lastReadNum;
|
||||
break;
|
||||
|
||||
case "circle.config":
|
||||
let readChange = _.get(rep.data, 'dif.read', null);
|
||||
|
||||
if (readChange) {
|
||||
store.configs[rep.data.cir] = {...store.configs[rep.data.cir], red: readChange};
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "landscape.prize":
|
||||
rep.data.circles.forEach(c => {
|
||||
store.configs[c.circle] = c.config || {};
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
processGramConfigs(grams, storeConfigs) {
|
||||
grams.forEach(gram => {
|
||||
let tac = _.get(gram, 'gam.sep.fat.tac.text', null);
|
||||
if (tac && ['new item', 'edited item'].includes(tac)) {
|
||||
let conf = _.get(gram, 'gam.sep.fat.sep.lin.msg', null);
|
||||
if (conf) {
|
||||
let parsedConf = JSON.parse(conf);
|
||||
if (parsedConf['parent-config']) {
|
||||
storeConfigs[gram.gam.aud[0]] = {
|
||||
...storeConfigs[gram.gam.aud[0]],
|
||||
...{ extConf: parsedConf['parent-config'] }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
addConfigs(configs, storeConfigs) {
|
||||
Object.keys(configs)
|
||||
.forEach((cos) => {
|
||||
storeConfigs[cos] = storeConfigs[cos] || {};
|
||||
Object.assign(storeConfigs[cos], configs[cos]);
|
||||
});
|
||||
}
|
||||
|
||||
updateConfig(data, station) {
|
||||
if (!station) return;
|
||||
|
||||
if (data.src) {
|
||||
if (data.add) {
|
||||
station.src.push(data.src);
|
||||
} else {
|
||||
station.src = station.src.filter((val) => val !== data.src);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.sis) {
|
||||
if (data.add) {
|
||||
station.con.sis = station.con.sis.concat(data.sis);
|
||||
} else {
|
||||
station.con.sis = station.con.sis.filter((val) => !data.sis.includes(val));
|
||||
}
|
||||
}
|
||||
|
||||
if (data.pes) {
|
||||
station.pes = station.pes || {};
|
||||
|
||||
Object.assign(station.pes, data.pes);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,191 +0,0 @@
|
||||
import _ from 'lodash';
|
||||
import { isDMStation, isRootCollection, getMessageContent } from '/lib/util';
|
||||
|
||||
const INBOX_MESSAGE_COUNT = 30;
|
||||
|
||||
export class MessagesReducer {
|
||||
reduce(reports, store) {
|
||||
reports.forEach((rep) => {
|
||||
let fromCircle = rep.from && rep.from.path.split("/")[2];
|
||||
let fromInbox = fromCircle === "inbox";
|
||||
|
||||
switch (rep.type) {
|
||||
case "circle.nes":
|
||||
this.processMessages(rep.data, store);
|
||||
break;
|
||||
case "circle.gram":
|
||||
this.processMessages([rep.data], store);
|
||||
break;
|
||||
case "circle.config.dif.remove":
|
||||
delete store.messages.stations[rep.data.cir];
|
||||
break;
|
||||
case "circle.cos.loc":
|
||||
if (fromInbox) {
|
||||
store.messages.inbox.config = rep.data;
|
||||
store.messages.inbox.src = rep.data.src;
|
||||
this.storeInboxMessages(store);
|
||||
}
|
||||
break;
|
||||
case "circle.config.dif.source":
|
||||
if (fromInbox) {
|
||||
if (rep.data.add) {
|
||||
store.messages.inbox.src = [...store.messages.inbox.src, rep.data.src];
|
||||
} else {
|
||||
store.messages.inbox.src = store.messages.inbox.src.filter(src => src !== rep.data.src);
|
||||
}
|
||||
this.storeInboxMessages(store);
|
||||
}
|
||||
break;
|
||||
|
||||
case "circle.config":
|
||||
fromInbox = rep.data.cir.includes("inbox");
|
||||
if (fromInbox && _.get(rep.data, 'dif.source', null)) {
|
||||
if (rep.data.dif.source.add) {
|
||||
store.messages.inbox.src = [...store.messages.inbox.src, rep.data.dif.source.src];
|
||||
} else {
|
||||
store.messages.inbox.src = store.messages.inbox.src.filter(src => src !== rep.data.dif.source.src);
|
||||
}
|
||||
this.storeInboxMessages(store);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "landscape.prize":
|
||||
if (rep.data.inbox) {
|
||||
store.messages.inbox.src = [...store.messages.inbox.src, ...rep.data.inbox.config.src];
|
||||
store.messages.inbox.config = rep.data.inbox.config;
|
||||
this.processMessages(rep.data.inbox.messages, store);
|
||||
this.processMessages(rep.data.invites, store);
|
||||
this.storeInboxMessages(store);
|
||||
} else {
|
||||
console.log("WEIRD: no inbox property in landscape.prize?")
|
||||
}
|
||||
|
||||
// if (fromInbox) {
|
||||
// if (rep.data.add) {
|
||||
// store.messages.inbox.src = [...store.messages.inbox.src, rep.data.src];
|
||||
// } else {
|
||||
// store.messages.inbox.src = store.messages.inbox.src.filter(src => src !== rep.data.src);
|
||||
// }
|
||||
// this.storeInboxMessages(store);
|
||||
// }
|
||||
break;
|
||||
|
||||
case "dm.new": {
|
||||
store.messages.notifications = [...store.messages.notifications, ...rep.data];
|
||||
break;
|
||||
}
|
||||
|
||||
case "dm.clear": {
|
||||
store.messages.notifications = store.messages.notifications.filter(n => !rep.data.includes(n.uid));
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
processMessages(messages, store) {
|
||||
let msgs = messages.filter(m => {
|
||||
return !m.gam.aud.some(st => isRootCollection(st));
|
||||
});
|
||||
this.storeStationMessages(msgs, store);
|
||||
this.storeInboxMessages(store);
|
||||
}
|
||||
|
||||
// TODO: Make this more like storeInboxMessages
|
||||
storeStationMessages(messages, store) {
|
||||
messages.forEach((message) => {
|
||||
let msg = message.gam;
|
||||
msg.num = message.num;
|
||||
msg.aud.forEach((aud) => {
|
||||
let msgClone = { ...msg, aud: [aud] };
|
||||
let station = store.messages.stations[aud]
|
||||
|
||||
if (!station) {
|
||||
store.messages.stations[aud] = [msgClone];
|
||||
} else if (station.findIndex(o => o.uid === msgClone.uid) === -1) {
|
||||
let newest = true;
|
||||
|
||||
for (let i = 0; i < station.length; i++) {
|
||||
if (msgClone.wen < station[i].wen) {
|
||||
station.splice(i, 0, msgClone);
|
||||
newest = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (newest) station.push(msgClone);
|
||||
|
||||
// Print messages by date, for debugging:
|
||||
// for (let msgClone of station.messages) {
|
||||
// console.log(`msgClone ${msg.uid}: ${msg.wen}`);
|
||||
// }
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
storeInboxMessages(store) {
|
||||
let messages = store.messages.inbox.src.reduce((msgs, src) => {
|
||||
let msgGroup = store.messages.stations[src];
|
||||
if (!msgGroup) return msgs;
|
||||
return msgs.concat(msgGroup.filter(this.filterInboxMessages)); // filter out app & accepted invite msgs
|
||||
}, []);
|
||||
|
||||
let ret = _(messages)
|
||||
.sort((a, b) => b.wen - a.wen) // sort by date
|
||||
// sort must come before uniqBy! if uniqBy detects a dupe, it takes
|
||||
// earlier element in the array. since we want later timestamps to
|
||||
// override, sort first
|
||||
.uniqBy('uid') // dedupe
|
||||
.slice(0, INBOX_MESSAGE_COUNT) // grab the first 30 or so
|
||||
.value(); // unwrap lodash chain
|
||||
// for (let msg of ret) {
|
||||
// console.log(`msg ${msg.uid}: ${msg.wen}`);
|
||||
// }
|
||||
|
||||
// store.messages.inbox.messages = [
|
||||
// {
|
||||
// aud: ["~zod/marzod.zod"],
|
||||
// aut: "zod",
|
||||
// sep: { lin: {
|
||||
// msg: "Hey marzod!"
|
||||
// }},
|
||||
// uid: "0v4.85q7h.25nnt.5mhop.92c1u.3rhsa",
|
||||
// wen: 1538084786999,
|
||||
// }, {
|
||||
// aud: ["~zod/marzod.zod"],
|
||||
// aut: "marzod",
|
||||
// sep: { lin: {
|
||||
// msg: "oh hey zod"
|
||||
// }},
|
||||
// uid: "0v4.85q7h.25nnt.5mhop.92c1u.3rhfa",
|
||||
// wen: 1538084787000,
|
||||
// },
|
||||
// ...ret
|
||||
// ];
|
||||
store.messages.inbox.messages = ret;
|
||||
}
|
||||
|
||||
// Filter out of inbox:
|
||||
// - app messages
|
||||
// - accepted invites
|
||||
// - all DM invites (should automatically accept)
|
||||
filterInboxMessages(msg) {
|
||||
let msgDetails = getMessageContent(msg);
|
||||
let typeApp = msgDetails.type === "app";
|
||||
let typeInv = msgDetails.type === "inv";
|
||||
// let isDmInvite = typeInv && isDMStation(msgDetails.content);
|
||||
let isInboxMsg = msg.aud[0].split("/")[1] === "inbox";
|
||||
let isEditUpdate = msgDetails.type === "edited item";
|
||||
// let hasResponded = typeInv && msgDetails.content === "~zod/null";
|
||||
|
||||
if (typeApp) return false;
|
||||
if (typeInv) return false;
|
||||
// if (hasResponded) return false;
|
||||
if (isEditUpdate) return false;
|
||||
if (isInboxMsg) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
import { getStationDetails } from '/services';
|
||||
import _ from 'lodash';
|
||||
|
||||
export class NamesReducer {
|
||||
reduce(reports, store) {
|
||||
reports.forEach((rep) => {
|
||||
let ships = {};
|
||||
let details;
|
||||
|
||||
switch (rep.type) {
|
||||
case "circle.cos.loc":
|
||||
ships[rep.from.ship] = [rep.from.path.split("/")[2]];
|
||||
rep.data.con.sis.forEach((mem) => ships[mem] = []);
|
||||
|
||||
this.storeNames(ships, store.names);
|
||||
break;
|
||||
|
||||
case "circle.cos.rem":
|
||||
Object.arrayify(rep.data).forEach(({key: station, value: config}) => {
|
||||
let details = getStationDetails(station);
|
||||
|
||||
if (ships[details.host]) {
|
||||
ships[details.host] = _.uniq(ships[details.host].concat(details.cir));
|
||||
} else {
|
||||
ships[details.host] = [details.cir];
|
||||
}
|
||||
|
||||
config.con.sis.forEach((mem) => {
|
||||
if (!ships[mem]) ships[mem] = [];
|
||||
});
|
||||
});
|
||||
this.storeNames(ships, store.names);
|
||||
break;
|
||||
case "circle.nes":
|
||||
this.storeMessagesNames(rep.data, store.names);
|
||||
break;
|
||||
case "circle.gram":
|
||||
this.storeMessagesNames([rep.data], store.names);
|
||||
break;
|
||||
// case "circle.pes.loc":
|
||||
// stationName = `~${rep.from.ship}/${rep.from.path.split("/")[2]}`;
|
||||
// this.updateConfig({pes: rep.data}, store.configs[stationName]);
|
||||
// break;
|
||||
case "circle.config.dif.source":
|
||||
details = getStationDetails(rep.data.src);
|
||||
ships[details.host] = [details.cir];
|
||||
this.storeNames(ships, store.names);
|
||||
break;
|
||||
case "circle.config.dif.full":
|
||||
details = getStationDetails(rep.data.src[0]); // TODO: API weirdness; we have to get name of new station from new station config's src property. Should maybe return a dict.
|
||||
ships[details.host] = [details.cir];
|
||||
this.storeNames(ships, store.names);
|
||||
break;
|
||||
case "circle.config.dif.permit": // TODO: This is very wonky, should be fixed with API discussion
|
||||
details = getStationDetails(rep.data.cir); // TODO: API weirdness; we have to get name of new station from new station config's src property. Should maybe return a dict.
|
||||
ships[details.host] = [details.cir];
|
||||
this.storeNames(ships, store.names);
|
||||
// case "circle.config.dif.remove":
|
||||
// delete store.names[rep.data.cir];
|
||||
// break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
storeMessagesNames(messages, storeNames) {
|
||||
let ships = {};
|
||||
|
||||
messages.forEach((message) => {
|
||||
let msg = message.gam;
|
||||
msg.aud.forEach((aud) => {
|
||||
let details = getStationDetails(aud); // TODO: API weirdness; we have to get name of new station from new station config's src property. Should maybe return a dict.
|
||||
ships[details.host] = [details.cir];
|
||||
});
|
||||
|
||||
ships[msg.aut] = ships[msg.aut] || [];
|
||||
});
|
||||
|
||||
this.storeNames(ships, storeNames);
|
||||
}
|
||||
|
||||
storeNames(ships, storeNames) {
|
||||
Object.arrayify(ships).forEach(({key: ship, value: stations}) => {
|
||||
let sttns = stations.filter(s => s !== "c");
|
||||
|
||||
if (!storeNames[ship]) {
|
||||
storeNames[ship] = sttns;
|
||||
} else {
|
||||
storeNames[ship] = _.uniq(sttns.concat(storeNames[ship]))
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
export class PublicReducer {
|
||||
reduce(reports, store) {
|
||||
reports.forEach((rep) => {
|
||||
if (rep.type == "public") {
|
||||
if (_.isArray(rep.data)) {
|
||||
rep.data.forEach((c) => {
|
||||
this.storeCircle(`~${rep.from.ship}`, c, store.public);
|
||||
})
|
||||
} else {
|
||||
if (rep.data.add) {
|
||||
this.storeCircle(`~${rep.from.ship}`, rep.data.cir, store.public);
|
||||
} else {
|
||||
this.removeCircle(`~${rep.from.ship}`, rep.data.cir, store.public);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
storeCircle(ship, circle, storePublic) {
|
||||
if (!storePublic[ship]) {
|
||||
storePublic[ship] = [circle];
|
||||
} else {
|
||||
if (storePublic[ship].indexOf(circle) === -1) {
|
||||
storePublic[ship] = [...storePublic[ship], circle];
|
||||
}
|
||||
}
|
||||
}
|
||||
removeCircle(ship, circle, storePublic) {
|
||||
storePublic[ship] = storePublic[ship].filter((e) => e !== circle);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user