apps/app_confbridge: Ensure 'normal' users hear message when last marked leaves
[asterisk/asterisk.git] / apps / confbridge / conf_state_multi_marked.c
index 42a8e7e..5d977f7 100644 (file)
@@ -86,8 +86,6 @@ static void leave_marked(struct confbridge_user *user)
        conf_remove_user_marked(user->conference, user);
 
        if (user->conference->markedusers == 0) {
-               need_prompt = 1;
-
                AST_LIST_TRAVERSE_SAFE_BEGIN(&user->conference->active_list, user_iter, list) {
                        /* Kick ENDMARKED cbu_iters */
                        if (ast_test_flag(&user_iter->u_profile, USER_OPT_ENDMARKED) && !user_iter->kicked) {
@@ -103,16 +101,17 @@ static void leave_marked(struct confbridge_user *user)
                                ast_bridge_remove(user_iter->conference->bridge, user_iter->chan);
                        } else if (ast_test_flag(&user_iter->u_profile, USER_OPT_WAITMARKED)
                                && !ast_test_flag(&user_iter->u_profile, USER_OPT_MARKEDUSER)) {
+                               need_prompt = 1;
+
                                AST_LIST_REMOVE_CURRENT(list);
                                user_iter->conference->activeusers--;
                                AST_LIST_INSERT_TAIL(&user_iter->conference->waiting_list, user_iter, list);
                                user_iter->conference->waitingusers++;
-
-                               /* Handle moh of user_iter if necessary */
-                               if (ast_test_flag(&user_iter->u_profile, USER_OPT_MUSICONHOLD)) {
-                                       conf_moh_start(user_iter);
-                               }
-                               conf_update_user_mute(user_iter);
+                       } else {
+                               /* User is neither wait_marked nor end_marked; however, they
+                                * should still hear the prompt.
+                                */
+                               need_prompt = 1;
                        }
                }
                AST_LIST_TRAVERSE_SAFE_END;
@@ -168,17 +167,36 @@ static void leave_marked(struct confbridge_user *user)
                        ast_autoservice_stop(user->chan);
                        ao2_lock(user->conference);
                }
+
+               AST_LIST_TRAVERSE(&user->conference->waiting_list, user_iter, list) {
+                       if (user_iter->kicked) {
+                               continue;
+                       }
+
+                       if (ast_test_flag(&user_iter->u_profile, USER_OPT_MUSICONHOLD)) {
+                               conf_moh_start(user_iter);
+                       }
+
+                       conf_update_user_mute(user_iter);
+               }
        }
 }
 
+static int post_join_play_begin(struct confbridge_user *cbu)
+{
+       int res;
+
+       ast_autoservice_start(cbu->chan);
+       res = play_sound_file(cbu->conference,
+               conf_get_sound(CONF_SOUND_BEGIN, cbu->b_profile.sounds));
+       ast_autoservice_stop(cbu->chan);
+       return res;
+}
+
 static void transition_to_marked(struct confbridge_user *user)
 {
        struct confbridge_user *user_iter;
-
-       /* Play the audio file stating they are going to be placed into the conference */
-       if (user->conference->markedusers == 1 && ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)) {
-               conf_handle_first_marked_common(user);
-       }
+       int waitmarked_moved = 0;
 
        /* Move all waiting users to active, stopping MOH and unmuting if necessary */
        AST_LIST_TRAVERSE_SAFE_BEGIN(&user->conference->waiting_list, user_iter, list) {
@@ -190,6 +208,15 @@ static void transition_to_marked(struct confbridge_user *user)
                        conf_moh_stop(user_iter);
                }
                conf_update_user_mute(user_iter);
+               waitmarked_moved++;
        }
        AST_LIST_TRAVERSE_SAFE_END;
+
+       /* Play the audio file stating that the conference is beginning */
+       if (user->conference->markedusers == 1
+               && ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)
+               && !ast_test_flag(&user->u_profile, USER_OPT_QUIET)
+               && waitmarked_moved) {
+               conf_add_post_join_action(user, post_join_play_begin);
+       }
 }