- if (p->subscribed != NONE) /* Only send state NOTIFY if we know the format */
- transmit_state_notify(p, state, 1, FALSE);
-
- ast_verb(2, "Extension Changed %s new state %s for Notify User %s\n", exten, ast_extension_state2str(state), p->username);
+ if (p->subscribed != NONE) { /* Only send state NOTIFY if we know the format */
+ if (!p->pendinginvite) {
+ transmit_state_notify(p, state, 1, FALSE);
+ } else {
+ /* We already have a NOTIFY sent that is not answered. Queue the state up.
+ if many state changes happen meanwhile, we will only send a notification of the last one */
+ ast_set_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE);
+ }
+ }
+ ast_verb(2, "Extension Changed %s[%s] new state %s for Notify User %s %s\n", exten, context, ast_extension_state2str(state), p->username,
+ ast_test_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE) ? "(queued)" : "");