From 67ed3589a553c5df1c4dac000a69837dcd1ff664 Mon Sep 17 00:00:00 2001 From: Emil Ivov Date: Fri, 2 Mar 2007 21:41:01 +0000 Subject: [PATCH] gibberish slck (Issue #241) and a better meta contact list ordering policy (Issue #316) instant messages destined for a gibberish contact that has a corresponding protocol provider installed in sip communicator, should be delivered to that provider instead of being echoed. --- ...SetBasicInstantMessagingGibberishImpl.java | 65 +++++++++++++++++-- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetBasicInstantMessagingGibberishImpl.java b/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetBasicInstantMessagingGibberishImpl.java index 98026febe..88e064f9b 100644 --- a/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetBasicInstantMessagingGibberishImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/gibberish/OperationSetBasicInstantMessagingGibberishImpl.java @@ -125,12 +125,69 @@ public void sendInstantMessage(Contact to, Message message) throws //first fire an event that we've delivered the message. //Note that in a real world protocol implementation we would first wait - //for a delivery confirmation coming from the protocol. + //for a delivery confirmation coming from the protocol stack. fireMessageDelivered(message, to); - //then fire an event saying we've received the same message as if it - //has been echoed by the "to" contact. - fireMessageReceived(message, to); + //now do message delivery. + deliverMessage(message, (ContactGibberishImpl)to); + } + + /** + * In case the to the to Contact corresponds to another gibberish + * protocol provider registered with SIP Communicator, we deliver + * the message to them, in case the to Contact represents us, we + * fire a MessageReceivedEvent, and if to is simply + * a contact in our contact list, then we simply echo the message. + * + * @param message the Message the message to deliver. + * @param to the Contact that we should deliver the message to. + */ + private void deliverMessage(Message message, ContactGibberishImpl to) + { + String userID = to.getAddress(); + + //if the user id is owr own id, then this message is being routed to us + //from another instance of the gibberish provider. + if (userID.equals(this.parentProvider.getAccountID().getUserID())) + { + //check who is the provider sending the message + String sourceUserID + = to.getProtocolProvider().getAccountID().getUserID(); + + //check whether they are in our contact list + Contact from = opSetPersPresence.findContactByID(sourceUserID); + + + //and if not - add them there as volatile. + if(from == null) + { + from = opSetPersPresence.createVolatileContact(sourceUserID); + } + + //and now fire the message received event. + fireMessageReceived(message, from); + } + else + { + //if userID is not our own, try an check whether another provider + //has that id and if yes - deliver the message to them. + ProtocolProviderServiceGibberishImpl gibberishProvider + = this.opSetPersPresence.findProviderForGibberishUserID(userID); + if(gibberishProvider != null) + { + OperationSetBasicInstantMessagingGibberishImpl opSetIM + = (OperationSetBasicInstantMessagingGibberishImpl) + gibberishProvider.getOperationSet( + OperationSetBasicInstantMessaging.class); + opSetIM.deliverMessage(message, to); + } + else + { + //if we got here then "to" is simply someone in our contact + //list so let's just echo the message. + fireMessageReceived(message, to); + } + } } /**