EmbeddedChat icon indicating copy to clipboard operation
EmbeddedChat copied to clipboard

Fix Loading of Older Thread Messages in Thread Message Modal

Open smritidoneria opened this issue 1 year ago • 12 comments

Brief Title

This pull request addresses the issue where older thread messages are not being loaded in the thread message modal.

Acceptance Criteria fulfillment

  • Updated the getAllThreadMessages function in EmbeddedChatApi.ts to correctly fetch older thread messages. -Updated the ChatBody component to correctly use the getAllThreadMessages function from the useFetchChatData hook and update the state.

Fixes #895

Video/Screenshots

https://github.com/user-attachments/assets/f2912771-dd29-4320-b59f-e5f13a347169

PR Test Details

Note: The PR will be ready for live testing at https://rocketchat.github.io/EmbeddedChat/pulls/pr-<pr_number> after approval. Contributors are requested to replace <pr_number> with the actual PR number.

smritidoneria avatar Jan 14 '25 12:01 smritidoneria

Hey @smritidoneria, I think fetching threads only through the API once on opening the sidebar might not retrieve older messages due to the limit on the number of items it returns. Perhaps we could consider implementing a "load more threads" (by setting required offset) feature on scroll down to handle this

abirc8010 avatar Jan 16 '25 18:01 abirc8010

hey @abirc8010 , Thanks for pointing out, I will look after this.

smritidoneria avatar Jan 18 '25 14:01 smritidoneria

Hi @smritidoneria, since this issue affects not only threads but also other items in the sidebar, it might be better to address the loading of more items in the sidebar in a single PR. You can refer to a similar issue #915 for reference.

abirc8010 avatar Jan 18 '25 15:01 abirc8010

I was reviewing the pr and find out some issue the query parameters are not passing in the url correctly except for the roomID refrence- Screenshot 2025-01-20 at 1 21 58 AM

Calling the function like this Screenshot 2025-01-20 at 1 22 34 AM

but the url shows Screenshot 2025-01-20 at 1 22 57 AM

and, where can I see the logs for the file EmbeddedChatApi.ts. it is neither showing in browser tools nor in terminal?

Any suggestions @abirc8010 , @Spiral-Memory , @SinghaAnirban005

smritidoneria avatar Jan 19 '25 19:01 smritidoneria

and, where can I see the logs for the file EmbeddedChatApi.ts. it is neither showing in browser tools nor in terminal?

Hey @smritidoneria you can find the logs in the browser console, did you run yarn build in the api directory after your changes?

image

Also I found this in ChatLayout.js , try to import the getAllThreadMessages function from useFetchchatData() and call it inside the useEffect

image

Btw is there any reason you’re passing rid? You can append it to the request URL as this.rid.

abirc8010 avatar Jan 19 '25 21:01 abirc8010

@smritidoneria you probably missed out on building the api package , Also take care of the pagination params like offset and count

@abirc8010 i believe doing that useEffect thing in ChatLayout.js is causing the threads endpoint to be called many times such as closing of sidebar and opening of sidebar for pinned or starred messages. Thus we must avoid calling it there

SinghaAnirban005 avatar Jan 20 '25 06:01 SinghaAnirban005

@smritidoneria you probably missed out on building the api package , Also take care of the pagination params like offset and count

@abirc8010 i believe doing that useEffect thing in ChatLayout.js is causing the threads endpoint to be called many times such as closing of sidebar and opening of sidebar for pinned or starred messages. Thus we must avoid calling it there

yaa, actually I forgot to build the package, thanks!

smritidoneria avatar Jan 20 '25 14:01 smritidoneria

hey @abirc8010 , @SinghaAnirban005 , I'm encountering an issue with the scroll event not being detected in the message aggregator component,. I have tried using many ways , I have tried giving ref to the threaded message main container that didn't work, and then the message aggregator component main box, which is also not working kindly ignore the rest of the code, it needs to be optimized

suggestions?

smritidoneria avatar Jan 20 '25 14:01 smritidoneria

Hey @smritidoneria instead of maintaining a ref could we go with this approach ?

Additionally, I think the logic in the MessageAggregator component needs to be refactored to make it more extensible, currently it fetches all the messages from the messageStore then filters messages based on shoudRender , maybe we can pass only the required filtered messages as a prop to MessageAggregator

The functionality needs to be extendable so that a similar logic can be applied to rest of the MessageAggregators like starred or pinned

abirc8010 avatar Jan 20 '25 20:01 abirc8010

Yes, @abirc8010, we can proceed with the approach you mentioned. However, in the main ChatInterface, we are currently addressing this issue using ref. To maintain the application's consistency and serializability, we should first attempt to resolve this using ref. If we are unable to do so after further effort, we can then switch to your proposed approach.

smritidoneria avatar Jan 22 '25 07:01 smritidoneria

Hey all,

Really busy these days.. and not getting the time to review.. will review as soon as i get some time

Thanks

Spiral-Memory avatar Jan 22 '25 07:01 Spiral-Memory

Hey everyone,

With the merge of the PR that enables loading older messages when reaching the top view, this issue is automatically resolved. Once the previous messages are loaded into the DOM view, the thread messages are fetched and displayed accordingly.

I don't believe any further changes are needed. What do you think, @Spiral-Memory, @abirc8010, @SinghaAnirban005?

Reference-

https://github.com/user-attachments/assets/d2b88238-cb23-4be4-831a-868856849744

smritidoneria avatar Feb 03 '25 12:02 smritidoneria