Make banmessages send over websocket close #529

merge-requests/341/head
Thomas Lynch 1 year ago
parent 565f52478b
commit 1785454e84
  1. 1
      .eslintrc.json
  2. 17
      gulp/res/js/banmessage.js
  3. 17
      gulp/res/js/live.js
  4. 3
      gulpfile.js
  5. 9
      models/forms/banposter.js
  6. 2
      views/includes/banmessage.pug
  7. 5
      views/mixins/banmessage.pug
  8. 6
      views/mixins/post.pug

@ -7,6 +7,7 @@
"gulp/res/js/modal.js",
"gulp/res/js/uploaditem.js",
"gulp/res/js/pugfilter.js",
"gulp/res/js/banmessage.js",
"gulp/res/js/captchaformsection.js",
"gulp/res/js/watchedthread.js",
"gulp/res/js/threadwatcher.js",

@ -0,0 +1,17 @@
function pug_attr(t,e,n,r){if(!1===e||null==e||!e&&("class"===t||"style"===t))return"";if(!0===e)return" "+(r?t:t+'="'+t+'"');var f=typeof e;return"object"!==f&&"function"!==f||"function"!=typeof e.toJSON||(e=e.toJSON()),"string"==typeof e||(e=JSON.stringify(e),n||-1===e.indexOf('"'))?(n&&(e=pug_escape(e))," "+t+'="'+e+'"'):" "+t+"='"+e.replace(/'/g,"'")+"'"}
function pug_escape(e){var a=""+e,t=pug_match_html.exec(a);if(!t)return e;var r,c,n,s="";for(r=t.index,c=0;r<a.length;r++){switch(a.charCodeAt(r)){case 34:n="&quot;";break;case 38:n="&amp;";break;case 60:n="&lt;";break;case 62:n="&gt;";break;default:continue}c!==r&&(s+=a.substring(c,r)),c=r+1,s+=n}return c!==r?s+a.substring(c,r):s}
var pug_match_html=/["&<>]/;function banmessage(locals) {var pug_html = "", pug_mixins = {}, pug_interp;;
var locals_for_with = (locals || {});
(function (__, banmessage) {
pug_mixins["banmessage"] = pug_interp = function(banmessage){
var block = (this && this.block), attributes = (this && this.attributes) || {};
pug_html = pug_html + "\u003Cp class=\"ban\"\u003E\u003Cspan class=\"message\"\u003E" + (pug_escape(null == (pug_interp = __('USER WAS BANNED FOR THIS POST')) ? "" : pug_interp)) + "\u003C\u002Fspan\u003E \u003Cspan" + (" class=\"reason\""+pug_attr("data-reason", banmessage, true, false)) + "\u003E" + (pug_escape(null == (pug_interp = banmessage) ? "" : pug_interp)) + "\u003C\u002Fspan\u003E\u003C\u002Fp\u003E";
};
pug_mixins["banmessage"](banmessage);
}.call(this, "__" in locals_for_with ?
locals_for_with.__ :
typeof __ !== 'undefined' ? __ : undefined, "banmessage" in locals_for_with ?
locals_for_with.banmessage :
typeof banmessage !== 'undefined' ? banmessage : undefined));
;;return pug_html;}

@ -1,4 +1,4 @@
/* globals __ isRecent isGlobalRecent isThread post extraLocals isModView io setLocalStorage */
/* globals __ isRecent banmessage isGlobalRecent isThread post extraLocals isModView io setLocalStorage */
let liveEnabled = localStorage.getItem('live') == 'true';
let scrollEnabled = localStorage.getItem('scroll') == 'true';
let socket;
@ -48,8 +48,8 @@ window.addEventListener('settingsReady', function() { //after domcontentloaded
applyToReplies = true;
disableReplies = true;
break;
case 'edit':
//opting for no data mark, already has the usual "edited x ago"
case 'banmessage':
case 'edit': //opting for no data mark, already has the usual "edited x ago"
break;
default:
return;
@ -87,6 +87,17 @@ window.addEventListener('settingsReady', function() { //after domcontentloaded
insertPoint: insertPoint,
insertPosition: 'beforeBegin',
});
} else if (data.type === 'banmessage') {
const banMessageHtml = banmessage({
banmessage: data.banmessage,
});
const existingBanMessage = postContainer.querySelector('.ban');
if (existingBanMessage) {
existingBanMessage.insertAdjacentHTML('afterend', banMessageHtml);
existingBanMessage.remove();
} else {
postContainer.insertAdjacentHTML('beforeend', banMessageHtml);
}
}
};

@ -499,7 +499,7 @@ const extraLocals = ${JSON.stringify({ meta: config.get.meta, reverseImageLinksU
// fs.writeFileSync('gulp/res/js/pugruntime.js', pugRuntimeFuncs);
//compile some pug client side functions
['modal', 'post', 'uploaditem', 'pugfilters', 'captchaformsection', 'watchedthread', 'threadwatcher']
['modal', 'post', 'uploaditem', 'pugfilters', 'captchaformsection', 'watchedthread', 'threadwatcher', 'banmessage']
.forEach(templateName => {
const compilationOptions = {
compileDebug: false,
@ -531,6 +531,7 @@ const extraLocals = ${JSON.stringify({ meta: config.get.meta, reverseImageLinksU
// `${paths.scripts.src}/pugruntime.js`,
`${paths.scripts.src}/modal.js`,
`${paths.scripts.src}/pugfilters.js`,
`${paths.scripts.src}/banmessage.js`,
`${paths.scripts.src}/post.js`,
`${paths.scripts.src}/settings.js`,
`${paths.scripts.src}/live.js`,

@ -1,6 +1,7 @@
'use strict';
const { Bans } = require(__dirname+'/../../db/')
, Socketio = require(__dirname+'/../../lib/misc/socketio.js')
, config = require(__dirname+'/../../lib/misc/config.js');
module.exports = async (req, res) => {
@ -21,6 +22,14 @@ module.exports = async (req, res) => {
acc[post.ip.cloak] = [];
}
acc[post.ip.cloak].push(post);
if (req.body.ban_reason) {
//send banmessage over websocket
Socketio.emitRoom(`${post.board}-${post.thread || post.postId}`, 'markPost', {
postId: post.postId,
type: 'banmessage',
banmessage: req.body.ban_reason,
});
}
return acc;
}, {});
for (let ip in ipPosts) {

@ -0,0 +1,2 @@
include ../mixins/banmessage.pug
+banmessage(banmessage)

@ -0,0 +1,5 @@
mixin banmessage(banmessage)
p.ban
span.message #{__('USER WAS BANNED FOR THIS POST')}
|
span.reason(data-reason=banmessage) #{banmessage}

@ -1,4 +1,5 @@
include ./report.pug
include ./banmessage.pug
mixin post(post, truncate, manage=false, globalmanage=false, ban=false, overboard=false)
.anchor(id=post.postId)
div(class=`post-container ${post.thread || ban === true ? '' : 'op'}`
@ -160,10 +161,7 @@ mixin post(post, truncate, manage=false, globalmanage=false, ban=false, overboar
time.reltime(datetime=postEditDate.toISOString()) #{postEditDate.toLocaleString(pageLanguage, { hourCycle:'h23' })}
| #{lastEdited[1]}
if post.banmessage
p.ban
span.message #{__('USER WAS BANNED FOR THIS POST')}
|
span.reason(data-reason=post.banmessage) #{post.banmessage}
+banmessage(post.banmessage)
if truncatedMessage !== post.message
div.cb.mt-5.ml-5
| #{__('Message too long.')} #[a.viewfulltext(href=`${postURL}#${post.postId}`) #{__('View the full text')}]

Loading…
Cancel
Save