autoclose an article toggle

This commit is contained in:
riley
2017-03-24 10:40:12 -06:00
parent c1baccae5a
commit 5d5ad2585d
3 changed files with 27 additions and 1 deletions
@@ -37,6 +37,11 @@ const updateInfoBoxContent = (updateSettings) => (event) => {
updateSettings({infoBoxContent});
};
const updateAutoClose = (updateSettings, autoCloseStream) => () => {
console.log('autoCloseStream', autoCloseStream);
updateSettings({autoCloseStream});
};
const updateClosedMessage = (updateSettings) => (event) => {
const closedMessage = event.target.value;
updateSettings({closedMessage});
@@ -131,6 +136,11 @@ const StreamSettings = ({updateSettings, settingsError, settings, errors}) => {
</div>
</Card>
<Card className={`${styles.configSetting} ${styles.configSettingInfoBox}`}>
<div className={styles.action}>
<Checkbox
onChange={updateAutoClose(updateSettings, !settings.autoCloseStream)}
checked={settings.autoCloseStream} />
</div>
<div className={styles.content}>
{lang.t('configure.close-after')}
<br />
+4
View File
@@ -47,6 +47,10 @@ const SettingSchema = new Schema({
organizationName: {
type: String
},
autoCloseStream: {
type: Boolean,
default: false
},
closedTimeout: {
type: Number,
+13 -1
View File
@@ -57,12 +57,24 @@ module.exports = class AssetsService {
static findOrCreateByUrl(url) {
// Check the URL to confirm that is in the domain whitelist
return domainlist.urlCheck(url).then((whitelisted) => {
return Promise.all([
domainlist.urlCheck(url),
SettingsService.retrieve()
]).then(([whitelisted, settings]) => {
const setOnInsert = {url};
if (settings.autoCloseStream) {
setOnInsert.closedAt = new Date(Date.now() + settings.closedTimeout * 1000);
}
if (!whitelisted) {
return Promise.reject(errors.ErrInvalidAssetURL);
} else {
return AssetModel.findOneAndUpdate({url}, {url}, {
$setOnInsert: setOnInsert,
// Ensure that if it's new, we return the new object created.
new: true,