mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	refactor: simplify mocks.post as it only needs minimal data for saving into db
This commit is contained in:
		| @@ -1,7 +1,5 @@ | |||||||
| 'use strict'; | 'use strict'; | ||||||
|  |  | ||||||
| const winston = require('winston'); |  | ||||||
|  |  | ||||||
| const db = require('../database'); | const db = require('../database'); | ||||||
| const user = require('../user'); | const user = require('../user'); | ||||||
|  |  | ||||||
| @@ -46,6 +44,7 @@ Mocks.profile = async (actors, callerUid = 0) => { | |||||||
| 			fullname: name, | 			fullname: name, | ||||||
| 			joindate: new Date(published).getTime(), | 			joindate: new Date(published).getTime(), | ||||||
| 			picture, | 			picture, | ||||||
|  | 			status: 'offline', | ||||||
| 			'icon:text': (preferredUsername[0] || '').toUpperCase(), | 			'icon:text': (preferredUsername[0] || '').toUpperCase(), | ||||||
| 			'icon:bgColor': bgColor, | 			'icon:bgColor': bgColor, | ||||||
| 			uploadedpicture: undefined, | 			uploadedpicture: undefined, | ||||||
| @@ -68,8 +67,6 @@ Mocks.profile = async (actors, callerUid = 0) => { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| Mocks.post = async (objects) => { | Mocks.post = async (objects) => { | ||||||
| 	const postCache = require('../posts/cache'); |  | ||||||
|  |  | ||||||
| 	let single = false; | 	let single = false; | ||||||
| 	if (!Array.isArray(objects)) { | 	if (!Array.isArray(objects)) { | ||||||
| 		single = true; | 		single = true; | ||||||
| @@ -92,33 +89,21 @@ Mocks.post = async (objects) => { | |||||||
| 			inReplyTo: toPid, | 			inReplyTo: toPid, | ||||||
| 		} = object; | 		} = object; | ||||||
|  |  | ||||||
| 		const timestamp = new Date(published); | 		const timestamp = new Date(published).getTime(); | ||||||
| 		let edited = new Date(updated); | 		let edited = new Date(updated); | ||||||
| 		edited = Number.isNaN(edited.valueOf()) ? 0 : edited; | 		edited = Number.isNaN(edited.valueOf()) ? undefined : edited; | ||||||
|  |  | ||||||
| 		// If no source content, then `content` is pre-parsed and should be HTML, so cache it |  | ||||||
| 		if (!sourceContent) { |  | ||||||
| 			winston.verbose(`[activitypub/mockPost] pid ${pid} already has pre-parsed HTML content, adding to post cache...`); |  | ||||||
| 			postCache.set(pid, content); |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		const payload = { | 		const payload = { | ||||||
| 			uid, | 			uid, | ||||||
| 			pid, | 			pid, | ||||||
| 			timestamp: timestamp.getTime(), | 			// tid, | ||||||
| 			timestampISO: timestamp.toISOString(), | 			content, | ||||||
| 			content: sourceContent || content, | 			sourceContent, | ||||||
|  | 			timestamp, | ||||||
| 			toPid, | 			toPid, | ||||||
|  |  | ||||||
| 			edited, | 			edited, | ||||||
| 			editor: edited ? uid : undefined, | 			editor: edited ? uid : undefined, | ||||||
| 			editedISO: edited ? edited.toISOString() : '', |  | ||||||
|  |  | ||||||
| 			deleted: 0, |  | ||||||
| 			deleterUid: 0, |  | ||||||
| 			replies: 0, // todo |  | ||||||
| 			bookmarks: 0, |  | ||||||
| 			votes: 0, // todo |  | ||||||
| 		}; | 		}; | ||||||
|  |  | ||||||
| 		return payload; | 		return payload; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user