Data-model for chat with threads and per-user restrictions

Hello,

I wonder how to model a scenario for a Chat-App, with different Threads and a list of allowed contributors. I would create a collection posts storing all posts for every thread.

Since I would like to list all Threads as well I wanted to create collection threads storing all thread-related metadata. Every post would reference the thread it belongs to.

I want to have a list of users allowed to post to given thread. Now what ?

If I add a field contributors to documents in threads I would need to do a query, if the current logged-in user is in the contributors list of the thread the new post belongs to on every insert. Is this a good Idea ?

Sounds like you could use my socialize: messaging package… Naming is a bit different (post=message, conversation=thread, participant=contributor) but I think it’s exactly what you need.

Hello @copleykj

thanks for your suggestion. I actually do not develop messaging app, but it is a very common use case here on Meteor, so I was hoping it will be simple to use the messaging analogy.

I actually looked at your code and found:

    insert(userId, message) {
        if (userId && ParticipantsCollection.findOne({ userId, conversationId: message.conversationId })) {
            return true;
        }
        return false;

So in my understanding you do exactly what I was planing to do: creating collection for whatever groups the messages and make an Request against it, whether or not the current user is among the recipients. DO I have to use Collection.finOne() od will find() work as well ?

I was afraid it could affect the performance when I check the current user against contrubutors on every insert. Apparently not.

Yes, you are correct. You could query the list of contributors to make sure that the current user is one of them. There really shouldn’t be any difference between a find and findOne as long as you have proper indexing. Internally a findOne is just a find with it’s limit set to 1.

1 Like