Comments (3)
Could you please explain a bit more about what you're trying to achieve overall? Why are you trying to load all the messages into memory? And are you trying to load just those directly referenced by the query, or also the other messages in the same conversations as messages in the query?
from overture.
@neilj thanks for your reply. I'm trying to create a sort of "Unified Inbox" where it shows the messsage count for messages in the Inbox with a particular label in the sidebar. So e.g. when I have 8 messages labeled "Project" in my Inbox, it shows "Project (8)" in the sidebar.
I'm using this code to create an extra inboxEmails
property on the Mailbox:
FastMail.classes.Mailbox.prototype.inboxEmails = 0;
const mailboxes = FastMail.store.getAll(FastMail.classes.Mailbox);
const inboxKey = FastMail.findMailbox(mailboxes,'Inbox').get('storeKey');
FastMail.store.getAll(FastMail.classes.Mailbox).forEach(mailbox => {
mailbox.inboxEmails = FastMail.store.getQuery("inboxEmails", FastMail.classes.LocalQuery, { Type: FastMail.classes.Message, where: function (data) { return data.mailboxIds[inboxKey] && data.mailboxIds[mailbox.get('storeKey')] } }).get('[]').map(x => x.get('thread')).filter((item,index,arr) => { return arr.indexOf(item) == index }).length;
mailbox.computedPropertyDidChange('badgeProperty')
});
The 'issue' is that the Inbox isn't always fully loaded, most often only the first 2 windows (60 messages) are loaded. I've found this hack as a workaround (which obviously only works if the Inbox is visible):
FastMail.activeViews.v66._renderRange.start = 0;
FastMail.activeViews.v66._renderRange.end = FastMail.activeViews.v66.contentLength;
FastMail.activeViews.v66.viewNeedsRedraw();
(btw - I noticed that this hack is actually botching up a few things, including the undo functionality...)
As you can see it's all quite hackish, but I'm pleased that at least this is possible at all because OvertureJS / Fastmail is built in a way I can actually follow (somewhat) what's going on. But I haven't cracked what is needed to load extra windows in a WindowedQuery
. I thought that FastMail.router.getAppController('mail').mailboxMessageList().getObjectAt(60);
would achieve that, but it doesn't seem to do anything (although I thought to see that that's how a MailboxView is actually populated(?)
Thanks in advance for any pointers in the right direction! I'm probably going this wrong way round, but happy to learn any pointers how to do this!
from overture.
That's a non-trivial thing to do properly to be honest. I would probably start with something like this:
const { Mailbox, Message, MessageList, Obj } = FM.classes;
const { store } = FM;
const inbox = store.getOne(Mailbox, x => x.role === 'inbox');
const args = {
accountId: inbox.get('accountId'),
where: { inMailbox: inbox.get('id') },
};
const queryId = Message.getQueryId(args);
const query = store.getQuery(queryId, MessageList, args);
const inboxCounts = new Obj({
counts: new Map(),
recalculate() {
query.getStoreKeysForAllObjects((storeKeys) => {
getMessages(storeKeys, 0, (messages) => {
const counts = new Map();
messages.forEach(message => {
message.get('mailboxes').forEach(mailbox => {
const id = mailbox.get('id');
counts.set(id, (counts.get(id) || 0) + 1)
})
})
this.set('counts', counts);
});
});
},
});
query.addObserverForRange({}, inboxCounts, recalculate);
… but I don't think we expose the getMessages
function on our FM
global at the moment (which is intended for our internal debugging purposes more than building stuff on top). And the above won't be quite right if you move stuff in or out of the project folders rather than the inbox.
Anyway, interesting idea, but I'm afraid I don't have time to help you further with it. One last thought though, I think if you get the message list (FM.router.getAppController('mail').get('mailboxMessageList')
) you could then do list.set('optimiseFetching', false).set('prefetch', 1024)
(or an even larger number) and that will probably get it to fetch everything in the query when you fetch one item, although I haven't tested it to confirm!
from overture.
Related Issues (20)
- Documentation rendering HOT 2
- Example Todo: Can not run in Iceweasel HOT 8
- How to/Who will add more views? HOT 1
- RPCSource#handle a public method, function map clarification HOT 2
- Todo Fails to Work HOT 1
- Todo example doesn't run locally
- overture + angular/ionic HOT 5
- Nested SwitchViews can place their contents out of order
- CSS code for views HOT 1
- performance claims
- Setting properties does not immediately call observers HOT 6
- To do demo app not responding to touch drag and drop HOT 1
- Bind JS Object to a view HOT 1
- Website should be served over HTTPS HOT 1
- Unit tests HOT 1
- Browser Support HOT 2
- Split Loader to a new Repo HOT 1
- Array methods motivation question HOT 1
- Question about bindings HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from overture.