Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit for show badge issue #149

Merged
merged 23 commits into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/controllers/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ let {ipcMain} = require('electron');

const Note = require('../models/note');
const NotesList = require('../models/notesList');
const Visits = require('../models/visits');

/**
* Time helper
Expand All @@ -22,6 +23,8 @@ class NotesController {
* Setup event handlers
*/
constructor() {
this.visits = new Visits();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

комментарий


ipcMain.on('note - save', (event, {note}) => {
this.saveNote(note, event);
});
Expand All @@ -32,6 +35,9 @@ class NotesController {

ipcMain.on('note - get', (event, {id}) => {
this.getNote(id, event);

// set note as visited
this.visits.touch(id);
});

ipcMain.on('note - delete', (event, {id}) => {
Expand Down Expand Up @@ -96,6 +102,18 @@ class NotesController {
let list = new NotesList(folderId);
let notesInFolder = await list.get();

await this.visits.syncVisits();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

комментарий


/**
* set up note visits
*/
notesInFolder.forEach( async (note) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

подгружать индикаторы isSeen отдельным запросом после открытия папки, передав ids статей

if ( this.visits.visitedNotes[note._id] >= note.dtModify ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.visits.getDate(note._id)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не обрабатывается отсутствие статьи в visits

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

перенести в модель NotesList в свойство isSeen

note.visited = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note.is_read = true

}
});

console.log(notesInFolder);
let returnValue = {
notes: notesInFolder,
isRootFolder: !folderId
Expand Down
1 change: 1 addition & 0 deletions src/models/note.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Note {
this.folderId = null;
this.isRemoved = false;
this.editorVersion = null;
this.visited = false;

this.data = noteData;
}
Expand Down
50 changes: 50 additions & 0 deletions src/models/visits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Created by khaydarovm on 27.02.2018.
*/
'use strict';
const db = require('../utils/database'),
Time = require('../utils/time');

class Visits {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SeenStateObserver


constructor() {
this.visitedNotes = {};
}

/**
* sync visits
* @return {Promise.<*>}
*/
async syncVisits() {
let allNotes = await db.find(db.VISITS, {});
allNotes.forEach( (note) => {
this.visitedNotes[note.noteId] = note.lastSeen;
});
}

async getNoteVisit(noteId) {
return await db.findOne(db.VISITS, {
noteId : noteId
});
}

async touch(noteId) {

let query = {
noteId : noteId
};

let data = {
noteId : noteId,
lastSeen : Time.now
};

await db.update(db.VISITS, query, {
$set : data
},{
upsert : true
});
}
}

module.exports = Visits;
11 changes: 8 additions & 3 deletions src/utils/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Database {
this.FOLDERS = new Datastore({ filename: path.join(this.appFolder, 'folders.db'), autoload: true});
this.NOTES = new Datastore({ filename: path.join(this.appFolder, 'notes.db'), autoload: true});
this.COLLABORATORS = new Datastore({ filename: path.join(this.appFolder, 'collaborators.db'), autoload: true });
this.VISITS = new Datastore({ filename: path.join(this.appFolder, 'visits.db'), autoload: true });
}

/**
Expand Down Expand Up @@ -96,13 +97,13 @@ class Database {
* @param {Boolean} force - force drop.
*/
drop(force = false) {
if (process.env.DEBUG !== 'true' || !force) {
if ( !force || ( process.env.DEBUG !== 'true' && !force )) {
throw Error('Datastore dropping is not allowed for current environment');
}

let sequence = [];

[this.USER, this.FOLDERS, this.NOTES, this.COLLABORATORS].forEach( collection => {
[this.USER, this.FOLDERS, this.NOTES, this.COLLABORATORS, this.VISITS].forEach( collection => {
console.log('\n\n Drop ', collection.filename, '\n\n');
sequence.push(this.remove(collection, {}, {multi: true}, (removedRows) => {
console.log(collection.filename, ': ', removedRows, ' docs removed');
Expand All @@ -113,8 +114,12 @@ class Database {
this.FOLDERS = null;
this.NOTES = null;
this.COLLABORATORS = null;
this.VISITS = null;

return Promise.all(sequence);
return Promise.all(sequence)
.catch((err) => {
throw Error('Couldn\'t drop the database', err);
});
}

/**
Expand Down