public static void reply ( XMPPConnection connection , Message original , Message reply ) throws XMPPErrorException , InterruptedException , NotConnectedException , NoResponseException , FeatureNotSupportedException { MultipleRecipientInfo info = getMultipleRecipientInfo ( original ) ; if ( info == null ) { throw new IllegalArgumentException ( "Original message does not contain multiple recipient info" ) ; } if ( info . shouldNotReply ( ) ) { throw new IllegalArgumentException ( "Original message should not be replied" ) ; } if ( info . getReplyRoom ( ) != null ) { throw new IllegalArgumentException ( "Reply should be sent through a room" ) ; } // Any <thread/> element from the initial message MUST be copied into the reply. if ( original . getThread ( ) != null ) { reply . setThread ( original . getThread ( ) ) ; } MultipleAddresses . Address replyAddress = info . getReplyAddress ( ) ; if ( replyAddress != null && replyAddress . getJid ( ) != null ) { // Send reply to the reply_to address reply . setTo ( replyAddress . getJid ( ) ) ; connection . sendStanza ( reply ) ; } else { // Send reply to multiple recipients List < Jid > to = new ArrayList <> ( info . getTOAddresses ( ) . size ( ) ) ; List < Jid > cc = new ArrayList <> ( info . getCCAddresses ( ) . size ( ) ) ; for ( MultipleAddresses . Address jid : info . getTOAddresses ( ) ) { to . add ( jid . getJid ( ) ) ; } for ( MultipleAddresses . Address jid : info . getCCAddresses ( ) ) { cc . add ( jid . getJid ( ) ) ; } // Add original sender as a 'to' address (if not already present) if ( ! to . contains ( original . getFrom ( ) ) && ! cc . contains ( original . getFrom ( ) ) ) { to . add ( original . getFrom ( ) ) ; } // Remove the sender from the TO/CC list (try with bare JID too) EntityFullJid from = connection . getUser ( ) ; if ( ! to . remove ( from ) && ! cc . remove ( from ) ) { EntityBareJid bareJID = from . asEntityBareJid ( ) ; to . remove ( bareJID ) ; cc . remove ( bareJID ) ; } send ( connection , reply , to , cc , null , null , null , false ) ; } }
Sends a reply to a previously received stanza that was sent to multiple recipients . Before attempting to send the reply message some checks are performed . If any of those checks fails then an XMPPException is going to be thrown with the specific error detail .