Skip to content

[FIX] MessagesView duplicating content#2307

Merged
diegolmello merged 4 commits intoRocketChat:developfrom
refactor-droidyy:pagination
Jul 17, 2020
Merged

[FIX] MessagesView duplicating content#2307
diegolmello merged 4 commits intoRocketChat:developfrom
refactor-droidyy:pagination

Conversation

@refactor-droidyy
Copy link
Copy Markdown
Contributor

@RocketChat/ReactNative

Closes #2287

Current while setting the state in MessageView we are using messages : [ ...messages , ...result.messages] which is causing duplicacy in file attachments so changed to [..result.message] which is the fetch response array and it works fine.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jul 17, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@djorkaeffalexandre djorkaeffalexandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @refactor-droidyy! Thanks for your first contribution! It's awesome to see new people contributing to our project. 🤗
This changes doesn't fix the error properly, the error is related to this function.
The messages is accessed when we call this function (at the constructor time), so, all access to messages.length inner this function are always returning 0, since it was instantiated once before.
The right solution is access messages state at each fetchFunc, like this:

fetchFunc: async() => {
  const { messages } = this.state;
  const result = await RocketChat.getFiles(this.rid, this.t, messages.length);
   return { ...result, messages: result.files };
}

@djorkaeffalexandre djorkaeffalexandre changed the title Fix Pagination duplicacy [FIX] MessagesView duplicating content Jul 17, 2020
@refactor-droidyy
Copy link
Copy Markdown
Contributor Author

@djorkaeffalexandre Thankyou very much for helping me in my first contribution :) I have changed as per your direction please have a look .

Copy link
Copy Markdown
Contributor

@djorkaeffalexandre djorkaeffalexandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM