mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
refactor: contenthistory -> sessioncontent
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { makeSessionContentId, makeSessionId } from "../utils/id";
|
||||
import Collection from "./collection";
|
||||
import ContentHistory from "./contenthistory";
|
||||
import SessionContent from "./session-content";
|
||||
/**
|
||||
* @typedef Session
|
||||
* @property {string} id
|
||||
@@ -27,11 +27,11 @@ export default class NoteHistory extends Collection {
|
||||
super.init();
|
||||
|
||||
/**
|
||||
* @type {ContentHistory}
|
||||
* @type {SessionContent}
|
||||
*/
|
||||
this.contentHistory = await ContentHistory.new(
|
||||
this.sessionContent = await SessionContent.new(
|
||||
this._db,
|
||||
"contenthistory",
|
||||
"sessioncontent",
|
||||
false
|
||||
);
|
||||
}
|
||||
@@ -80,7 +80,7 @@ export default class NoteHistory extends Collection {
|
||||
}
|
||||
|
||||
await this._collection.addItem(session);
|
||||
await this.contentHistory.add(sessionId, content, session.locked);
|
||||
await this.sessionContent.add(sessionId, content, session.locked);
|
||||
await this._cleanup(noteId);
|
||||
|
||||
return session;
|
||||
@@ -106,9 +106,9 @@ export default class NoteHistory extends Collection {
|
||||
*
|
||||
* @returns {Promise<Content>}
|
||||
*/
|
||||
async content(sessionId) {
|
||||
content(sessionId) {
|
||||
if (!sessionId) return;
|
||||
return await this.contentHistory.get(sessionId);
|
||||
return this.sessionContent.get(sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +120,7 @@ export default class NoteHistory extends Collection {
|
||||
/**
|
||||
* @type {Session}
|
||||
*/
|
||||
let session = this._collection.getItem(sessionId);
|
||||
let session = await this._collection.getItem(sessionId);
|
||||
await this._remove(session);
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ export default class NoteHistory extends Collection {
|
||||
*/
|
||||
async _remove(session) {
|
||||
await this._collection.deleteItem(session.id);
|
||||
await this.contentHistory.remove(session.sessionContentId);
|
||||
await this.sessionContent.remove(session.sessionContentId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +154,7 @@ export default class NoteHistory extends Collection {
|
||||
* @type {Session}
|
||||
*/
|
||||
let session = await this._collection.getItem(sessionId);
|
||||
let content = await this.contentHistory.get(session.sessionContentId);
|
||||
let content = await this.sessionContent.get(session.sessionContentId);
|
||||
let note = this._db.notes.note(session.noteId).data;
|
||||
if (session.locked) {
|
||||
await this._db.content.add({
|
||||
@@ -180,7 +180,7 @@ export default class NoteHistory extends Collection {
|
||||
async serialize() {
|
||||
return JSON.stringify({
|
||||
sessions: await this.all(),
|
||||
sessionContents: await this.contentHistory.all(),
|
||||
sessionContents: await this.sessionContent.all(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ export default class NoteHistory extends Collection {
|
||||
);
|
||||
if (sessionContent) {
|
||||
await this._collection.addItem(session);
|
||||
await this.contentHistory._collection.addItem(sessionContent);
|
||||
await this.sessionContent._collection.addItem(sessionContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { compress, decompress } from "../utils/compression";
|
||||
import { makeSessionContentId } from "../utils/id";
|
||||
import Collection from "./collection";
|
||||
|
||||
export default class ContentHistory extends Collection {
|
||||
export default class SessionContent extends Collection {
|
||||
/**
|
||||
*
|
||||
* @param {string} sessionId
|
||||
@@ -17,7 +17,7 @@ export default class ContentHistory extends Collection {
|
||||
data: compressed || content.data,
|
||||
type: content.type,
|
||||
compressed: !!compressed,
|
||||
locked
|
||||
locked,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,11 +43,9 @@ export default class ContentHistory extends Collection {
|
||||
await this._collection.deleteItem(sessionContentId);
|
||||
}
|
||||
|
||||
|
||||
async all() {
|
||||
let indices = await this._collection.indexer.getIndices();
|
||||
let items =
|
||||
(await this._collection.getItems(indices));
|
||||
let items = await this._collection.getItems(indices);
|
||||
|
||||
return Object.values(items);
|
||||
}
|
||||
Reference in New Issue
Block a user