Skip to content

Commit

Permalink
provide note dates in the frontend API, fixes #4232
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed Sep 6, 2023
1 parent 97d8b19 commit d2263c6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
14 changes: 2 additions & 12 deletions src/becca/entities/bnote.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,6 @@ class BNote extends AbstractBeccaEntity {
return this._getContent();
}

/** @returns {{dateModified, utcDateModified}} */
getContentMetadata() {
return sql.getRow(`SELECT dateModified, utcDateModified FROM blobs WHERE blobId = ?`, [this.blobId]);
}

/** @returns {*} */
getJsonContent() {
const content = this.getContent();
Expand Down Expand Up @@ -1571,7 +1566,6 @@ class BNote extends AbstractBeccaEntity {
saveRevision() {
return sql.transactional(() => {
let noteContent = this.getContent();
const contentMetadata = this.getContentMetadata();

const revision = new BRevision({
noteId: this.noteId,
Expand All @@ -1580,14 +1574,10 @@ class BNote extends AbstractBeccaEntity {
type: this.type,
mime: this.mime,
isProtected: this.isProtected,
utcDateLastEdited: this.utcDateModified > contentMetadata.utcDateModified
? this.utcDateModified
: contentMetadata.utcDateModified,
utcDateLastEdited: this.utcDateModified,
utcDateCreated: dateUtils.utcNowDateTime(),
utcDateModified: dateUtils.utcNowDateTime(),
dateLastEdited: this.dateModified > contentMetadata.dateModified
? this.dateModified
: contentMetadata.dateModified,
dateLastEdited: this.dateModified,
dateCreated: dateUtils.localNowDateTime()
}, true);

Expand Down
4 changes: 4 additions & 0 deletions src/public/app/entities/fnote.js
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,10 @@ class FNote {
isOptions() {
return this.noteId.startsWith("_options");
}

async getMetadata() {
return await server.get(`notes/${this.noteId}/metadata`);
}
}

export default FNote;
4 changes: 2 additions & 2 deletions src/public/app/widgets/ribbon_widgets/note_info_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ export default class NoteInfoWidget extends NoteContextAwareWidget {
.attr("title", metadata.dateCreated);

this.$dateModified
.text(metadata.combinedDateModified.substr(0, 16))
.attr("title", metadata.combinedDateModified);
.text(metadata.dateModified.substr(0, 16))
.attr("title", metadata.dateModified);

this.$type.text(note.type);

Expand Down
5 changes: 3 additions & 2 deletions src/routes/api/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ function getNoteBlob(req) {

function getNoteMetadata(req) {
const note = becca.getNoteOrThrow(req.params.noteId);
const contentMetadata = note.getContentMetadata();

return {
dateCreated: note.dateCreated,
combinedDateModified: note.utcDateModified > contentMetadata.utcDateModified ? note.dateModified : contentMetadata.dateModified
utcDateCreated: note.utcDateCreated,
dateModified: note.dateModified,
utcDateModified: note.utcDateModified,
};
}

Expand Down

0 comments on commit d2263c6

Please sign in to comment.