1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-18 23:07:45 +02:00
Files
Assets
CliClient
Clipper
ElectronClient
ReactNativeClient
android
ios
lib
components
images
models
Alarm.js
BaseItem.js
Folder.js
ItemChange.js
MasterKey.js
Note.js
NoteResource.js
NoteTag.js
Resource.js
ResourceLocalState.js
Search.js
Setting.js
Tag.js
services
vendor
ArrayUtils.js
BaseApplication.js
BaseModel.js
BaseSyncTarget.js
Cache.js
ClipperServer.js
DropboxApi.js
EventDispatcher.js
HtmlToMd.js
JoplinError.js
MdToHtml.js
MdToHtml_Katex.js
ModelCache.js
ObjectUtils.js
SyncTargetDropbox.js
SyncTargetFilesystem.js
SyncTargetMemory.js
SyncTargetNextcloud.js
SyncTargetOneDrive.js
SyncTargetOneDriveDev.js
SyncTargetRegistry.js
SyncTargetWebDAV.js
WebDavApi.js
WelcomeUtils.js
database-driver-node.js
database-driver-react-native.js
database.js
dialogs.js
file-api-driver-dropbox.js
file-api-driver-local.js
file-api-driver-memory.js
file-api-driver-onedrive.js
file-api-driver-webdav.js
file-api.js
folders-screen-utils.js
fs-driver-base.js
fs-driver-dummy.js
fs-driver-node.js
fs-driver-rn.js
geolocation-node.js
geolocation-react.js
import-enex-md-gen.js
import-enex.js
joplin-database.js
layout-utils.js
locale.js
logger.js
markJsUtils.js
markdownUtils.js
mime-utils.js
net-utils.js
onedrive-api.js
package.json
parameters.js
parseUri.js
path-utils.js
poor-man-intervals.js
promise-utils.js
randomClipperPort.js
react-logger.js
reducer.js
registry.js
shim-init-node.js
shim-init-react.js
shim.js
string-utils-common.js
string-utils.js
synchronizer.js
time-utils.js
urlUtils.js
uuid.js
welcomeAssets.js
locales
.babelrc
.buckconfig
.flowconfig
.gitattributes
.gitignore
.watchmanconfig
App.js
app.json
build_android.bat
build_android_prod.bat
clean_build.bat
debug_log.bat
debug_log.sh
index.android.js
index.ios.js
index.js
main.js
package-lock.json
package.json
root.js
start_emulator.bat
start_server.bat
start_server.sh
Tools
docs
readme
.gitignore
.travis.yml
BUILD.md
CONTRIBUTING.md
Joplin_install_and_update.sh
LICENSE
README.md
_config.yml
appveyor.yml
joplin.sublime-project
linkToLocal.sh
joplin/ReactNativeClient/lib/models/Alarm.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-12-14 18:12:14 +00:00
const BaseModel = require('lib/BaseModel.js');
const Note = require('lib/models/Note.js');
class Alarm extends BaseModel {
static tableName() {
return 'alarms';
}
static modelType() {
return BaseModel.TYPE_ALARM;
}
static byNoteId(noteId) {
return this.modelSelectOne('SELECT * FROM alarms WHERE note_id = ?', [noteId]);
}
static async deleteExpiredAlarms() {
return this.db().exec('DELETE FROM alarms WHERE trigger_time <= ?', [Date.now()]);
}
static async alarmIdsWithoutNotes() {
// https://stackoverflow.com/a/4967229/561309
const alarms = await this.db().selectAll('SELECT alarms.id FROM alarms LEFT JOIN notes ON alarms.note_id = notes.id WHERE notes.id IS NULL');
return alarms.map((a) => { return a.id });
}
2017-11-28 20:17:34 +00:00
static async makeNotification(alarm, note = null) {
if (!note) {
note = await Note.load(alarm.note_id);
} else if (!note.todo_due) {
this.logger().warn('Trying to create notification for note with todo_due property - reloading note object in case we are dealing with a partial note');
note = await Note.load(alarm.note_id);
this.logger().warn('Reloaded note:', note);
}
2017-11-28 20:17:34 +00:00
const output = {
id: alarm.id,
date: new Date(note.todo_due),
title: note.title.substr(0,128),
};
if (note.body) output.body = note.body.substr(0,512);
return output;
}
static async allDue() {
return this.modelSelectAll('SELECT * FROM alarms WHERE trigger_time >= ?', [Date.now()]);
}
}
module.exports = Alarm;