Skip to content

Commit

Permalink
closes #1369
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Aug 14, 2014
1 parent d12a526 commit c9c4548
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 28 deletions.
5 changes: 4 additions & 1 deletion public/language/en_GB/user.json
Expand Up @@ -71,5 +71,8 @@
"notification_sounds" : "Play a sound when you receive a notification.",

"browsing": "Browsing Settings",
"open_links_in_new_tab": "Open outgoing links in new tab?"
"open_links_in_new_tab": "Open outgoing links in new tab?",

"follow_topics_you_reply_to": "Follow topics that you reply to.",
"follow_topics_you_create": "Follow topics you create."
}
15 changes: 15 additions & 0 deletions src/threadTools.js
Expand Up @@ -240,4 +240,19 @@ var winston = require('winston'),
], callback);
};

ThreadTools.follow = function(tid, uid, callback) {
callback = callback || function() {};
async.waterfall([
function (next) {
ThreadTools.exists(tid, next);
},
function (exists, next) {
if (!exists) {
return next(new Error('[[error:no-topic]]'));
}
db.setAdd('tid:' + tid + ':followers', uid, next);
}
], callback);
};

}(exports));
63 changes: 37 additions & 26 deletions src/topics/create.js
Expand Up @@ -105,45 +105,53 @@ module.exports = function(Topics) {
if(!canCreate) {
return next(new Error('[[error:no-privileges]]'));
}
next();
},
function(next) {
user.isReadyToPost(uid, next);
},
function(next) {
plugins.fireHook('filter:topic.post', data, next);
},
function(filteredData, next) {
content = filteredData.content || data.content;
next();
},
function(next) {
Topics.create({uid: uid, title: title, cid: cid, thumb: data.thumb, tags: data.tags}, next);
},
function(tid, next) {
Topics.reply({uid:uid, tid:tid, content:content, req: data.req}, next);
},
function(postData, next) {
threadTools.toggleFollow(postData.tid, uid);
next(null, postData);
},
function(postData, next) {
Topics.getTopicsByTids([postData.tid], 0, function(err, topicData) {
if(err) {
return next(err);
async.parallel({
postData: function(next) {
next(null, postData);
},
settings: function(next) {
user.getSettings(uid, function(err, settings) {
if (err) {
return next(err);
}
if (settings.followTopicsOnCreate) {
threadTools.follow(postData.tid, uid, next);
} else {
next();
}
});
},
topicData: function(next) {
Topics.getTopicsByTids([postData.tid], 0, next);
}
if(!topicData || !topicData.length) {
return next(new Error('[[error:no-topic]]'));
}
topicData = topicData[0];
topicData.unreplied = 1;
}, next);
},
function(data, next) {
if(!Array.isArray(data.topicData) || !data.topicData.length) {
return next(new Error('[[error:no-topic]]'));
}

data.topicData = data.topicData[0];
data.topicData.unreplied = 1;

plugins.fireHook('action:topic.post', topicData);
plugins.fireHook('action:topic.post', data.topicData);

next(null, {
topicData: topicData,
postData: postData
});
next(null, {
topicData: data.topicData,
postData: data.postData
});
}
], callback);
Expand Down Expand Up @@ -178,9 +186,6 @@ module.exports = function(Topics) {
if (!canReply) {
return next(new Error('[[error:no-privileges]]'));
}
next();
},
function(next) {
user.isReadyToPost(uid, next);
},
function(next) {
Expand Down Expand Up @@ -215,6 +220,12 @@ module.exports = function(Topics) {
function(topicData, next) {
topicData.title = validator.escape(topicData.title);
postData.topic = topicData;
user.getSettings(uid, next);
},
function(settings, next) {
if (settings.followTopicsOnReply) {
threadTools.follow(postData.tid, uid);
}
posts.getPidIndex(postData.pid, next);
},
function(index, next) {
Expand Down
6 changes: 5 additions & 1 deletion src/user/settings.js
Expand Up @@ -33,6 +33,8 @@ module.exports = function(User) {
settings.notificationSounds = settings.notificationSounds ? parseInt(settings.notificationSounds, 10) === 1 : true;
settings.language = settings.language || meta.config.defaultLang || 'en_GB';
settings.topicPostSort = settings.topicPostSort || meta.config.topicPostSort || 'oldest_to_newest';
settings.followTopicsOnCreate = settings.followTopicsOnCreate ? parseInt(settings.followTopicsOnCreate, 10) === 1 : true;
settings.followTopicsOnReply = settings.followTopicsOnReply ? parseInt(settings.followTopicsOnReply, 10) === 1 : false;
callback(null, settings);
});
});
Expand Down Expand Up @@ -80,7 +82,9 @@ module.exports = function(User) {
topicsPerPage: data.topicsPerPage,
postsPerPage: data.postsPerPage,
notificationSounds: data.notificationSounds,
language: data.language || meta.config.defaultLang
language: data.language || meta.config.defaultLang,
followTopicsOnCreate: data.followTopicsOnCreate,
followTopicsOnReply: data.followTopicsOnReply
}, callback);
};

Expand Down

0 comments on commit c9c4548

Please sign in to comment.