mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
closes #294
This commit is contained in:
@@ -377,17 +377,6 @@
|
||||
$(this).fadeIn(250);
|
||||
});
|
||||
|
||||
if(data.uploadedImages && data.uploadedImages.length) {
|
||||
$('#images_'+data.pid).html('');
|
||||
for(var i=0; i< data.uploadedImages.length; ++i) {
|
||||
var img = $('<i class="icon-picture icon-1"></i><a href="' + data.uploadedImages[i].url +'"> '+data.uploadedImages[i].name+'</a><br/>');
|
||||
$('#images_' + data.pid).append(img);
|
||||
}
|
||||
} else {
|
||||
$('#images_'+data.pid).html('');
|
||||
}
|
||||
|
||||
console.log('time to recreate images', data);
|
||||
});
|
||||
|
||||
socket.on('api:posts.favourite', function(data) {
|
||||
|
||||
@@ -7,29 +7,33 @@ define(['taskbar'], function(taskbar) {
|
||||
postContainer: undefined,
|
||||
};
|
||||
|
||||
function createImageLabel(img, postImages) {
|
||||
var imageLabel = $('<span class="label label-primary">' + img.name +'</span>');
|
||||
var closeButton = $('<button class="close">×</button>');
|
||||
var uploadsInProgress = [];
|
||||
|
||||
closeButton.on('click', function(e) {
|
||||
function createImagePlaceholder(img) {
|
||||
var text = $('.post-window textarea').val(),
|
||||
textarea = $('.post-window textarea'),
|
||||
imgText = "";
|
||||
|
||||
imageLabel.remove();
|
||||
var index = postImages.indexOf(img);
|
||||
if(index !== -1) {
|
||||
postImages.splice(index, 1);
|
||||
}
|
||||
text += imgText;
|
||||
textarea.val(text + " ");
|
||||
uploadsInProgress.push(1);
|
||||
socket.emit("api:posts.uploadImage", img, function(err, data) {
|
||||
|
||||
var currentText = textarea.val();
|
||||
imgText = "";
|
||||
|
||||
if(!err)
|
||||
textarea.val(currentText.replace(imgText, ""));
|
||||
else
|
||||
textarea.val(currentText.replace(imgText, ""));
|
||||
uploadsInProgress.pop();
|
||||
});
|
||||
|
||||
imageLabel.append(closeButton);
|
||||
return imageLabel;
|
||||
}
|
||||
|
||||
function loadFile(file) {
|
||||
var reader = new FileReader(),
|
||||
dropDiv = $('.post-window .imagedrop'),
|
||||
imagelist = $('.post-window .imagelist'),
|
||||
uuid = dropDiv.parents('[data-uuid]').attr('data-uuid'),
|
||||
posts = composer.posts[uuid];
|
||||
uuid = dropDiv.parents('[data-uuid]').attr('data-uuid');
|
||||
|
||||
$(reader).on('loadend', function(e) {
|
||||
var bin = this.result;
|
||||
@@ -40,11 +44,8 @@ define(['taskbar'], function(taskbar) {
|
||||
data: bin
|
||||
};
|
||||
|
||||
posts.images.push(img);
|
||||
createImagePlaceholder(img);
|
||||
|
||||
var imageLabel = createImageLabel(img, posts.images);
|
||||
|
||||
imagelist.append(imageLabel);
|
||||
dropDiv.hide();
|
||||
});
|
||||
|
||||
@@ -89,7 +90,6 @@ define(['taskbar'], function(taskbar) {
|
||||
drop.on('drop', function(e) {
|
||||
e.preventDefault();
|
||||
var uuid = drop.parents('[data-uuid]').attr('data-uuid'),
|
||||
posts = composer.posts[uuid],
|
||||
dt = e.dataTransfer,
|
||||
files = dt.files;
|
||||
|
||||
@@ -121,7 +121,6 @@ define(['taskbar'], function(taskbar) {
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<textarea tabIndex="2"></textarea>' +
|
||||
'<div class="imagelist"></div>'+
|
||||
'<div class="imagedrop"><div>Drag and Drop Images Here</div></div>'+
|
||||
'<div class="btn-toolbar action-bar">' +
|
||||
'<div class="btn-group" style="float: right; margin-right: -8px">' +
|
||||
@@ -151,8 +150,7 @@ define(['taskbar'], function(taskbar) {
|
||||
cid: threadData.cid,
|
||||
pid: threadData.pid,
|
||||
title: threadData.title || '',
|
||||
body: threadData.body || '',
|
||||
images: threadData.uploadedImages || []
|
||||
body: threadData.body || ''
|
||||
};
|
||||
composer.load(uuid);
|
||||
} else {
|
||||
@@ -265,18 +263,6 @@ define(['taskbar'], function(taskbar) {
|
||||
});
|
||||
}
|
||||
|
||||
function createPostImages(images) {
|
||||
var imagelist = $(composer.postContainer).find('.imagelist');
|
||||
imagelist.empty();
|
||||
|
||||
if(images && images.length) {
|
||||
for(var i=0; i<images.length; ++i) {
|
||||
var imageLabel = createImageLabel(images[i], images);
|
||||
imagelist.append(imageLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
composer.load = function(post_uuid) {
|
||||
var post_data = composer.posts[post_uuid],
|
||||
titleEl = composer.postContainer.querySelector('input'),
|
||||
@@ -299,7 +285,6 @@ define(['taskbar'], function(taskbar) {
|
||||
}
|
||||
bodyEl.value = post_data.body;
|
||||
|
||||
createPostImages(post_data.images);
|
||||
|
||||
// Direct user focus to the correct element
|
||||
if ((parseInt(post_data.tid) || parseInt(post_data.pid)) > 0) {
|
||||
@@ -334,6 +319,16 @@ define(['taskbar'], function(taskbar) {
|
||||
titleEl.value = titleEl.value.trim();
|
||||
bodyEl.value = bodyEl.value.trim();
|
||||
|
||||
if(uploadsInProgress.length) {
|
||||
return app.alert({
|
||||
type: 'warning',
|
||||
timeout: 2000,
|
||||
title: 'Still uploading',
|
||||
message: "Please wait for uploads to complete.",
|
||||
alert_id: 'post_error'
|
||||
});
|
||||
}
|
||||
|
||||
if (titleEl.value.length < config.minimumTitleLength) {
|
||||
return app.alert({
|
||||
type: 'danger',
|
||||
@@ -359,21 +354,18 @@ define(['taskbar'], function(taskbar) {
|
||||
socket.emit('api:topics.post', {
|
||||
'title' : titleEl.value,
|
||||
'content' : bodyEl.value,
|
||||
'category_id' : postData.cid,
|
||||
images: composer.posts[post_uuid].images
|
||||
'category_id' : postData.cid
|
||||
});
|
||||
} else if (parseInt(postData.tid) > 0) {
|
||||
socket.emit('api:posts.reply', {
|
||||
'topic_id' : postData.tid,
|
||||
'content' : bodyEl.value,
|
||||
images: composer.posts[post_uuid].images
|
||||
'content' : bodyEl.value
|
||||
});
|
||||
} else if (parseInt(postData.pid) > 0) {
|
||||
socket.emit('api:posts.edit', {
|
||||
pid: postData.pid,
|
||||
content: bodyEl.value,
|
||||
title: titleEl.value,
|
||||
images: composer.posts[post_uuid].images
|
||||
title: titleEl.value
|
||||
});
|
||||
}
|
||||
|
||||
@@ -383,7 +375,6 @@ define(['taskbar'], function(taskbar) {
|
||||
composer.discard = function(post_uuid) {
|
||||
if (composer.posts[post_uuid]) {
|
||||
$(composer.postContainer).find('.imagedrop').hide();
|
||||
$(composer.postContainer).find('.imagelist').empty();
|
||||
delete composer.posts[post_uuid];
|
||||
composer.minimize();
|
||||
taskbar.discard('composer', post_uuid);
|
||||
|
||||
@@ -56,11 +56,6 @@
|
||||
</div>
|
||||
|
||||
<div id="content_{main_posts.pid}" class="post-content">{main_posts.content}</div>
|
||||
<div id="images_{main_posts.pid}" class="post-images">
|
||||
<!-- BEGIN uploadedImages -->
|
||||
<i class="icon-picture icon-1"></i><a href="{main_posts.uploadedImages.url}"> {main_posts.uploadedImages.name}</a><br/>
|
||||
<!-- END uploadedImages -->
|
||||
</div>
|
||||
<div class="post-signature">{main_posts.signature}</div>
|
||||
<div class="profile-block">
|
||||
<span class="pull-right">
|
||||
@@ -116,11 +111,6 @@
|
||||
</div>
|
||||
|
||||
<div id="content_{posts.pid}" class="post-content">{posts.content}</div>
|
||||
<div id="images_{posts.pid}" class="post-images">
|
||||
<!-- BEGIN uploadedImages -->
|
||||
<i class="icon-picture icon-1"></i><a href="{posts.uploadedImages.url}"> {posts.uploadedImages.name}</a><br/>
|
||||
<!-- END uploadedImages -->
|
||||
</div>
|
||||
<div class="post-signature">{posts.signature}</div>
|
||||
<div class="profile-block">
|
||||
<span class="pull-right">
|
||||
|
||||
@@ -56,7 +56,7 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
|
||||
PostTools.edit = function(uid, pid, title, content, images) {
|
||||
PostTools.edit = function(uid, pid, title, content) {
|
||||
var success = function() {
|
||||
posts.setPostField(pid, 'content', content);
|
||||
posts.setPostField(pid, 'edited', Date.now());
|
||||
@@ -67,11 +67,6 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
posts.uploadPostImages(pid, images, function(err, uploadedImages) {
|
||||
next(err, uploadedImages);
|
||||
});
|
||||
},
|
||||
function(next) {
|
||||
posts.getPostField(pid, 'tid', function(tid) {
|
||||
PostTools.isMain(pid, tid, function(isMainPost) {
|
||||
@@ -90,12 +85,12 @@ var RDB = require('./redis.js'),
|
||||
PostTools.toHTML(content, next);
|
||||
}
|
||||
], function(err, results) {
|
||||
io.sockets.in('topic_' + results[1].tid).emit('event:post_edited', {
|
||||
console.log("TEEEST");
|
||||
io.sockets.in('topic_' + results[0].tid).emit('event:post_edited', {
|
||||
pid: pid,
|
||||
title: title,
|
||||
isMainPost: results[1].isMainPost,
|
||||
content: results[2],
|
||||
uploadedImages:results[0]
|
||||
isMainPost: results[0].isMainPost,
|
||||
content: results[1]
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
60
src/posts.js
60
src/posts.js
@@ -166,17 +166,6 @@ var RDB = require('./redis.js'),
|
||||
postData['edited-class'] = postData.editor !== '' ? '' : 'none';
|
||||
postData['relativeEditTime'] = postData.edited !== '0' ? utils.relativeTime(postData.edited) : '';
|
||||
|
||||
if(postData.uploadedImages) {
|
||||
try {
|
||||
postData.uploadedImages = JSON.parse(postData.uploadedImages);
|
||||
} catch(err) {
|
||||
postData.uploadedImages = [];
|
||||
winston.err(err);
|
||||
}
|
||||
} else {
|
||||
postData.uploadedImages = [];
|
||||
}
|
||||
|
||||
postTools.toHTML(postData.content, function(err, content) {
|
||||
postData.content = content;
|
||||
posts.push(postData);
|
||||
@@ -226,7 +215,7 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
|
||||
Posts.reply = function(tid, uid, content, images, callback) {
|
||||
Posts.reply = function(tid, uid, content, callback) {
|
||||
if(content) {
|
||||
content = content.trim();
|
||||
}
|
||||
@@ -242,7 +231,7 @@ var RDB = require('./redis.js'),
|
||||
return;
|
||||
}
|
||||
|
||||
Posts.create(uid, tid, content, images, function(postData) {
|
||||
Posts.create(uid, tid, content, function(postData) {
|
||||
if (postData) {
|
||||
|
||||
topics.markUnRead(tid);
|
||||
@@ -270,7 +259,7 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
};
|
||||
|
||||
Posts.create = function(uid, tid, content, images, callback) {
|
||||
Posts.create = function(uid, tid, content, callback) {
|
||||
if (uid === null) {
|
||||
callback(null);
|
||||
return;
|
||||
@@ -293,7 +282,6 @@ var RDB = require('./redis.js'),
|
||||
'editor': '',
|
||||
'edited': 0,
|
||||
'deleted': 0,
|
||||
'uploadedImages': '[]',
|
||||
'fav_button_class': '',
|
||||
'fav_star_class': 'icon-star-empty',
|
||||
'show_banned': 'hide',
|
||||
@@ -331,16 +319,6 @@ var RDB = require('./redis.js'),
|
||||
user.onNewPostMade(uid, tid, pid, timestamp);
|
||||
|
||||
async.parallel({
|
||||
uploadedImages: function(next) {
|
||||
Posts.uploadPostImages(postData.pid, images, function(err, uploadedImages) {
|
||||
if(err) {
|
||||
winston.error('Uploading images failed!', err.stack);
|
||||
next(null, []);
|
||||
} else {
|
||||
next(null, uploadedImages);
|
||||
}
|
||||
});
|
||||
},
|
||||
content: function(next) {
|
||||
plugins.fireHook('filter:post.get', postData, function(postData) {
|
||||
postTools.toHTML(postData.content, function(err, content) {
|
||||
@@ -349,7 +327,6 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
}, function(err, results) {
|
||||
postData.uploadedImages = results.uploadedImages;
|
||||
postData.content = results.content;
|
||||
callback(postData);
|
||||
});
|
||||
@@ -365,46 +342,29 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
|
||||
Posts.uploadPostImages = function(pid, images, callback) {
|
||||
Posts.uploadPostImage = function(image, callback) {
|
||||
var imgur = require('./imgur');
|
||||
imgur.setClientID(meta.config.imgurClientID);
|
||||
|
||||
if(!images)
|
||||
return callback(null, []);
|
||||
|
||||
var uploadedImages = images.filter(function(image) { return !!image.url; });
|
||||
|
||||
function uploadImage(image, next) {
|
||||
if(!image.data)
|
||||
return next(null);
|
||||
if(!image)
|
||||
return callback('invalid image', null);
|
||||
|
||||
imgur.upload(image.data, 'base64', function(err, data) {
|
||||
if(err) {
|
||||
next(err);
|
||||
callback('Can\'t upload image!', null);
|
||||
} else {
|
||||
if(data.success) {
|
||||
var img= {url:data.data.link, name:image.name};
|
||||
uploadedImages.push(img);
|
||||
next(null);
|
||||
|
||||
callback(null, img);
|
||||
} else {
|
||||
winston.error('Can\'t upload image, did you set imgurClientID?');
|
||||
next(data);
|
||||
callback("upload error", null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async.each(images, uploadImage, function(err) {
|
||||
if(!err) {
|
||||
Posts.setPostField(pid, 'uploadedImages', JSON.stringify(uploadedImages));
|
||||
callback(null, uploadedImages);
|
||||
} else {
|
||||
console.log(err);
|
||||
callback(err, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Posts.getPostsByUid = function(uid, start, end, callback) {
|
||||
|
||||
user.getPostIds(uid, start, end, function(pids) {
|
||||
|
||||
@@ -604,7 +604,7 @@ var RDB = require('./redis.js')
|
||||
});
|
||||
}
|
||||
|
||||
Topics.post = function(uid, title, content, category_id, images, callback) {
|
||||
Topics.post = function(uid, title, content, category_id, callback) {
|
||||
if (!category_id)
|
||||
throw new Error('Attempted to post without a category_id');
|
||||
|
||||
@@ -678,7 +678,7 @@ var RDB = require('./redis.js')
|
||||
|
||||
feed.updateCategory(category_id);
|
||||
|
||||
posts.create(uid, tid, content, images, function(postData) {
|
||||
posts.create(uid, tid, content, function(postData) {
|
||||
if (postData) {
|
||||
|
||||
// Auto-subscribe the post creator to the newly created topic
|
||||
|
||||
@@ -322,7 +322,7 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
|
||||
socket.on('api:topics.post', function(data) {
|
||||
|
||||
topics.post(uid, data.title, data.content, data.category_id, data.images, function(err, result) {
|
||||
topics.post(uid, data.title, data.content, data.category_id, function(err, result) {
|
||||
if(err) {
|
||||
if(err.message === 'not-logged-in') {
|
||||
socket.emit('event:alert', {
|
||||
@@ -379,7 +379,7 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
return;
|
||||
}
|
||||
|
||||
posts.reply(data.topic_id, uid, data.content, data.images, function(err, result) {
|
||||
posts.reply(data.topic_id, uid, data.content, function(err, result) {
|
||||
if(err) {
|
||||
if(err.message === 'content-too-short') {
|
||||
posts.emitContentTooShortAlert(socket);
|
||||
@@ -477,6 +477,10 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('api:posts.uploadImage', function(data, callback) {
|
||||
posts.uploadPostImage(data, callback);
|
||||
});
|
||||
|
||||
socket.on('api:posts.getRawPost', function(data) {
|
||||
posts.getPostField(data.pid, 'content', function(raw) {
|
||||
socket.emit('api:posts.getRawPost', { post: raw });
|
||||
@@ -623,14 +627,7 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
|
||||
async.parallel([
|
||||
function(next) {
|
||||
posts.getPostFields(data.pid, ['content', 'uploadedImages'], function(raw) {
|
||||
try {
|
||||
raw.uploadedImages = JSON.parse(raw.uploadedImages);
|
||||
} catch(e) {
|
||||
winston.err(e);
|
||||
raw.uploadedImages = [];
|
||||
}
|
||||
|
||||
posts.getPostFields(data.pid, ['content'], function(raw) {
|
||||
next(null, raw);
|
||||
});
|
||||
},
|
||||
@@ -643,8 +640,7 @@ var SocketIO = require('socket.io').listen(global.server, {
|
||||
socket.emit('api:composer.push', {
|
||||
title: results[1],
|
||||
pid: data.pid,
|
||||
body: results[0].content,
|
||||
uploadedImages: results[0].uploadedImages
|
||||
body: results[0].content
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user