[FIX] mention-links not being always resolved (#11745)
parent
b16fe93334
commit
8f40051d9b
@ -1,10 +1,17 @@ |
||||
import { FlowRouter } from 'meteor/kadira:flow-router'; |
||||
import { ChatSubscription } from 'meteor/rocketchat:models'; |
||||
import { roomTypes } from 'meteor/rocketchat:utils'; |
||||
import { call } from 'meteor/rocketchat:ui-utils'; |
||||
|
||||
FlowRouter.goToRoomById = (roomId) => { |
||||
const subscription = ChatSubscription.findOne({ rid: roomId }); |
||||
FlowRouter.goToRoomById = async(rid) => { |
||||
if (!rid) { |
||||
return; |
||||
} |
||||
const subscription = ChatSubscription.findOne({ rid }); |
||||
if (subscription) { |
||||
roomTypes.openRouteLink(subscription.t, subscription, FlowRouter.current().queryParams); |
||||
return roomTypes.openRouteLink(subscription.t, subscription, FlowRouter.current().queryParams); |
||||
} |
||||
|
||||
const room = await call('getRoomById', rid); |
||||
return roomTypes.openRouteLink(room.t, room, FlowRouter.current().queryParams); |
||||
}; |
||||
|
@ -0,0 +1,40 @@ |
||||
|
||||
import { Meteor } from 'meteor/meteor'; |
||||
import { check } from 'meteor/check'; |
||||
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter'; |
||||
|
||||
import { Rooms } from 'meteor/rocketchat:models'; |
||||
import { canAccessRoom } from 'meteor/rocketchat:authorization'; |
||||
|
||||
Meteor.methods({ |
||||
getRoomById(rid) { |
||||
check(rid, String); |
||||
const userId = Meteor.userId(); |
||||
if (!userId) { |
||||
throw new Meteor.Error('error-invalid-user', 'Invalid user', { |
||||
method: 'getRoomNameById', |
||||
}); |
||||
} |
||||
|
||||
const room = Rooms.findOneById(rid); |
||||
if (room == null) { |
||||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { |
||||
method: 'getRoomNameById', |
||||
}); |
||||
} |
||||
if (!canAccessRoom(room, Meteor.user())) { |
||||
throw new Meteor.Error('error-not-allowed', 'Not allowed', { |
||||
method: 'getRoomById', |
||||
}); |
||||
} |
||||
return room; |
||||
}, |
||||
}); |
||||
|
||||
DDPRateLimiter.addRule({ |
||||
type: 'method', |
||||
name: 'getRoomById', |
||||
userId() { |
||||
return true; |
||||
}, |
||||
}, 1, 60000); |
Loading…
Reference in new issue