cleaned up api.js

This commit is contained in:
Isaac Visintainer 2019-06-11 15:58:48 -07:00
parent 6f61d57383
commit 9e051a2dd6

View File

@ -9,9 +9,7 @@ class UrbitApi {
this.bindPaths = []; this.bindPaths = [];
} }
// keep default bind to hall, since its bind procedure more complex for now AA bind(path, method, ship = this.authTokens.ship, appl = "write", success, fail) {
bind(path, method, ship = this.authTokens.ship, appl = "hall", success, fail) {
console.log('binding to ...', appl, ", path: ", path, ", as ship: ", ship, ", by method: ", method);
this.bindPaths = _.uniq([...this.bindPaths, path]); this.bindPaths = _.uniq([...this.bindPaths, path]);
window.urb.subscribe(ship, appl, path, window.urb.subscribe(ship, appl, path,
@ -29,19 +27,8 @@ class UrbitApi {
}, },
(err) => { (err) => {
fail(err); fail(err);
});
} }
);
hall(data) {
this.action("hall", "hall-action", data);
}
coll(data) {
this.action("collections", "collections-action", data);
}
setOnboardingBit(value) {
this.action("collections", "json", { onboard: value });
} }
action(appl, mark, data) { action(appl, mark, data) {
@ -55,134 +42,6 @@ class UrbitApi {
}); });
}); });
} }
/*
Special actions
*/
permit(cir, aud, message) {
this.hall({
permit: {
nom: cir,
sis: aud,
inv: true
}
});
if (message) {
this.invite(cir, aud);
}
}
permitCol(cir, aud, message, nom) {
this.hall({
permit: {
nom: cir,
sis: aud,
inv: true
}
});
if (message) {
this.inviteCol(cir, aud, nom);
}
}
invite(cir, aud) {
let audInboxes = aud.map((aud) => `~${aud}/i`);
let inviteMessage = {
aud: audInboxes,
ses: [{
inv: {
inv: true,
cir: `~${window.ship}/${cir}`
}
}]
};
this.hall({
phrase: inviteMessage
});
}
inviteCol(cir, aud, nom) {
let audInboxes = aud.map((aud) => `~${aud}/i`);
let inviteMessage = {
aud: audInboxes,
ses: [{
app: {
app: nom,
sep: {
inv: {
inv: true,
cir: `~${window.ship}/${cir}`
}
}
}
}]
};
this.hall({
phrase: inviteMessage
});
}
message(aud, words) {
let msg = {
aud,
ses: [{
lin: {
msg: words,
pat: false
}
}]
};
this.hall({
phrase: msg
});
}
source(nom, sub) {
this.hall({
source: {
nom: "inbox",
sub: sub,
srs: [nom]
}
})
}
create(nom, priv) {
this.hall({
create: {
nom: nom,
des: "chatroom",
sec: priv ? "village" : "channel"
}
});
}
ire(aud, uid, msg) {
let message = {
aud: aud,
ses: [{
ire: {
top: uid,
sep: {
lin: {
msg: msg,
pat: false
}
}
}
}]
}
this.hall({
phrase: message
})
}
} }
export let api = new UrbitApi(); export let api = new UrbitApi();