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 2 years ago
parent de9b82ebad
commit 11609b37b8
No known key found for this signature in database
GPG Key ID: 36A72F7C62CF8480
  1. 12
      gulp/res/css/style.css
  2. 46
      gulp/res/js/live.js
  3. 2
      models/forms/deletepost.js
  4. 38
      models/forms/moveposts.js

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

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

@ -117,7 +117,7 @@ module.exports = async (posts, board, all=false) => {
const deletedPosts = await Posts.deleteMany(postMongoIds).then(result => result.deletedCount);
//emit the deletes to thread sockets (not recent sockets [yet?])
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) {

@ -3,6 +3,7 @@
const uploadDirectory = require(__dirname+'/../../helpers/files/uploadDirectory.js')
, { remove } = require('fs-extra')
, { Posts } = require(__dirname+'/../../db/')
, Socketio = require(__dirname+'/../../socketio.js')
, quoteHandler = require(__dirname+'/../../helpers/posting/quotes.js')
, { markdown } = require(__dirname+'/../../helpers/posting/markdown.js')
, { createHash } = require('crypto')
@ -20,21 +21,18 @@ module.exports = async (req, res) => {
return acc;
}, { 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 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
bulkWrites.push({
'updateMany': {
@ -95,6 +93,7 @@ module.exports = async (req, res) => {
acc.replyfiles += p.files.length;
return acc;
}, { replyposts: 0, replyfiles: 0 });
bulkWrites.push({
'updateOne': {
'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);
//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
if (backlinkRebuilds.size > 0) {
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)
- 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);
}
//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 {
message: 'Moved posts',
action: movedPosts > 0,

Loading…
Cancel
Save