[NEW] Add a new stream to emit and listen room data events (#15770)
parent
ff5fc05357
commit
00f072a093
@ -0,0 +1,11 @@ |
||||
import './app/livechatAutocompleteUser'; |
||||
import './app/livechatQueue'; |
||||
import './app/livechatReadOnly'; |
||||
import './app/livechatNotSubscribed.html'; |
||||
import './app/livechatRoomTagSelector.html'; |
||||
import './app/tabbar/externalSearch'; |
||||
import './app/tabbar/visitorEdit'; |
||||
import './app/tabbar/visitorForward'; |
||||
import './app/tabbar/visitorHistory'; |
||||
import './app/tabbar/visitorInfo'; |
||||
import './app/tabbar/visitorNavigation'; |
||||
@ -0,0 +1 @@ |
||||
export const ROOM_DATA_STREAM_OBSERVER = 'room-data-observer'; |
||||
@ -0,0 +1,40 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { roomTypes } from '../../../app/utils'; |
||||
import { ROOM_DATA_STREAM_OBSERVER } from '../../../app/utils/stream/constants'; |
||||
|
||||
export const roomDataStream = new Meteor.Streamer(ROOM_DATA_STREAM_OBSERVER); |
||||
|
||||
const isEmitAllowed = (t) => roomTypes.getConfig(t).isEmitAllowed(); |
||||
|
||||
roomDataStream.allowWrite('none'); |
||||
|
||||
roomDataStream.allowRead(function(rid) { |
||||
try { |
||||
const room = Meteor.call('canAccessRoom', rid, this.userId); |
||||
|
||||
if (!room) { |
||||
return false; |
||||
} |
||||
|
||||
if (isEmitAllowed(room.t) === false) { |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} catch (error) { |
||||
return false; |
||||
} |
||||
}); |
||||
|
||||
export function emitRoomDataEvent(id, data) { |
||||
if (!data) { |
||||
return; |
||||
} |
||||
|
||||
if (isEmitAllowed(data.t) === false) { |
||||
return; |
||||
} |
||||
|
||||
roomDataStream.emit(id, data); |
||||
} |
||||
Loading…
Reference in new issue