diff --git a/public/src/client/topic.js b/public/src/client/topic.js index c25a910431..f2e1b0bab4 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -116,7 +116,8 @@ define('forum/topic', [ }; function handleBookmark(tid) { - var bookmark = localStorage.getItem('topic:' + tid + ':bookmark'); + // use the user's bookmark data if available, fallback to local if available + var bookmark = ajaxify.data.bookmark || localStorage.getItem('topic:' + tid + ':bookmark'); var postIndex = getPostIndex(); if (postIndex && window.location.search.indexOf('page=') === -1) { @@ -198,10 +199,9 @@ define('forum/topic', [ } var bookmarkKey = 'topic:' + ajaxify.data.tid + ':bookmark'; - var currentBookmark = localStorage.getItem(bookmarkKey); + var currentBookmark = ajaxify.data.bookmark || localStorage.getItem(bookmarkKey); if (!currentBookmark || parseInt(postIndex, 10) > parseInt(currentBookmark, 10)) { - localStorage.setItem(bookmarkKey, postIndex); if (app.user.uid) { var data = { 'tid': ajaxify.data.tid, @@ -209,6 +209,8 @@ define('forum/topic', [ 'postIndex': postIndex } socket.emit('topics.bookmark', data); + } else { + localStorage.setItem(bookmarkKey, postIndex); } app.removeAlert('bookmark'); } diff --git a/src/topics.js b/src/topics.js index 36a7dc89b1..44e277e04f 100644 --- a/src/topics.js +++ b/src/topics.js @@ -221,7 +221,8 @@ var async = require('async'), category: async.apply(Topics.getCategoryData, tid), threadTools: async.apply(plugins.fireHook, 'filter:topic.thread_tools', {topic: topicData, uid: uid, tools: []}), tags: async.apply(Topics.getTopicTagsObjects, tid), - isFollowing: async.apply(Topics.isFollowing, [tid], uid) + isFollowing: async.apply(Topics.isFollowing, [tid], uid), + bookmark: async.apply(Topics.getUserBookmark, tid, uid) }, function(err, results) { if (err) { return callback(err); @@ -232,6 +233,7 @@ var async = require('async'), topicData.thread_tools = results.threadTools.tools; topicData.tags = results.tags; topicData.isFollowing = results.isFollowing[0]; + topicData.bookmark = results.bookmark; topicData.unreplied = parseInt(topicData.postcount, 10) === 1; topicData.deleted = parseInt(topicData.deleted, 10) === 1;