From cb9aed03f7780814ab14905092fca098c69f942e Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Tue, 14 Jun 2016 18:37:05 +0300 Subject: [PATCH] drafts draft --- app/js/services.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/app/js/services.js b/app/js/services.js index d16efcf0..6015f6f2 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -4454,3 +4454,54 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) shareUrl: shareUrl }; }) + + +.service('DraftsManager', function (qSync, Storage) { + + var localDrafts = {}; + + return { + getDraft: getDraft, + saveDraft: saveDraft, + changeDraft: changeDraft, + syncDraft: syncDraft + }; + + function getDraft (peerID, options) { + return Storage.get('draft' + peerID).then(function (draft) { + if (typeof draft === 'string' && draft.length > 0) { + draft = { + text: draft + }; + } + if (draft === false || draft == null) { + draft = ''; + } + + }); + } + + function saveDraft(peerID, draftData) { + localDrafts[peerID] = draftData; + } + + function changeDraft(peerID, message, options) { + options = options || {}; + if (typeof message === 'string' || options.replyToMsgID) { + var localDraft = { + text: message, + replyToMsgID: replyToMsgID + }; + var backupDraftObj = {}; + backupDraftObj['draft' + peerID] = localDraft; + Storage.set(backupDraftObj); + } else { + Storage.remove('draft' + peerID); + } + } + + function syncDraft(peerID) { + + } + +}) \ No newline at end of file