From 55b2e1fd57d7cd0daeeed33ae9b241e4ee599939 Mon Sep 17 00:00:00 2001 From: Emil Ivov Date: Fri, 4 Sep 2009 14:39:10 +0000 Subject: [PATCH] Renames occurrences of callParticipant to callPeer so that it would better reflect our new Call architecture that also includes conferencing and ConferenceMembers --- ...ionSetBasicInstantMessagingJabberImpl.java | 75 ++++++++++++++++++- .../mailnotification/NewMailNotification.java | 22 ++---- .../NewMailNotificationProvider.java | 9 --- 3 files changed, 78 insertions(+), 28 deletions(-) diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java index d5b6d99f4..ca395f934 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java @@ -9,6 +9,7 @@ import java.util.*; import net.java.sip.communicator.impl.protocol.jabber.extensions.keepalive.*; +import net.java.sip.communicator.impl.protocol.jabber.extensions.mailnotification.*; import net.java.sip.communicator.impl.protocol.jabber.extensions.version.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.Message; @@ -22,7 +23,7 @@ import org.jivesoftware.smack.provider.*; import org.jivesoftware.smack.util.*; import org.jivesoftware.smackx.*; -import org.jivesoftware.smackx.packet.XHTMLExtension; +import org.jivesoftware.smackx.packet.*; /** * A straightforward implementation of the basic instant messaging operation @@ -286,7 +287,7 @@ private class RegistrationStateListener implements RegistrationStateChangeListener { /** - * The method is called by a ProtocolProvider implementation whenver + * The method is called by a ProtocolProvider implementation whenever * a change in the registration state of the corresponding provider had * occurred. * @param evt ProviderStatusChangeEvent the event describing the status @@ -311,7 +312,12 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt) new PacketTypeFilter( org.jivesoftware.smack.packet.Message.class)})); - // run keepalive thread + //subscribe for Google (GMail or Google Apps) notifications + //for new mail messages. + subscribeForGmailNotifications(); + + + // run keep alive thread if(keepAliveSendTask == null && keepAliveEnabled) { jabberProvider.getConnection().addPacketListener( @@ -625,4 +631,67 @@ public boolean accept(Packet packet) return true; } } + + /** + * Subscribes this provider as interested in receiving notifications for + * new mail messages from Google mail services such as GMail or Google Apps. + */ + private void subscribeForGmailNotifications() + { + //------listerner mail + try + { + // with discovered info, we can check if the remote clients + // supports e-mail but not if he don't, because + // a non conforming client can supports a feature + // without advertising it. + //So we don't rely on it (for the moment) + DiscoverInfo di = ServiceDiscoveryManager + .getInstanceFor(jabberProvider.getConnection()) + .discoverInfo(jabberProvider.getAccountID() + .getAccountAddress()); + if (di.containsFeature( + "http://jabber.org/protocol/disco#info")) + { + ProviderManager providerManager = + ProviderManager.getInstance(); + providerManager.addIQProvider( + "mailbox", "google:mail:notify", + new MailboxProvider()); + providerManager.addIQProvider( + "new-mail", "google:mail:notify", + new NewMailNotificationProvider()); + + jabberProvider.getConnection().addPacketListener( + new MailNotificationListener(), + new PacketTypeFilter( + IQ.class)); + + jabberProvider.getConnection().addPacketListener( + new NewMailNotificationListener(), + new PacketTypeFilter( + IQ.class)); + + if(opSetPersPresence.getCurrentStatusMessage() + .equals(JabberStatusEnum.OFFLINE)) + return; + + QueryNotify mailnotification = new QueryNotify(lastResultTime); + + logger.trace( + "send mailNotification for acc: " + + jabberProvider.getAccountID().getAccountUniqueID()); + + jabberProvider.getConnection().sendPacket(mailnotification); + } + } + catch (XMPPException ex) + { + logger.warn("could not retrieve info for "+ + jabberProvider.getAccountID().getAccountAddress(), + ex); + } + + + } } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/NewMailNotification.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/NewMailNotification.java index 41a923c2d..a41f8ef3f 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/NewMailNotification.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/NewMailNotification.java @@ -27,28 +27,18 @@ public class NewMailNotification extends IQ Logger.getLogger(NewMailNotification.class); /** - * The content of the new mail element + * The name space for new mail notification packets. */ - private String xmls; + public static final String NAMESPACE = "google:mail:notify"; /** - * Returns the xmls value of the new-mail element + * Returns the name space of the new-mail element * - * @return the xmls value of the new-mail element. + * @return the XML name space of the new-mail element. */ - public String getNmnxmls() + public String getXmlsns() { - return xmls; - } - - /** - * Sets the xmls value - * - * @param xmls the xmls String - */ - public void setNmnxmls(String xmls) - { - this.xmls = xmls; + return NAMESPACE; } /** diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/NewMailNotificationProvider.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/NewMailNotificationProvider.java index bbd973e0e..337f3c5ad 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/NewMailNotificationProvider.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/NewMailNotificationProvider.java @@ -48,15 +48,6 @@ public IQ parseIQ(final XmlPullParser parser) throws Exception iq.setTo(parser.getAttributeValue("", "to")); iq.setPacketID(parser.getAttributeValue("", "id")); - int eventType = parser.next(); - String name = parser.getName(); - if (eventType == XmlPullParser.START_TAG) - { - if ("new-mail".equals(name)) - { - iq.setNmnxmls(parser.getAttributeValue("", "xmlns")); - } - } return iq; } }