mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-17 19:28:58 +01:00
125849673a
Co-authored-by: syuilo <syuilotan@yahoo.co.jp> Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
88 lines
1.8 KiB
TypeScript
88 lines
1.8 KiB
TypeScript
import $ from 'cafy';
|
|
import User from '../../../../models/user';
|
|
import { publishMainStream } from '../../../../stream';
|
|
import define from '../../define';
|
|
|
|
export const meta = {
|
|
requireCredential: true,
|
|
|
|
secure: true,
|
|
|
|
params: {
|
|
id: {
|
|
validator: $.str
|
|
},
|
|
|
|
data: {
|
|
validator: $.obj()
|
|
}
|
|
}
|
|
};
|
|
|
|
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
|
if (ps.id == null && ps.data == null) return rej('you need to set id and data params if home param unset');
|
|
|
|
let widget;
|
|
|
|
//#region Desktop home
|
|
if (widget == null && user.clientSettings.home) {
|
|
const desktopHome = user.clientSettings.home;
|
|
widget = desktopHome.find((w: any) => w.id == ps.id);
|
|
if (widget) {
|
|
widget.data = ps.data;
|
|
|
|
await User.update(user._id, {
|
|
$set: {
|
|
'clientSettings.home': desktopHome
|
|
}
|
|
});
|
|
}
|
|
}
|
|
//#endregion
|
|
|
|
//#region Mobile home
|
|
if (widget == null && user.clientSettings.mobileHome) {
|
|
const mobileHome = user.clientSettings.mobileHome;
|
|
widget = mobileHome.find((w: any) => w.id == ps.id);
|
|
if (widget) {
|
|
widget.data = ps.data;
|
|
|
|
await User.update(user._id, {
|
|
$set: {
|
|
'clientSettings.mobileHome': mobileHome
|
|
}
|
|
});
|
|
}
|
|
}
|
|
//#endregion
|
|
|
|
//#region Deck
|
|
if (widget == null && user.clientSettings.deck && user.clientSettings.deck.columns) {
|
|
const deck = user.clientSettings.deck;
|
|
for (const c of deck.columns.filter((c: any) => c.type == 'widgets')) {
|
|
for (const w of c.widgets.filter((w: any) => w.id == ps.id)) {
|
|
widget = w;
|
|
}
|
|
}
|
|
if (widget) {
|
|
widget.data = ps.data;
|
|
|
|
await User.update(user._id, {
|
|
$set: {
|
|
'clientSettings.deck': deck
|
|
}
|
|
});
|
|
}
|
|
}
|
|
//#endregion
|
|
|
|
if (widget) {
|
|
publishMainStream(user._id, 'widgetUpdated', {
|
|
id: ps.id, data: ps.data
|
|
});
|
|
|
|
res();
|
|
} else {
|
|
rej('widget not found');
|
|
}
|
|
}));
|