mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	stores the user's bookmark on the server
This commit is contained in:
		| @@ -197,10 +197,19 @@ define('forum/topic', [ | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		var currentBookmark = localStorage.getItem('topic:' + ajaxify.data.tid + ':bookmark'); | ||||
| 		var bookmarkKey = 'topic:' + ajaxify.data.tid + ':bookmark'; | ||||
| 		var currentBookmark = localStorage.getItem(bookmarkKey); | ||||
|  | ||||
| 		if (!currentBookmark || parseInt(postIndex, 10) >= parseInt(currentBookmark, 10)) { | ||||
| 			localStorage.setItem('topic:' + ajaxify.data.tid + ':bookmark', postIndex); | ||||
| 		if (!currentBookmark || parseInt(postIndex, 10) > parseInt(currentBookmark, 10)) { | ||||
| 			localStorage.setItem(bookmarkKey, postIndex); | ||||
| 			if (app.user.uid) { | ||||
| 				var data = { | ||||
| 					'tid':  ajaxify.data.tid, | ||||
| 					'uid': app.user.uid, | ||||
| 					'postIndex': postIndex | ||||
| 				} | ||||
| 				socket.emit('topics.bookmark', data); | ||||
| 			} | ||||
| 			app.removeAlert('bookmark'); | ||||
| 		} | ||||
|  | ||||
|   | ||||
| @@ -96,6 +96,11 @@ SocketTopics.postcount = function(socket, tid, callback) { | ||||
| 	topics.getTopicField(tid, 'postcount', callback); | ||||
| }; | ||||
|  | ||||
| SocketTopics.bookmark = function(socket, data, callback) { | ||||
| 	// data contains tid, uid, and postIndex | ||||
| 	topics.setUserBookmark(data, callback); | ||||
| } | ||||
|  | ||||
| SocketTopics.markAsRead = function(socket, tids, callback) { | ||||
| 	if(!Array.isArray(tids) || !socket.uid) { | ||||
| 		return callback(new Error('[[error:invalid-data]]')); | ||||
|   | ||||
| @@ -327,6 +327,14 @@ var async = require('async'), | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	Topics.getUserBookmark = function (tid, uid, callback) { | ||||
| 		Topics.getTopicField(tid + ':bookmarks', uid, callback); | ||||
| 	} | ||||
|  | ||||
| 	Topics.setUserBookmark = function(data, callback) { | ||||
| 		Topics.setTopicField(data.tid + ':bookmarks', data.uid, data.postIndex, callback); | ||||
| 	} | ||||
|  | ||||
| 	Topics.getTopicField = function(tid, field, callback) { | ||||
| 		db.getObjectField('topic:' + tid, field, callback); | ||||
| 	}; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user