[deploy] 🐞Bugfix: Redundant messages issue in connect (#9432)

* Feature 🚀 : Ability to delete messages in chat channels

- Sending message ID to frontend
- Deleting Message
- Use pusher to delete message realtime

* Minor Bug 🐞: Show message action only for current user

- User can delete or edit their own messages

* Test cases added

* Bug 🐞: Update message id for receiver

Message id was not sent to receiver by pusher

* Refactoring🛠: Message controller refactoring

* Test Cases📝 : Specs for Delete message added

* Feature 🚀 : Ability to edit messages

* Test Cases📝 : Specs for Edit message added

* Merge conflict resolved

* 🐞Bugfix: Redundant messages on connect channel.

* Changes requested

Co-authored-by: Narender Singh <narender2031@gmail.com>
This commit is contained in:
Sarthak Sharma 2020-07-22 21:53:18 +05:30 committed by GitHub
parent 7eb27328bb
commit 89c15fd9d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -451,19 +451,23 @@ export default class Chat extends Component {
chatChannels,
unopenedChannelIds,
} = this.state;
const receivedChatChannelId = message.chat_channel_id;
const messageList = document.getElementById('messagelist');
let newMessages = [];
const nearBottom =
messageList.scrollTop + messageList.offsetHeight + 400 >
messageList.scrollHeight;
if (nearBottom) {
scrollToBottom();
}
let newMessages = [];
// Remove reduntant messages
if (
activeChannelId &&
message.temp_id &&
messages[activeChannelId].findIndex(
messages[receivedChatChannelId] &&
messages[receivedChatChannelId].findIndex(
(oldmessage) => oldmessage.temp_id === message.temp_id,
) > -1
) {
@ -477,10 +481,13 @@ export default class Chat extends Component {
newMessages.shift();
}
}
//Show alert if message received and you have scrolled up
const newShowAlert =
activeChannelId === receivedChatChannelId
? { showAlert: !nearBottom }
: {};
let newMessageChannelIndex = 0;
let newMessageChannel = null;
const newChannelsObj = chatChannels.map((channel, index) => {
@ -497,6 +504,7 @@ export default class Chat extends Component {
newChannelsObj.unshift(newMessageChannel);
}
// Mark messages read
if (receivedChatChannelId === activeChannelId) {
sendOpen(receivedChatChannelId, this.handleChannelOpenSuccess, null);
} else {
@ -509,6 +517,7 @@ export default class Chat extends Component {
});
}
// Updating the messages
this.setState((prevState) => ({
...newShowAlert,
chatChannels: newChannelsObj,