2023-01-13 06:19:52 +00:00
|
|
|
const UserProps = require('../user_property');
|
2023-01-28 18:55:31 +00:00
|
|
|
const Config = require('../config').get;
|
2023-01-09 00:11:49 +00:00
|
|
|
|
|
|
|
module.exports = class ActivityPubSettings {
|
|
|
|
constructor(obj) {
|
2023-01-28 18:55:31 +00:00
|
|
|
this.enabled = true;
|
2023-01-09 00:11:49 +00:00
|
|
|
this.manuallyApproveFollowers = false;
|
|
|
|
this.hideSocialGraph = false; // followers, following
|
2023-01-22 20:51:32 +00:00
|
|
|
this.showRealName = true;
|
2023-01-14 04:27:02 +00:00
|
|
|
this.image = '';
|
|
|
|
this.icon = '';
|
2023-01-09 00:11:49 +00:00
|
|
|
|
2023-01-28 18:55:31 +00:00
|
|
|
// 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
|
2023-01-09 00:11:49 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-03-19 19:50:44 +00:00
|
|
|
persistToUserProperties(user, cb) {
|
2023-01-09 00:11:49 +00:00
|
|
|
return user.persistProperty(
|
|
|
|
UserProps.ActivityPubSettings,
|
|
|
|
JSON.stringify(this),
|
2023-02-01 05:16:19 +00:00
|
|
|
err => {
|
2023-03-19 19:50:44 +00:00
|
|
|
if (err) {
|
2023-02-01 05:16:19 +00:00
|
|
|
return cb(err);
|
|
|
|
}
|
2023-03-19 19:50:44 +00:00
|
|
|
|
|
|
|
// drop from cache - force re-cache
|
|
|
|
delete user.activityPubSettings;
|
|
|
|
|
|
|
|
const { prepareLocalUserAsActor } = require('./util');
|
|
|
|
prepareLocalUserAsActor(user, { force: false }, err => {
|
2023-03-19 19:54:13 +00:00
|
|
|
if (err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
return user.persistProperties(user.properties, cb);
|
2023-03-19 19:50:44 +00:00
|
|
|
});
|
2023-02-01 05:16:19 +00:00
|
|
|
}
|
2023-01-09 00:11:49 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|