Keeping multiple messages in the same repeating group cell

hi @fayewatson
I have created a group chat in my app, but the problem is it takes a long time to display data. Do you have some tricks to solve that one?

Thanks anyway

Hi @tifanirose1611 :slight_smile: Sure thing! To minimize the page load time, I set the repeating group to only display the most recent 30 Messages in a Conversation when a Conversation is first loaded.

Each Conversation has a Messages field (type: Message, list: yes). When a Conversation is loaded, I set a custom state (of type number) to be that Conversation’s Messages field:count minus 30. In order to display the most recent 30 Messages in a Conversation, I use the expression “Parent Group’s Conversation’s Messages:items from [custom state number value]” as the data source of the repeating group. This ensures the right ‘number’ of Messages are loaded at a time.

For example, if the Conversation that is being loaded has a total of 90 Messages, then this custom state number would equal 60 when the Conversation is first loaded, because 90 (the total number of Messages) minus 30 (the amount of Messages we want to load initially) is 60. The data source of the repeating group automatically updates to “Parent Group Conversation’s Messages:items from: 60” since the :from item number value is stored in the custom state. This ensures the newest 30 Messages in a Conversation are displayed when the page is initially loaded.

Since we also need to give the User the ability to read the older Messages in the Conversation, there is another group within the repeating group which subtracts another 30 from that custom state number to show the next 30 Messages – as long as there are more Messages to be displayed. In our Conversation with 90 total Messages, if the Current User clicked this in order to view older Messages (past the most recent 30 being displayed), the custom state value would have another 30 subtracted from it (changing the value to 30, since 60 - 30 is 30). The Repeating Group of Messages data source would automatically become: “Parent Group Conversation’s Messages:items from (custom state value of 30)”

This custom state subtraction continues each time the Current User clicks the ‘show more’ element in the repeating group in order to view more Messages.

That should work, but let me know if you have any questions! :slight_smile:

@Nocodify what plugin are you using for messaging?

Hi @calvin1, I don’t use a plugin for messaging.

You can build a messaging feature through repeating groups and a database structure.

If you want to play around with it, I suggest looking at airdevs messaging widget, as shown above by Dan.

This works…thank you stavvit… :+1: