2021-06-10 22:54:26 +03:00
|
|
|
import * as Social from "~/node_common/social";
|
|
|
|
import * as Arrays from "~/common/arrays";
|
2021-06-11 22:25:58 +03:00
|
|
|
import * as Logging from "~/common/logging";
|
2021-06-10 22:54:26 +03:00
|
|
|
|
2021-06-11 03:36:57 +03:00
|
|
|
//things taht could be combined into this:
|
2021-06-10 22:54:26 +03:00
|
|
|
//update search (searchmanager)
|
|
|
|
//send websocket update (viewermanager)
|
|
|
|
//send slack message (Social.sendSlackMessage)
|
2021-06-11 03:36:57 +03:00
|
|
|
//create activity
|
|
|
|
//update summary counts
|
2021-06-10 22:54:26 +03:00
|
|
|
|
|
|
|
//maybe you could remove the try catch from here and put it inside the send part
|
|
|
|
|
|
|
|
const getUserURL = (user) => {
|
|
|
|
const userProfileURL = `https://slate.host/${user.username}`;
|
|
|
|
const userURL = `<${userProfileURL}|${user.username}>`;
|
|
|
|
return userURL;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const error = (location, e) => {
|
|
|
|
try {
|
|
|
|
const message = `@martina there was an error at ${location}: ${e}`;
|
|
|
|
Social.sendSlackMessage(message);
|
|
|
|
} catch (e) {
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.error(e);
|
2021-06-10 22:54:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const upload = ({ user, slate, files: targetFiles }) => {
|
|
|
|
if (slate && !slate.isPublic) return;
|
|
|
|
const files = Arrays.filterPublic(targetFiles);
|
|
|
|
if (!files.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
const userURL = getUserURL(user);
|
|
|
|
const extra =
|
|
|
|
files.length > 1
|
2021-07-07 01:40:27 +03:00
|
|
|
? ` and ${files.length - 1} other file${files.length - 1 > 1 ? "s" : ""}`
|
2021-06-10 22:54:26 +03:00
|
|
|
: "";
|
|
|
|
let message;
|
|
|
|
if (slate) {
|
2021-06-11 08:12:24 +03:00
|
|
|
const objectURL = `<https://slate.host/${user.username}/${slate.slatename}?cid=${files[0].cid}|${files[0].filename}>`;
|
2021-07-07 01:40:27 +03:00
|
|
|
const slateURL = `<https://slate.host/${user.username}/${slate.slatename}|${slate.data.name}>`;
|
|
|
|
message = `*${userURL}* uploaded ${objectURL}${extra} to ${slateURL}`;
|
2021-06-10 22:54:26 +03:00
|
|
|
} else {
|
|
|
|
const objectURL = `<https://slate.host/${user.username}?cid=${files[0].cid}|${files[0].filename}>`;
|
|
|
|
message = `*${userURL}* uploaded ${objectURL}${extra}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
Social.sendSlackMessage(message);
|
|
|
|
} catch (e) {
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.error(e);
|
2021-06-10 22:54:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const download = ({ user, files: targetFiles }) => {
|
|
|
|
const files = Arrays.filterPublic(targetFiles);
|
|
|
|
if (!files.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
const userURL = getUserURL(user);
|
|
|
|
const objectURL = `<https://slate.host/${user.username}?cid=${files[0].cid}|${files[0].filename}>`;
|
|
|
|
const extra =
|
|
|
|
files.length > 1
|
2021-07-07 01:40:27 +03:00
|
|
|
? ` and ${files.length - 1} other file${files.length - 1 > 1 ? "s" : ""}`
|
2021-06-10 22:54:26 +03:00
|
|
|
: "";
|
|
|
|
const message = `*${userURL}* downloaded ${objectURL}${extra}`;
|
|
|
|
Social.sendSlackMessage(message);
|
|
|
|
} catch (e) {
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.error(e);
|
2021-06-10 22:54:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const saveCopy = ({ slate, user, files: targetFiles }) => {
|
|
|
|
if (slate && !slate.isPublic) return;
|
|
|
|
const files = Arrays.filterPublic(targetFiles);
|
|
|
|
if (!files.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
const userURL = getUserURL(user);
|
|
|
|
const extra =
|
|
|
|
files.length > 1
|
2021-07-07 01:40:27 +03:00
|
|
|
? ` and ${files.length - 1} other file${files.length - 1 > 1 ? "s" : ""}`
|
2021-06-10 22:54:26 +03:00
|
|
|
: "";
|
|
|
|
let message;
|
|
|
|
if (slate) {
|
2021-06-11 08:12:24 +03:00
|
|
|
const objectURL = `<https://slate.host/${user.username}/${slate.slatename}?cid=${files[0].cid}|${files[0].filename}>`;
|
2021-07-07 01:40:27 +03:00
|
|
|
const slateURL = `<https://slate.host/${user.username}/${slate.slatename}|${slate.data.name}>`;
|
|
|
|
message = `*${userURL}* saved ${objectURL}${extra} to ${slateURL}`;
|
2021-06-10 22:54:26 +03:00
|
|
|
} else {
|
|
|
|
const objectURL = `<https://slate.host/${user.username}?cid=${files[0].cid}|${files[0].filename}>`;
|
|
|
|
message = `*${userURL}* saved ${objectURL}${extra}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
Social.sendSlackMessage(message);
|
|
|
|
} catch (e) {
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.error(e);
|
2021-06-10 22:54:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const createSlate = ({ user, slate }) => {
|
|
|
|
if (!slate.isPublic) return;
|
|
|
|
try {
|
|
|
|
const userURL = getUserURL(user);
|
2021-07-07 01:40:27 +03:00
|
|
|
const slateURL = `<https://slate.host/${user.username}/${slate.slatename}|${slate.data.name}>`;
|
|
|
|
const message = `*${userURL}* created a collection ${slateURL}`;
|
2021-06-10 22:54:26 +03:00
|
|
|
|
|
|
|
Social.sendSlackMessage(message);
|
|
|
|
} catch (e) {
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.error(e);
|
2021-06-10 22:54:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const createUser = ({ user }) => {
|
|
|
|
try {
|
|
|
|
const userURL = getUserURL(user);
|
|
|
|
const message = `*${userURL}* joined slate`;
|
|
|
|
|
|
|
|
Social.sendSlackMessage(message);
|
|
|
|
} catch (e) {
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.error(e);
|
2021-06-10 22:54:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const subscribeUser = ({ user, targetUser }) => {
|
|
|
|
try {
|
|
|
|
const userURL = getUserURL(user);
|
|
|
|
const targetUserURL = getUserURL(targetUser);
|
|
|
|
|
|
|
|
const message = `*${userURL}* followed ${targetUserURL}`;
|
|
|
|
|
|
|
|
Social.sendSlackMessage(message);
|
|
|
|
} catch (e) {
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.error(e);
|
2021-06-10 22:54:26 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const subscribeSlate = ({ user, targetSlate }) => {
|
|
|
|
if (!targetSlate.isPublic) return;
|
|
|
|
try {
|
|
|
|
const userURL = getUserURL(user);
|
2021-07-07 01:40:27 +03:00
|
|
|
const targetSlateURL = `<https://slate.host/$/${targetSlate.id}|${targetSlate.slateId}>`;
|
2021-06-10 22:54:26 +03:00
|
|
|
|
|
|
|
const message = `*${userURL}* subscribed to ${targetSlateURL}`;
|
|
|
|
|
|
|
|
Social.sendSlackMessage(message);
|
|
|
|
} catch (e) {
|
2021-06-11 22:25:58 +03:00
|
|
|
Logging.error(e);
|
2021-06-10 22:54:26 +03:00
|
|
|
}
|
|
|
|
};
|