[Regression] Replace the Omnichannel queue model observe with Stream (#16999)
* Replace LivechatInquiry observe by stream. * Unify stream. * Add hasPermission method. * Add missing importers. * Revert package-lock file. * Improve the codebase. * Add return statement. * Fix remove listeners that were missing. * Removed unnecessary imports. * Remove unnecessary function parameters.pull/16973/head^2
parent
80c69c0fb8
commit
54b5523618
@ -1,5 +1,5 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { LIVECHAT_INQUIRY_DATA_STREAM_OBSERVER } from '../../../lib/stream/constants'; |
||||
import { LIVECHAT_INQUIRY_QUEUE_STREAM_OBSERVER } from '../../../lib/stream/constants'; |
||||
|
||||
export const inquiryDataStream = new Meteor.Streamer(LIVECHAT_INQUIRY_DATA_STREAM_OBSERVER); |
||||
export const inquiryDataStream = new Meteor.Streamer(LIVECHAT_INQUIRY_QUEUE_STREAM_OBSERVER); |
||||
|
@ -1,34 +0,0 @@ |
||||
import { Meteor } from 'meteor/meteor'; |
||||
|
||||
import { LivechatInquiry } from '../../../../models/server'; |
||||
import { LIVECHAT_INQUIRY_DATA_STREAM_OBSERVER } from '../../../lib/stream/constants'; |
||||
import { hasPermission } from '../../../../authorization/server'; |
||||
|
||||
export const inquiryDataStream = new Meteor.Streamer(LIVECHAT_INQUIRY_DATA_STREAM_OBSERVER); |
||||
|
||||
inquiryDataStream.allowWrite('none'); |
||||
|
||||
inquiryDataStream.allowRead(function() { |
||||
return this.userId ? hasPermission(this.userId, 'view-l-room') : false; |
||||
}); |
||||
|
||||
const emitInquiryDataEvent = (id, data) => { |
||||
if (!data) { |
||||
return; |
||||
} |
||||
|
||||
inquiryDataStream.emit(id, data); |
||||
}; |
||||
|
||||
LivechatInquiry.on('change', ({ clientAction, id }) => { |
||||
switch (clientAction) { |
||||
case 'inserted': |
||||
case 'updated': |
||||
emitInquiryDataEvent(id, LivechatInquiry.findOneById(id)); |
||||
break; |
||||
|
||||
case 'removed': |
||||
emitInquiryDataEvent(id, { _id: id }); |
||||
break; |
||||
} |
||||
}); |
Loading…
Reference in new issue