2015-08-12 23:26:05 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
const messageArea = require('../core/message_area.js');
|
|
|
|
const { get } = require('lodash');
|
2016-08-04 01:48:45 +00:00
|
|
|
|
2015-08-12 23:26:05 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
exports.MessageAreaConfTempSwitcher = Sup => class extends Sup {
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
tempMessageConfAndAreaSwitch(messageAreaTag, recordPrevious = true) {
|
|
|
|
messageAreaTag = messageAreaTag || get(this, 'config.messageAreaTag', this.messageAreaTag);
|
|
|
|
if(!messageAreaTag) {
|
2018-06-23 03:26:46 +00:00
|
|
|
return; // nothing to do!
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
if(recordPrevious) {
|
|
|
|
this.prevMessageConfAndArea = {
|
2018-06-23 03:26:46 +00:00
|
|
|
confTag : this.client.user.properties.message_conf_tag,
|
|
|
|
areaTag : this.client.user.properties.message_area_tag,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
if(!messageArea.tempChangeMessageConfAndArea(this.client, messageAreaTag)) {
|
|
|
|
this.client.log.warn( { messageAreaTag : messageArea }, 'Failed to perform temporary message area/conf switch');
|
|
|
|
}
|
|
|
|
}
|
2016-08-04 01:48:45 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
tempMessageConfAndAreaRestore() {
|
|
|
|
if(this.prevMessageConfAndArea) {
|
|
|
|
this.client.user.properties.message_conf_tag = this.prevMessageConfAndArea.confTag;
|
|
|
|
this.client.user.properties.message_area_tag = this.prevMessageConfAndArea.areaTag;
|
|
|
|
}
|
|
|
|
}
|
2016-08-04 01:48:45 +00:00
|
|
|
};
|