-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] No new room created when conversation is closed #13753
Conversation
if (!guest) { | ||
throw new Meteor.Error('invalid-token'); | ||
} | ||
|
||
// Check if conversation is closed or not. | ||
const closed = Rooms.findOneLivechatById(rid, fields); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't add this validation here because the current version of the Livechat client needs to create a new room when the current room is closed.
The point is that the issue #13733 is related to REST API endpoints, and our new Livechat client works over this approach, so I suggest you add validation on the Livechat message endpoint:
https://github.com/RocketChat/Rocket.Chat/blob/develop/app/livechat/server/api/v1/message.js#L33
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will do that.
@@ -34,6 +34,11 @@ API.v1.addRoute('livechat/message', { | |||
throw new Meteor.Error('invalid-room'); | |||
} | |||
|
|||
const closed = findRoomClosed(rid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to create another method to find rooms.
@@ -34,6 +34,11 @@ API.v1.addRoute('livechat/message', { | |||
throw new Meteor.Error('invalid-room'); | |||
} | |||
|
|||
const closed = findRoomClosed(rid); | |||
if (closed && closed.closedAt) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check the open
field, like:
if !(room && room.open) {
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be if (room && !room.open)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually my suggestion was to check both room
and room.open
in only one validation, but if you want to check the room.open
separately, yeah you just need to check:
if (!room.open) {
...
Below the existing validation:
if (!room) {
throw new Meteor.Error('invalid-room');
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it's fine right?
app/models/server/models/Rooms.js
Outdated
@@ -94,6 +94,21 @@ export class Rooms extends Base { | |||
return this.find(query, options); | |||
} | |||
|
|||
findOneLivechatById(_id, fields) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this method.
@renatobecker updated |
@@ -34,6 +34,10 @@ API.v1.addRoute('livechat/message', { | |||
throw new Meteor.Error('invalid-room'); | |||
} | |||
|
|||
if (room && !room.open) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just check:
if (!room.open) {
...
}
Because the room
object is checked here:
https://github.com/RocketChat/Rocket.Chat/blob/develop/app/livechat/server/api/v1/message.js#L33
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, let me update it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -34,6 +34,10 @@ API.v1.addRoute('livechat/message', { | |||
throw new Meteor.Error('invalid-room'); | |||
} | |||
|
|||
if (!room.open) { | |||
throw new Meteor.Error('chat-closed'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, replace the chat-closed
to room-closed
, according we do here:
https://github.com/RocketChat/Rocket.Chat/blob/develop/app/livechat/server/api/v1/room.js#L56
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 😄
Closes #13733
This PR solves the problem of creating a new room, again and again, once the conversation is closed.
Also fixed little CSS for analytics page from
to
cc @renatobecker would you please review.