Skip to content

[FIX] Update Message: Does not show edited when message was not edited.#13053

Merged
sampaiodiego merged 2 commits intoRocketChat:developfrom
Kailash0311:develop
Jan 20, 2019
Merged

[FIX] Update Message: Does not show edited when message was not edited.#13053
sampaiodiego merged 2 commits intoRocketChat:developfrom
Kailash0311:develop

Conversation

@Kailash0311
Copy link
Copy Markdown
Contributor

Closes #12282

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Dec 29, 2018

CLA assistant check
All committers have signed the CLA.

@geekgonecrazy
Copy link
Copy Markdown
Contributor

Thanks for contributing! This looks good in my opinion.

@sampaiodiego thoughts?

geekgonecrazy
geekgonecrazy previously approved these changes Jan 15, 2019
message.urls = urls.map((url) => ({ url }));

message = RocketChat.callbacks.run('beforeSaveMessage', message);
if (originalMessage.msg !== message.msg) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we return before having the message processed by Apps?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you mean message processing by Apps should happen when the messages are not equal ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also, I am not sure what Apps does here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Apps can change the message content or prevent a message from being sent.

so my question was: should we skip everything if the edited message didn't change? or should Apps still process messages that were "edited" but still have the same content?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rodrigok @d-gubert @graywolf336 what you guys think on above?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd say that we could skip the whole RocketChat.updateMessage method when the message's content doesn't change, not executing Apps, before/after hooks, or message history ->

if (RocketChat.settings.get('Message_KeepHistory')) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cool then sounds like this is good?

Copy link
Copy Markdown
Contributor Author

@Kailash0311 Kailash0311 Jan 17, 2019

Choose a reason for hiding this comment

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

Yeah I'll change it to skipping the whole RocketChat.updateMessage method.

@Kailash0311
Copy link
Copy Markdown
Contributor Author

Ohh thanks!
Yeah, I think we should skip all message processing because that will process the already processed message, which is redundant, I guess.

@Kailash0311
Copy link
Copy Markdown
Contributor Author

@geekgonecrazy I have updated the code according to what we discussed.

const prevent = Promise.await(Apps.getBridges().getListenerBridge().messageEvent('IPreMessageUpdatedPrevent', appMessage));
if (prevent) {
throw new Meteor.Error('error-app-prevented-updating', 'A Rocket.Chat App prevented the message updating.');
if (originalMessage.msg !== message.msg) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

instead of shifting everything to inside the if, can you please change it to something like:

if (originalMessage.msg !== message.msg) {
	return;
}
/* rest of the code */

this way the code looks nicer and clean as so the diff :)

Copy link
Copy Markdown
Contributor Author

@Kailash0311 Kailash0311 Jan 18, 2019

Choose a reason for hiding this comment

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

Yeah true, I'll do that but shouldn't it be,

if (originalMessage.msg === message.msg) {
       return;
}

because we want to skip everything and return if both messages are equal ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, that's right :)

_id: message._id,
'u._id': Meteor.userId(),
}, { $set : messageObject });
if (originalMessage.msg !== message.msg) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like you could move this if up to the start of the method and make an "early return", similarly to the other file :)

@Kailash0311
Copy link
Copy Markdown
Contributor Author

Kailash0311 commented Jan 19, 2019

In the latest commit that I pushed, I early returned from updateMessage methods on client and sever. Earlier they were processing the entire method and passing into the updateMessage function on the server to be processed by Apps and updating the database.
This is better I think.
@sampaiodiego @geekgonecrazy @d-gubert what do you guys think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Message is recognized as edited even if there is no change in content

5 participants