enigma-bbs/core/activitypub/settings.js

59 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-01-13 06:19:52 +00:00
const UserProps = require('../user_property');
const Config = require('../config').get;
module.exports = class ActivityPubSettings {
constructor(obj) {
this.enabled = true;
this.manuallyApproveFollowers = false;
this.hideSocialGraph = false; // followers, following
2023-01-22 20:51:32 +00:00
this.showRealName = true;
this.image = '';
this.icon = '';
// override default with any op config
Object.assign(this, Config().users.activityPub);
2023-02-01 05:16:19 +00:00
// finally override with any explicit values given to us
if (obj) {
Object.assign(this, obj);
}
}
static fromUser(user) {
if (!user.activityPubSettings) {
const settingsProp = user.getProperty(UserProps.ActivityPubSettings);
let settings;
try {
const parsed = JSON.parse(settingsProp);
settings = new ActivityPubSettings(parsed);
} catch (e) {
settings = new ActivityPubSettings();
}
user.activityPubSettings = settings;
}
return user.activityPubSettings;
}
persistToUserProperties(user, cb) {
return user.persistProperty(
UserProps.ActivityPubSettings,
JSON.stringify(this),
2023-02-01 05:16:19 +00:00
err => {
if (err) {
2023-02-01 05:16:19 +00:00
return cb(err);
}
// drop from cache - force re-cache
delete user.activityPubSettings;
const { prepareLocalUserAsActor } = require('./util');
prepareLocalUserAsActor(user, { force: false }, err => {
return cb(err);
});
2023-02-01 05:16:19 +00:00
}
);
}
};