Back

Bug? Creating document with custom permissions won't trigger realtime event

  • 0
  • Web
  • Databases
  • Realtime
  • Self Hosted
  • Functions
ikoba218
11 May, 2024, 21:37

Basically, I have the following structure database:

TypeScript
Profile -[many]-> UserConversation -[one]-> Conversation -[many]-> Messages

Profile <-[one]- UserConversation <-[many]- Conversation <-[one]- Messages

It happens that, when an Auth user (with his profile) has a UserConversation, it points to a conversation, where another person should also be, connected through his own UserConversion.

sendMessage (server function): creates a new message, needed just to include document permissions:

TypeScript
// server-function-self-hosted 1.5.5 
// – "node-appwrite": "^9.0.0"
// - "appwrite": "^13.0.0"

    const newMessage = await database.createDocument(
      DATABASE_ID,
      MESSAGES_COLLECTION_ID,
      ID.unique(),
      {//...data},
      [
        Permission.read(Role.user([currentAccountId])),
        Permission.update(Role.user(currentAccountId)),
        Permission.read(Role.user([participantId])),
      ]
    );

Finally, it happens that the person sending the message, it means, creating the document, (currentAccountId) is notified about the creation. But the other person (participantId) is not.

I've made some tests: I thought when the event trigger is created, the permission could not have been updated yet or anything like that – while the creator was already there by default and my setup is merely rewriting. Seems not to be true, since I included an updateDocument for testing, and it still does not notify the other person, just the creator.

Hope someone can put me in the right direction. I tried to describe everything as needed – if some info is missing, please, just let me know and I will kindly respond to figure it out.

TL;DR
Issue with creating documents with custom permissions not triggering realtime event for the participant user. The developer has a database structure with Profiles, UserConversations, Conversations, and Messages. The sendMessage server function is used to create a new message with document permissions but only notifies the creator, not the other participant. The developer has tested with updateDocument but still faces the issue. Solution: Check the permissions set for triggering real-time events and ensure they include the participant user along with the creator.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more