Disallow posting empty message

This commit is contained in:
anthony 2023-09-25 20:25:01 -05:00
parent fc107f1552
commit a6196c38ec
3 changed files with 61 additions and 10 deletions

View File

@ -183,6 +183,13 @@ exports.FullScreenEditorModule =
return cb(null); return cb(null);
}, },
editModeEscPressed: function (formData, extraArgs, cb) { editModeEscPressed: function (formData, extraArgs, cb) {
const errMsgView = self.viewControllers.header.getView(
MciViewIds.header.errorMsg
);
if (errMsgView) {
errMsgView.clearText();
}
self.footerMode = self.footerMode =
'editor' === self.footerMode ? 'editorMenu' : 'editor'; 'editor' === self.footerMode ? 'editorMenu' : 'editor';

View File

@ -763,6 +763,11 @@ module.exports = class Message {
} }
persist(cb) { persist(cb) {
const containsNonWhitespaceCharacterRegEx = /\S/;
if (!containsNonWhitespaceCharacterRegEx.test(this.message)) {
return cb(Errors.Invalid('Empty message'));
}
if (!this.isValid()) { if (!this.isValid()) {
return cb(Errors.Invalid('Cannot persist invalid message!')); return cb(Errors.Invalid('Cannot persist invalid message!'));
} }

View File

@ -14,6 +14,39 @@ exports.moduleInfo = {
author: 'NuSkooler', author: 'NuSkooler',
}; };
const MciViewIds = {
header: {
from: 1,
to: 2,
subject: 3,
errorMsg: 4,
modTimestamp: 5,
msgNum: 6,
msgTotal: 7,
customRangeStart: 10, // 10+ = customs
},
body: {
message: 1,
},
// :TODO: quote builder MCIs - remove all magic #'s
// :TODO: consolidate all footer MCI's - remove all magic #'s
ViewModeFooter: {
MsgNum: 6,
MsgTotal: 7,
// :TODO: Just use custom ranges
},
quoteBuilder: {
quotedMsg: 1,
// 2 NYI
quoteLines: 3,
},
};
exports.getModule = class AreaPostFSEModule extends FullScreenEditorModule { exports.getModule = class AreaPostFSEModule extends FullScreenEditorModule {
constructor(options) { constructor(options) {
super(options); super(options);
@ -42,19 +75,25 @@ exports.getModule = class AreaPostFSEModule extends FullScreenEditorModule {
], ],
function complete(err) { function complete(err) {
if (err) { if (err) {
// :TODO:... sooooo now what? const errMsgView = self.viewControllers.header.getView(
} else { MciViewIds.header.errorMsg
// note: not logging 'from' here as it's part of client.log.xxxx()
self.client.log.info(
{
to: msg.toUserName,
subject: msg.subject,
uuid: msg.messageUuid,
},
`User "${self.client.user.username}" posted message to "${msg.toUserName}" (${msg.areaTag})`
); );
if (errMsgView) {
errMsgView.setText(err.message);
}
return cb(err);
} }
// note: not logging 'from' here as it's part of client.log.xxxx()
self.client.log.info(
{
to: msg.toUserName,
subject: msg.subject,
uuid: msg.messageUuid,
},
`User "${self.client.user.username}" posted message to "${msg.toUserName}" (${msg.areaTag})`
);
return self.nextMenu(cb); return self.nextMenu(cb);
} }
); );