-
Notifications
You must be signed in to change notification settings - Fork 15
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
Changes from 1 commit
73119ac
dfaabda
c66fd9f
705da8d
14f8e13
d41efe4
29a0290
3fb668d
48ebe06
e049b9f
200a51a
597da45
3ee79c1
5ff7462
8edfd8a
f6fa6fc
cc507f6
6d5e677
db963f6
e477bbb
904f9e5
0800998
a618c1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -22,6 +23,8 @@ class NotesController { | |
* Setup event handlers | ||
*/ | ||
constructor() { | ||
this.visits = new Visits(); | ||
|
||
ipcMain.on('note - save', (event, {note}) => { | ||
this.saveNote(note, event); | ||
}); | ||
|
@@ -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}) => { | ||
|
@@ -96,6 +102,18 @@ class NotesController { | |
let list = new NotesList(folderId); | ||
let notesInFolder = await list.get(); | ||
|
||
await this.visits.syncVisits(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. комментарий |
||
|
||
/** | ||
* set up note visits | ||
*/ | ||
notesInFolder.forEach( async (note) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. подгружать индикаторы isSeen отдельным запросом после открытия папки, передав ids статей |
||
if ( this.visits.visitedNotes[note._id] >= note.dtModify ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this.visits.getDate(note._id) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не обрабатывается отсутствие статьи в visits There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. перенести в модель NotesList в свойство isSeen |
||
note.visited = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
комментарий