Git Product home page Git Product logo

Comments (3)

neilj avatar neilj commented on July 18, 2024

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.

mdbraber avatar mdbraber commented on July 18, 2024

@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.

neilj avatar neilj commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.