@@ -52,10 +52,11 @@ export default class Polls {
5252 this . _xmpp . pollsComponentAddress ,
5353 JSON . stringify ( {
5454 answers : answers . map ( answer => answer . name ) ,
55+ command : COMMAND_NEW_POLL ,
5556 pollId,
5657 question,
5758 roomJid : this . _mainRoom . roomjid ,
58- type : COMMAND_NEW_POLL
59+ type : 'polls'
5960 } ) ,
6061 'json-message' ,
6162 true ) ;
@@ -72,8 +73,9 @@ export default class Polls {
7273 this . _xmpp . pollsComponentAddress ,
7374 JSON . stringify ( {
7475 answers,
76+ command : COMMAND_ANSWER_POLL ,
7577 pollId,
76- type : COMMAND_ANSWER_POLL
78+ type : 'polls'
7779 } ) ,
7880 'json-message' ,
7981 true ) ;
@@ -85,20 +87,18 @@ export default class Polls {
8587 * @param {object } payload - Arbitrary data.
8688 */
8789 _handleMessages ( payload ) {
88- switch ( payload . type ) {
90+ switch ( payload . command ) {
8991 case COMMAND_NEW_POLL :
9092 this . _mainRoom . eventEmitter . emit ( XMPPEvents . POLLS_RECEIVE_EVENT , payload ) ;
9193
9294 break ;
9395 case COMMAND_OLD_POLLS : {
94- if ( payload ?. polls ) {
95- payload . polls . forEach ( ( poll : any ) => {
96- this . _mainRoom . eventEmitter . emit ( XMPPEvents . POLLS_RECEIVE_EVENT , {
97- history : true ,
98- ...poll
99- } ) ;
96+ payload ?. polls ?. forEach ( ( poll : any ) => {
97+ this . _mainRoom . eventEmitter . emit ( XMPPEvents . POLLS_RECEIVE_EVENT , {
98+ history : true ,
99+ ...poll
100100 } ) ;
101- }
101+ } ) ;
102102 break ;
103103 }
104104 case COMMAND_ANSWER_POLL : {
0 commit comments