skip to Main Content

Most of the blogs and stacks suggests below database for chat.

message_table
-id
-message
-conversationId
-sender
-receiverId

conversation_table
-id
-conversationId

Now message_table look like this.

enter image description here

So, for the chat screen I subscribe the message table.

final mySubscription = supabase
  .from('message_table')
  .on(SupabaseEventTypes.all, (payload) {
    // Handle realtime payload
  })
  .subscribe();

if user1 and user2 are chatting, they will get all messages from this table.

So, how to filter this data with specified conversationId in supabase to stop receive the other message of other users and for reduce of bandwidth ?

And Is this database viable ?

2

Answers


  1. Finds all rows whose column satisfies the filter.

    var conversationId = yourvalue ;
    final mySubscription = supabase
      .from('message_table')
      .select('message, conversationId, sender , receiverId')
      .eq('conversationId', conversationId) // Correct
      .on(SupabaseEventTypes.all, (payload) {
        // Handle realtime payload
      })
      .subscribe();
    
    
    Login or Signup to reply.
  2. You can add eq filter on your realtime listeners like this:

    supabase-flutter v1.X

    final subscription = supabase.channel('unique_channel').on(
        RealtimeListenTypes.postgresChanges,
        ChannelFilter(
          event: '*',
          schema: 'public',
          table: 'message_table',
          filter: 'conversationId=eq.conv12',
        ), (payload, [ref]) {
          // handle realtime here
    }).subscribe();
    

    supabase-flutter v0.X

    final subscription = supabase
      .from('message_table:conversationId=eq.conv12')
      .on(SupabaseEventTypes.all, (payload) {
        // Handle realtime payload
      })
      .subscribe();
    

    You can read more about this feature on the official Supabase documentation here!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search