Skip to content

Node.js based forum software built for the modern web

#656

Baris Soner Usakli36ae56834978
diff --git a/public/language/en_GB/topic.json b/public/language/en_GB/topic.json
index 0b1d903019..09a9eda671 100644
--- a/public/language/en_GB/topic.json
+++ b/public/language/en_GB/topic.json
@@ -18,6 +18,9 @@
"link": "Link",
"share": "Share",
"tools": "Tools",
+ "flag": "Flag",
+
+ "flag_title":"Flag this post for moderation",
"thread_tools.title": "Thread Tools",
"thread_tools.markAsUnreadForAll": "Mark Unread",
diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js
index 59d80041e8..2814f8342a 100644
--- a/public/src/forum/topic.js
+++ b/public/src/forum/topic.js
@@ -431,21 +431,27 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
$('#post-container').on('click', '.favourite', function() {
var pid = $(this).parents('.post-row').attr('data-pid');
- var uid = $(this).parents('.post-row').attr('data-uid');
- if ($(this).attr('data-favourited') == 'false') {
- socket.emit('posts.favourite', {
- pid: pid,
- room_id: app.currentRoom
- });
- } else {
- socket.emit('posts.unfavourite', {
- pid: pid,
- room_id: app.currentRoom
- });
- }
+ var method = $(this).attr('data-favourited') == 'false' ? 'posts.favourite' : 'posts.unfavourite';
+
+ socket.emit(method, {
+ pid: pid,
+ room_id: app.currentRoom
+ });
});
+ $('#post-container').on('click', '.flag', function() {
+ var pid = $(this).parents('.post-row').attr('data-pid');
+
+ socket.emit('posts.flag', pid, function(err) {
+ if(err) {
+ return app.alertError(err.message);
+ }
+ app.alertSuccess('This post has been flagged for moderation.');
+ });
+ });
+
+
$('#post-container').on('shown.bs.dropdown', '.share-dropdown', function() {
var pid = $(this).parents('.post-row').attr('data-pid');
$('#post_' + pid + '_link').val(window.location.href + "#" + pid);
diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl
index 4feedc1c23..51a1d6da32 100644
--- a/public/templates/topic.tpl
+++ b/public/templates/topic.tpl
@@ -66,8 +66,9 @@
<div class="btn-group">
<!-- IF @first -->
- <button class="btn btn-sm btn-default follow" type="button" title="Be notified of new replies in this topic"><i class="fa fa-eye"></i></button>
+ <button class="btn btn-sm btn-default follow" type="button" title="[[topic:notify_me]]"><i class="fa fa-eye"></i></button>
<!-- ENDIF @first -->
+ <button class="btn btn-sm btn-default flag" type="button" title="[[topic:flag_title]]"><i class="fa fa-flag-o"></i></button>
<button data-favourited="{posts.favourited}" class="favourite favourite-tooltip btn btn-sm btn-default <!-- IF posts.favourited --> btn-warning <!-- ENDIF posts.favourited -->" type="button">
<span class="favourite-text">[[topic:favourite]]</span>
<span class="post_rep_{posts.pid}">{posts.reputation} </span>
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index 8581ad3a98..940b8bb111 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -1,8 +1,13 @@
-var posts = require('../posts'),
+var async = require('async'),
+ nconf = require('nconf'),
+
+ posts = require('../posts'),
meta = require('../meta'),
topics = require('../topics'),
favourites = require('../favourites'),
postTools = require('../postTools'),
+ notifications = require('../notifications'),
+ groups = require('../groups'),
user = require('../user'),
index = require('./index'),
@@ -208,4 +213,36 @@ SocketPosts.getPidPage = function(socket, pid, callback) {
posts.getPidPage(pid, callback);
}
+SocketPosts.flag = function(socket, pid, callback) {
+ var message = '',
+ path = '';
+
+ async.waterfall([
+ function(next) {
+ user.getUserField(socket.uid, 'username', next);
+ },
+ function(username, next) {
+ message = username + ' flagged a post.';
+ posts.getPostField(pid, 'tid', next);
+ },
+ function(tid, next) {
+ topics.getTopicField(tid, 'slug', next)
+ },
+ function(topicSlug, next) {
+ path = nconf.get('relative_path') + '/topic/' + topicSlug + '#' + pid;
+ groups.getByGroupName('administrators', {}, next);
+ },
+ function(adminGroup, next) {
+
+ notifications.create(message, path, 'post_flag:' + pid, function(nid) {
+
+ notifications.push(nid, adminGroup.members, function() {
+ console.log('derp');
+ next(null);
+ });
+ });
+ }
+ ], callback);
+}
+
module.exports = SocketPosts;
\ No newline at end of file