move mark text to bottom
make a bit more generic
add support for moves as well
opacity .75 on the post contents for a bit more affordance
jschan
Thomas Lynch 3 years ago
parent de9b82ebad
commit 11609b37b8
No known key found for this signature in database
GPG Key ID: 36A72F7C62CF8480
  1. 8
      gulp/res/css/style.css
  2. 26
      gulp/res/js/live.js
  3. 2
      models/forms/deletepost.js
  4. 38
      models/forms/moveposts.js

@ -1026,12 +1026,16 @@ input:invalid, textarea:invalid {
background: none; background: none;
} }
.deleted .post-info::before { .post-container.marked::after {
content: "Deleted "; content: attr(data-mark) " ";
font-weight: bold; font-weight: bold;
color: var(--title-color); color: var(--title-color);
} }
.post-container.marked .post-data, .post-container.marked .post-info {
opacity: 0.75
}
.anchor:target + .post-container, .anchor:target + .post-container,
.anchor:target + .catalog-tile, .anchor:target + .catalog-tile,
.post-container.highlighted, .post-container.highlighted,

@ -26,16 +26,24 @@ window.addEventListener('settingsReady', function(event) { //after domcontentloa
lastPostIds[board] = Math.max((lastPostIds[board] || 0), postId); lastPostIds[board] = Math.max((lastPostIds[board] || 0), postId);
} }
//add "deleted" title text to posts to show it was deleted //add text before post-info to show posts deleted, moved, etc
const deletePost = (data) => { const markPost = (data) => {
console.log('got delete post message', data); console.log('got mark post message', data);
const anchor = document.getElementById(data.postId); const anchor = document.getElementById(data.postId);
const postContainer = anchor.nextSibling; const postContainer = anchor.nextSibling;
postContainer.classList.add('deleted'); postContainer.classList.add('marked');
postContainer.setAttribute('data-mark', data.mark);
//handle any special cases for different marks
switch (data.type) {
case "delete":
case "move":
if (postContainer.classList.contains('op')) { if (postContainer.classList.contains('op')) {
//OP was deleted, so every post in the thread is "deleted". //moved or delete OPs then apply to whole thread
const postContainers = document.getElementsByClassName('post-container'); const postContainers = document.getElementsByClassName('post-container');
Array.from(postContainers).forEach(e => e.classList.add('deleted')); Array.from(postContainers).forEach(e => {
e.classList.add('marked')
e.setAttribute('data-mark', data.mark);
});
//remove new reply buttons and postform //remove new reply buttons and postform
document.getElementById('postform').remove(); document.getElementById('postform').remove();
const postButtons = document.getElementsByClassName('post-button'); const postButtons = document.getElementsByClassName('post-button');
@ -45,6 +53,10 @@ window.addEventListener('settingsReady', function(event) { //after domcontentloa
socket.disconnect(); socket.disconnect();
} }
} }
break;
default:
//nothing special
}
}; };
const newPost = (data) => { const newPost = (data) => {
@ -257,7 +269,7 @@ window.addEventListener('settingsReady', function(event) { //after domcontentloa
enableLive(); enableLive();
}); });
socket.on('newPost', newPost); socket.on('newPost', newPost);
socket.on('deletePost', deletePost); socket.on('markPost', markPost);
} else { } else {
//websocket not supported, update with polling to api //websocket not supported, update with polling to api
updateButton.removeAttribute('style'); updateButton.removeAttribute('style');

@ -117,7 +117,7 @@ module.exports = async (posts, board, all=false) => {
const deletedPosts = await Posts.deleteMany(postMongoIds).then(result => result.deletedCount); const deletedPosts = await Posts.deleteMany(postMongoIds).then(result => result.deletedCount);
//emit the deletes to thread sockets (not recent sockets [yet?]) //emit the deletes to thread sockets (not recent sockets [yet?])
for (let i = 0; i < deleteEmits.length; i++) { for (let i = 0; i < deleteEmits.length; i++) {
Socketio.emitRoom(deleteEmits[i].room, 'deletePost', { postId: deleteEmits[i].postId }); Socketio.emitRoom(deleteEmits[i].room, 'markPost', { postId: deleteEmits[i].postId, type: 'delete', mark: 'Deleted' });
} }
if (all === false) { if (all === false) {

@ -3,6 +3,7 @@
const uploadDirectory = require(__dirname+'/../../helpers/files/uploadDirectory.js') const uploadDirectory = require(__dirname+'/../../helpers/files/uploadDirectory.js')
, { remove } = require('fs-extra') , { remove } = require('fs-extra')
, { Posts } = require(__dirname+'/../../db/') , { Posts } = require(__dirname+'/../../db/')
, Socketio = require(__dirname+'/../../socketio.js')
, quoteHandler = require(__dirname+'/../../helpers/posting/quotes.js') , quoteHandler = require(__dirname+'/../../helpers/posting/quotes.js')
, { markdown } = require(__dirname+'/../../helpers/posting/markdown.js') , { markdown } = require(__dirname+'/../../helpers/posting/markdown.js')
, { createHash } = require('crypto') , { createHash } = require('crypto')
@ -20,21 +21,18 @@ module.exports = async (req, res) => {
return acc; return acc;
}, { threads: [], postIds: [], postMongoIds: [] }); }, { threads: [], postIds: [], postMongoIds: [] });
//console.log(threads, postIds, postMongoIds) //maybe should filter these? because it will include threads from which child posts are already fetched in the action handler, unlike the deleteposts model
const moveEmits = res.locals.posts.reduce((acc, post) => {
acc.push({
room: `${post.board}-${post.thread || post.postId}`,
postId: post.postId,
});
return acc;
}, []);
const backlinkRebuilds = new Set(); const backlinkRebuilds = new Set();
const bulkWrites = []; const bulkWrites = [];
if (threads.length > 0) {
//threads moved, so their html/json doesnt need to exist anymore
await Promise.all(threads.map(thread => {
return Promise.all([
remove(`${uploadDirectory}/html/${thread.board}/thread/${thread.postId}.html`),
remove(`${uploadDirectory}/json/${thread.board}/thread/${thread.postId}.json`)
]);
}));
}
//remove backlinks from selected posts that link to unselected posts //remove backlinks from selected posts that link to unselected posts
bulkWrites.push({ bulkWrites.push({
'updateMany': { 'updateMany': {
@ -95,6 +93,7 @@ module.exports = async (req, res) => {
acc.replyfiles += p.files.length; acc.replyfiles += p.files.length;
return acc; return acc;
}, { replyposts: 0, replyfiles: 0 }); }, { replyposts: 0, replyfiles: 0 });
bulkWrites.push({ bulkWrites.push({
'updateOne': { 'updateOne': {
'filter': { 'filter': {
@ -112,6 +111,11 @@ module.exports = async (req, res) => {
const movedPosts = await Posts.move(postMongoIds, req.body.move_to_thread).then(result => result.modifiedCount); const movedPosts = await Posts.move(postMongoIds, req.body.move_to_thread).then(result => result.modifiedCount);
//emit markPost moves
for (let i = 0; i < moveEmits.length; i++) {
Socketio.emitRoom(moveEmits[i].room, 'markPost', { postId: moveEmits[i].postId, type: 'move', mark: 'Moved' });
}
//get posts that quoted moved posts so we can remarkup them //get posts that quoted moved posts so we can remarkup them
if (backlinkRebuilds.size > 0) { if (backlinkRebuilds.size > 0) {
const remarkupPosts = await Posts.globalGetPosts([...backlinkRebuilds]); const remarkupPosts = await Posts.globalGetPosts([...backlinkRebuilds]);
@ -160,8 +164,6 @@ module.exports = async (req, res) => {
})); }));
} }
//console.log(require('util').inspect(bulkWrites, {depth:null}))
/* /*
- post A quotes B, then A is moved to another thread: WORKS (removes backlink on B) - post A quotes B, then A is moved to another thread: WORKS (removes backlink on B)
- moving post A back into thread with B and backlink gets readded: WORKS - moving post A back into thread with B and backlink gets readded: WORKS
@ -174,6 +176,16 @@ module.exports = async (req, res) => {
await Posts.db.bulkWrite(bulkWrites); await Posts.db.bulkWrite(bulkWrites);
} }
//delete html/json for no longer existing threads, because op was moved
if (threads.length > 0) {
await Promise.all(threads.map(thread => {
return Promise.all([
remove(`${uploadDirectory}/html/${thread.board}/thread/${thread.postId}.html`),
remove(`${uploadDirectory}/json/${thread.board}/thread/${thread.postId}.json`)
]);
}));
}
return { return {
message: 'Moved posts', message: 'Moved posts',
action: movedPosts > 0, action: movedPosts > 0,

Loading…
Cancel
Save