@@ -216,38 +216,39 @@ public Conversation beginConversation(boolean temporary, JoinMode joinMode) {
216
216
// set the temporary flag of the newly created conversation and also
217
217
// assign it a newly created, unique id
218
218
newConversation .setTemporary (temporary );
219
+ newConversation .setSwitched (joinMode == JoinMode .SWITCHED );
219
220
newConversation .setId (createNewConversationId ());
220
221
221
222
store .registerConversation (newConversation );
222
223
}
223
224
224
225
// check, if there is a current conversation
225
226
if (currentConversation != null ) {
227
+ // check, if nesting is not allowed and throw an exception if so
228
+ if (joinMode .mustBeRoot ()) {
229
+ throw new IllegalStateException (
230
+ "Beginning a new conversation while one is still in progress and nesting is not allowed is not possible." );
231
+ }
232
+
226
233
if (joinMode .mustBeJoined ()) {
227
234
currentConversation .joinConversation ();
228
235
return currentConversation ;
229
236
}
230
237
231
- if (joinMode .mustBeSwitched ()) {
238
+ if (joinMode .mustBeSwitched () && currentConversation . isSwitched () ) {
232
239
currentConversation .deactivated (ConversationDeactivationType .NEW_SWITCHED , newConversation );
233
240
}
234
241
235
242
// check, if the current one must be ended before creating a new one
236
- if (joinMode .mustEndCurrent ()) {
243
+ if (joinMode .mustEndCurrent (currentConversation )) {
237
244
endConversation (currentConversation , ConversationEndingType .TRANSCRIBED );
238
245
}
239
246
240
- // check, if nesting is not allowed and throw an exception if so
241
- if (joinMode .mustBeRoot ()) {
242
- throw new IllegalStateException (
243
- "Beginning a new conversation while one is still in progress and nesting is not allowed is not possible." );
244
- }
245
-
246
247
// nest the new conversation to the current one, if available and
247
248
// set the current one as the parent of the new one
248
249
if (joinMode .mustBeNested ()) {
249
250
newConversation .setParentConversation (currentConversation , joinMode .mustBeIsolated ());
250
- newConversation .deactivated (joinMode .mustBeIsolated () ? ConversationDeactivationType .NEW_ISOLATED
251
+ currentConversation .deactivated (joinMode .mustBeIsolated () ? ConversationDeactivationType .NEW_ISOLATED
251
252
: ConversationDeactivationType .NEW_NESTED , newConversation );
252
253
}
253
254
}
0 commit comments