From 0bec5719fdf5895907eb6313b3bacb66fd6443a7 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Sat, 24 Jun 2017 02:28:13 -0700 Subject: [PATCH] Fetch messages on demand --- .gitignore | 2 -- .../custom-fonts/stylesheets/fonts.less | 12 ++++---- .../message-list/lib/message-item-body.cjsx | 2 -- .../flux/stores/database-change-record.es6 | 18 ------------ .../src/flux/stores/message-store.coffee | 28 ++++++++----------- .../src/flux/tasks/event-rsvp-task.es6 | 3 -- 6 files changed, 18 insertions(+), 47 deletions(-) diff --git a/.gitignore b/.gitignore index fd2950631..3fb47cab8 100644 --- a/.gitignore +++ b/.gitignore @@ -10,8 +10,6 @@ ##### Client Private Plugins (symlinked) **/client-app/src/error-logger-extensions -**/client-app/src/nylas-private-* -**/internal_packages/nylas-private-* **/internal_packages/activity-list **/internal_packages/composer-mail-merge **/internal_packages/composer-scheduler diff --git a/packages/client-app/internal_packages/custom-fonts/stylesheets/fonts.less b/packages/client-app/internal_packages/custom-fonts/stylesheets/fonts.less index 037a0e564..652bba577 100644 --- a/packages/client-app/internal_packages/custom-fonts/stylesheets/fonts.less +++ b/packages/client-app/internal_packages/custom-fonts/stylesheets/fonts.less @@ -3,35 +3,35 @@ font-family: 'Nylas-Pro'; font-style: normal; font-weight: 200; - src: url('nylas://custom-fonts/fonts/Nylas-Pro-Thin.otf'); + src: url('nylas://custom-fonts/fonts/Custom-Thin.otf'); } @font-face { font-family: 'Nylas-Pro'; font-style: normal; font-weight: 300; - src: url('nylas://custom-fonts/fonts/Nylas-Pro-Blond.otf'); + src: url('nylas://custom-fonts/fonts/Custom-Blond.otf'); } @font-face { font-family: 'Nylas-Pro'; font-style: normal; font-weight: 400; - src: url('nylas://custom-fonts/fonts/Nylas-Pro-Normal.otf'); + src: url('nylas://custom-fonts/fonts/Custom-Normal.otf'); } @font-face { font-family: 'Nylas-Pro'; font-style: normal; font-weight: 500; - src: url('nylas://custom-fonts/fonts/Nylas-Pro-Medium.otf'); + src: url('nylas://custom-fonts/fonts/Custom-Medium.otf'); } @font-face { font-family: 'Nylas-Pro'; font-style: normal; font-weight: 600; - src: url('nylas://custom-fonts/fonts/Nylas-Pro-SemiBold.otf'); + src: url('nylas://custom-fonts/fonts/Custom-SemiBold.otf'); } // Pro-SemiBold doesn't render emoji properly. Override the emjoi unicode @@ -40,6 +40,6 @@ font-family: 'Nylas-Pro'; font-style: normal; font-weight: 600; - src: url('nylas://custom-fonts/fonts/Nylas-Pro-Normal.otf'), Helvetica, sans-serif; + src: url('nylas://custom-fonts/fonts/Custom-Normal.otf'), Helvetica, sans-serif; unicode-range: U+1F300-1F5FF, U+1F600-1F64F, U+1F680-1F6FF, U+2600-26FF; } diff --git a/packages/client-app/internal_packages/message-list/lib/message-item-body.cjsx b/packages/client-app/internal_packages/message-list/lib/message-item-body.cjsx index 33f64f572..0a35f1d4a 100644 --- a/packages/client-app/internal_packages/message-list/lib/message-item-body.cjsx +++ b/packages/client-app/internal_packages/message-list/lib/message-item-body.cjsx @@ -5,8 +5,6 @@ EmailFrame = require('./email-frame').default { DraftHelpers, CanvasUtils, - NylasAPI, - NylasAPIRequest, MessageUtils, MessageBodyProcessor, QuotedHTMLTransformer, diff --git a/packages/client-app/src/flux/stores/database-change-record.es6 b/packages/client-app/src/flux/stores/database-change-record.es6 index e134e1fb3..853d75530 100644 --- a/packages/client-app/src/flux/stores/database-change-record.es6 +++ b/packages/client-app/src/flux/stores/database-change-record.es6 @@ -14,24 +14,6 @@ export default class DatabaseChangeRecord { this._objectsString = options.objectsString; this._objects = this._objects || JSON.parse(this._objectsString, Utils.registeredObjectReviver); - /** - * We notify the entire app in ALL windows when anything in the - * database changes. This is normally okay except for Messages because - * their bodies might contain millions of charcters that will have to - * be serialized, sent over IPC, and deserialized in each and every - * window! We make an exception for message bodies here to - * dramatically reduce the processing overhead of sending object - * changes across the deltas. - */ - if (options.objectClass === "Message") { - this._objects = this._objects.map((o) => { - if (!o.draft) { - o.body = null; - } - return o; - }) - } - Object.defineProperty(this, 'type', { get: () => options.type, }) diff --git a/packages/client-app/src/flux/stores/message-store.coffee b/packages/client-app/src/flux/stores/message-store.coffee index 07ae80577..baea29121 100644 --- a/packages/client-app/src/flux/stores/message-store.coffee +++ b/packages/client-app/src/flux/stores/message-store.coffee @@ -141,7 +141,7 @@ class MessageStore extends NylasStore @_fetchFromCache() if change.objectClass is Thread.name - updatedThread = _.find change.objects, (obj) => obj.id is @_thread.id + updatedThread = change.objects.find((t) => t.id is @_thread.id) if updatedThread @_thread = updatedThread @_fetchFromCache() @@ -251,19 +251,14 @@ class MessageStore extends NylasStore # loading items for. Necessary because this takes a while. return unless loadedThreadId is @_thread?.id - loaded = true - @_items = items.filter((m) => !m.isHidden()) @_items = @_sortItemsForDisplay(@_items) - # If no items were returned, attempt to load messages via the API. If items - # are returned, this will trigger a refresh here. - if @_items.length is 0 - @_fetchMessages() - loaded = false - @_expandItemsToDefault() + if @_itemsLoading + @_fetchMissingBodies(@_items) + # Download the attachments on expanded messages. @_fetchExpandedAttachments(@_items) @@ -272,10 +267,14 @@ class MessageStore extends NylasStore # know we're not ready, don't even bother. Trigger once at start # and once when ready. Many third-party stores will observe # MessageStore and they'll be stupid and re-render constantly. - if loaded - @_itemsLoading = false - @_markAsRead() - @trigger(@) + @_itemsLoading = false + @_markAsRead() + @trigger(@) + + _fetchMissingBodies: (items) -> + missingIds = items.filter((i) -> i.body == null).map((i) -> i.id) + if missingIds.length > 0 + NylasEnv.actionBridgeCpp.onTellClients({type: 'need-bodies', ids: missingIds}) _fetchExpandedAttachments: (items) -> policy = NylasEnv.config.get('core.attachments.downloadPolicy') @@ -293,9 +292,6 @@ class MessageStore extends NylasStore if item.unread or item.draft or idx is visibleItems.length - 1 @_itemsExpanded[item.id] = "default" - _fetchMessages: -> - NylasAPIHelpers.getCollection(@_thread.accountId, 'messages', {thread_id: @_thread.id}) - _sortItemsForDisplay: (items) -> # Re-sort items in the list so that drafts appear after the message that # they are in reply to, when possible. First, identify all the drafts diff --git a/packages/client-app/src/flux/tasks/event-rsvp-task.es6 b/packages/client-app/src/flux/tasks/event-rsvp-task.es6 index 71e9a9167..d486cd3ed 100644 --- a/packages/client-app/src/flux/tasks/event-rsvp-task.es6 +++ b/packages/client-app/src/flux/tasks/event-rsvp-task.es6 @@ -1,10 +1,7 @@ import Task from './task'; import Event from '../models/event'; -import {APIError} from '../errors'; import Utils from '../models/utils'; import DatabaseStore from '../stores/database-store'; -import NylasAPI from '../nylas-api'; -import NylasAPIRequest from '../nylas-api-request'; export default class EventRSVPTask extends Task {