history.ts: Fix 🚑 getHistory

Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
David Mehren 2020-04-18 17:54:12 +02:00
parent 2408aef54c
commit e0192b5652
No known key found for this signature in database
GPG key ID: 6017AF117F9756CB

View file

@ -14,6 +14,7 @@ type HistoryObject = {
text: string; text: string;
time: number; time: number;
tags: string[]; tags: string[];
pinned?: boolean;
} }
function parseHistoryMapToArray (historyMap: Map<string, HistoryObject>): HistoryObject[] { function parseHistoryMapToArray (historyMap: Map<string, HistoryObject>): HistoryObject[] {
@ -42,9 +43,8 @@ function getHistory (userId, callback: (err: any, history: any) => void): void {
if (!user) { if (!user) {
return callback(null, null) return callback(null, null)
} }
let history
if (user.history) { if (user.history) {
history = JSON.parse(user.history) const history = JSON.parse(user.history)
// migrate LZString encoded note id to base64url encoded note id // migrate LZString encoded note id to base64url encoded note id
for (let i = 0, l = history.length; i < l; i++) { for (let i = 0, l = history.length; i < l; i++) {
// Calculate minimal string length for an UUID that is encoded // Calculate minimal string length for an UUID that is encoded
@ -70,10 +70,11 @@ function getHistory (userId, callback: (err: any, history: any) => void): void {
} }
} }
} }
history = parseHistoryArrayToMap(history)
}
logger.debug(`read history success: ${user.id}`) logger.debug(`read history success: ${user.id}`)
return callback(null, history) return callback(null, parseHistoryArrayToMap(history))
}
logger.debug(`read empty history: ${user.id}`)
return callback(null, [])
}).catch(function (err) { }).catch(function (err) {
logger.error('read history failed: ' + err) logger.error('read history failed: ' + err)
return callback(err, null) return callback(err, null)