@@ -8,16 +8,16 @@ var sprintf = require('sprintf-js');
8
8
var events = require ( 'events' ) ;
9
9
var Session = ( function ( _super ) {
10
10
__extends ( Session , _super ) ;
11
- function Session ( args ) {
11
+ function Session ( options ) {
12
12
_super . call ( this ) ;
13
- this . args = args ;
13
+ this . options = options ;
14
14
this . msgSent = false ;
15
15
this . _isReset = false ;
16
16
this . lastSendTime = new Date ( ) . getTime ( ) ;
17
17
this . sendQueue = [ ] ;
18
- this . dialogs = args . dialogs ;
19
- if ( typeof this . args . minSendDelay !== 'number' ) {
20
- this . args . minSendDelay = 1000 ;
18
+ this . dialogs = options . dialogs ;
19
+ if ( typeof this . options . minSendDelay !== 'number' ) {
20
+ this . options . minSendDelay = 1000 ;
21
21
}
22
22
}
23
23
Session . prototype . dispatch = function ( sessionState , message ) {
@@ -60,8 +60,8 @@ var Session = (function (_super) {
60
60
} ;
61
61
Session . prototype . ngettext = function ( msgid , msgid_plural , count ) {
62
62
var tmpl ;
63
- if ( this . args . localizer && this . message ) {
64
- tmpl = this . args . localizer . ngettext ( this . message . language || '' , msgid , msgid_plural , count ) ;
63
+ if ( this . options . localizer && this . message ) {
64
+ tmpl = this . options . localizer . ngettext ( this . message . language || '' , msgid , msgid_plural , count ) ;
65
65
}
66
66
else if ( count == 1 ) {
67
67
tmpl = msgid ;
@@ -127,6 +127,10 @@ var Session = (function (_super) {
127
127
args [ _i - 1 ] = arguments [ _i ] ;
128
128
}
129
129
var ss = this . sessionState ;
130
+ if ( ! ss || ! ss . callstack || ss . callstack . length == 0 ) {
131
+ console . error ( 'ERROR: Too many calls to session.endDialog().' ) ;
132
+ return this ;
133
+ }
130
134
var m ;
131
135
var r = { } ;
132
136
if ( result ) {
@@ -172,6 +176,10 @@ var Session = (function (_super) {
172
176
Session . prototype . reset = function ( dialogId , dialogArgs ) {
173
177
this . _isReset = true ;
174
178
this . sessionState . callstack = [ ] ;
179
+ if ( ! dialogId ) {
180
+ dialogId = this . options . dialogId ;
181
+ dialogArgs = dialogArgs || this . options . dialogArgs ;
182
+ }
175
183
this . beginDialog ( dialogId , dialogArgs ) ;
176
184
return this ;
177
185
} ;
@@ -191,7 +199,7 @@ var Session = (function (_super) {
191
199
try {
192
200
var ss = this . sessionState ;
193
201
if ( ss . callstack . length == 0 ) {
194
- this . beginDialog ( this . args . dialogId , this . args . dialogArgs ) ;
202
+ this . beginDialog ( this . options . dialogId , this . options . dialogArgs ) ;
195
203
}
196
204
else if ( this . validateCallstack ( ) ) {
197
205
var cur = ss . callstack [ ss . callstack . length - 1 ] ;
@@ -201,7 +209,7 @@ var Session = (function (_super) {
201
209
}
202
210
else {
203
211
console . error ( 'Callstack is invalid, resetting session.' ) ;
204
- this . reset ( this . args . dialogId , this . args . dialogArgs ) ;
212
+ this . reset ( this . options . dialogId , this . options . dialogArgs ) ;
205
213
}
206
214
}
207
215
catch ( e ) {
@@ -210,8 +218,8 @@ var Session = (function (_super) {
210
218
} ;
211
219
Session . prototype . vgettext = function ( msgid , args ) {
212
220
var tmpl ;
213
- if ( this . args . localizer && this . message ) {
214
- tmpl = this . args . localizer . gettext ( this . message . language || '' , msgid ) ;
221
+ if ( this . options . localizer && this . message ) {
222
+ tmpl = this . options . localizer . gettext ( this . message . language || '' , msgid ) ;
215
223
}
216
224
else {
217
225
tmpl = msgid ;
@@ -239,11 +247,11 @@ var Session = (function (_super) {
239
247
if ( _this . sendQueue . length > 0 ) {
240
248
delaySend ( ) ;
241
249
}
242
- } , _this . args . minSendDelay - ( now - _this . lastSendTime ) ) ;
250
+ } , _this . options . minSendDelay - ( now - _this . lastSendTime ) ) ;
243
251
} ;
244
252
if ( this . sendQueue . length == 0 ) {
245
253
this . msgSent = true ;
246
- if ( ( now - this . lastSendTime ) >= this . args . minSendDelay ) {
254
+ if ( ( now - this . lastSendTime ) >= this . options . minSendDelay ) {
247
255
this . lastSendTime = now ;
248
256
this . emit ( event , message ) ;
249
257
}
0 commit comments