From 224f3da2cada149f1e284169f0bd2c8f094b69f6 Mon Sep 17 00:00:00 2001 From: Emil Ivov Date: Fri, 4 Sep 2009 14:41:58 +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 | 94 +++---- .../extensions/mailnotification/Mailbox.java | 247 ------------------ .../mailnotification/MailboxProvider.java | 97 ------- .../mailnotification/NewMailNotification.java | 65 ----- .../NewMailNotificationProvider.java | 2 +- .../mailnotification/QueryNotify.java | 87 +++++- 6 files changed, 119 insertions(+), 473 deletions(-) delete mode 100644 src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/Mailbox.java delete mode 100644 src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/MailboxProvider.java delete mode 100644 src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/NewMailNotification.java 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 50882a90d..114975f20 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java @@ -90,6 +90,13 @@ public class OperationSetBasicInstantMessagingJabberImpl */ private static final String CLOSE_BODY_TAG = ""; + /** + * Contains the time of the last mail result set that we've received from + * the server. We use this time when sending new queries to the server so + * that it won't return messages that we've already shown to our user. + */ + private long lastResultTime = -1; + /** * Creates an instance of this operation set. * @param provider a reference to the ProtocolProviderServiceImpl @@ -639,26 +646,23 @@ public boolean accept(Packet packet) */ private void subscribeForGmailNotifications() { - //------listerner mail - try - { - // first check support for the notification service - boolean notificationsAreSupported = ServiceDiscoveryManager - .getInstanceFor(jabberProvider.getConnection()) - .includesFeature(NewMailNotification.NAMESPACE); + // first check support for the notification service + boolean notificationsAreSupported = ServiceDiscoveryManager + .getInstanceFor(jabberProvider.getConnection()) + .includesFeature(NewMailNotificationIQ.NAMESPACE); - if (!notificationsAreSupported) - return; + if (!notificationsAreSupported) + return; - ProviderManager providerManager = ProviderManager.getInstance(); - providerManager.addIQProvider( - Mailbox.ELEMENT_NAME, Mailbox.NAMESPACE, new MailboxProvider()); + ProviderManager providerManager = ProviderManager.getInstance(); + providerManager.addIQProvider( + MailboxIQ.ELEMENT_NAME, MailboxIQ.NAMESPACE, new MailboxIQProvider()); providerManager.addIQProvider( - NewMailNotification.ELEMENT_NAME, NewMailNotification.NAMESPACE, + NewMailNotificationIQ.ELEMENT_NAME, NewMailNotificationIQ.NAMESPACE, new NewMailNotificationProvider()); jabberProvider.getConnection().addPacketListener( - new MailNotificationListener(), + new MailboxListener(), new PacketTypeFilter( IQ.class)); @@ -678,61 +682,44 @@ private void subscribeForGmailNotifications() + jabberProvider.getAccountID().getAccountUniqueID()); jabberProvider.getConnection().sendPacket(mailnotification); - } - catch (XMPPException ex) - { - logger.warn("could not retrieve info for "+ - jabberProvider.getAccountID().getAccountAddress(), - ex); - } } /** * Receives incoming MailNotification Packets */ - private class MailNotificationListener + private class MailboxListener implements PacketListener { public void processPacket(Packet packet) { - if(packet != null && !(packet instanceof Mailbox)) + if(packet != null && !(packet instanceof MailboxIQ)) return; - Mailbox mailbox = (Mailbox) packet; + MailboxIQ mailbox = (MailboxIQ) packet; - //check if the date of the most recent mail is the same as that - //of the previous packet. If the last mail is the most recent, - //we notify it to the user - if ( lastDate < mailbox.getDate()) - { - lastResultTime = mailbox.getResultTime(); - lastDate = mailbox.getDate(); + String fromUserID + = StringUtils.parseBareAddress(mailbox.getSender()); - String fromUserID = - StringUtils.parseBareAddress(mailbox.getSender()); + //create the volatile contact + Contact sourceContact = opSetPersPresence + .createVolatileContact(fromUserID); - //create the volatile contact - Contact sourceContact = opSetPersPresence - .createVolatileContact(fromUserID); + String newMail = JabberActivator.getResources().getI18NString( + "service.gui.NEW_MAIL", + new String[]{mailbox.getSender(), + "<" + mailbox.getSender() + ">", + mailbox.getSubject(), + "    " +mailbox.getUrl()+ ""}) ; - String newMail = JabberActivator.getResources().getI18NString( - "service.gui.NEW_MAIL", - new String[]{mailbox.getSender(), - "<" + mailbox.getSender() + ">", - mailbox.getSubject(), - "    " +mailbox.getUrl() - + ""}) ; + Message newMailMessage = new MessageJabberImpl( + newMail, HTML_MIME_TYPE, DEFAULT_MIME_ENCODING, null); - Message newMailMessage = new MessageJabberImpl( newMail, - HTML_MIME_TYPE, DEFAULT_MIME_ENCODING, null); + MessageReceivedEvent msgReceivedEvt = new MessageReceivedEvent( + newMailMessage, sourceContact, System.currentTimeMillis(), + MessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED); - MessageReceivedEvent msgReceivedEvt = new MessageReceivedEvent( - newMailMessage, sourceContact, System.currentTimeMillis(), - MessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED); - - fireMessageEvent(msgReceivedEvt); - } + fireMessageEvent(msgReceivedEvt); } } @@ -744,7 +731,7 @@ private class NewMailNotificationListener { public void processPacket(Packet packet) { - if(packet != null && !(packet instanceof NewMailNotification)) + if(packet != null && !(packet instanceof NewMailNotificationIQ)) return; if(opSetPersPresence.getCurrentStatusMessage() @@ -760,5 +747,4 @@ public void processPacket(Packet packet) jabberProvider.getConnection().sendPacket(mailnotification); } } - } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/Mailbox.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/Mailbox.java deleted file mode 100644 index 52039fdda..000000000 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/Mailbox.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.jabber.extensions.mailnotification; - -import org.jivesoftware.smack.packet.*; -import net.java.sip.communicator.util.*; - -/** - * A straightforward extension of the IQ. A Mailbox object is created via the - * MailboxProvider. It contains all the information we need to notify the user - * about a new E-Mail message. - * - * @author Matthieu Helleringer - * @author Alain Knaebel - */ -public class Mailbox extends IQ -{ - - /** - * Logger for this class - */ - private static final Logger logger = - Logger.getLogger(Mailbox.class); - - /** - * The time these results were generated, in milliseconds since the - * UNIX epoch. This value should be cached and sent as the newer-than-time - * attribute in the next email query. - * not used for the moment - */ - private long resultTime; - - /** - * Number of unread messages. - */ - private int totalMatched; - - /** - * A number indicating whether total-matched is just an estimate: - * 1 indicates it is; 0 or omitted indicates that it is not. - */ - private boolean totalEstimate; - - /** - * Contains the address that a message was sent from - */ - private String sender; - - /** - * Indicates the subject of an email - */ - private String subject; - - /** - * Indicates the URL of the email server - */ - private String url; - - /** - * Indicates the date of the most recent email message. - */ - private long date; - - /** - * The name space for new mail notification packets. - */ - public static final String NAMESPACE = "google:mail:notify"; - - /** - * The name of the element that Google use to transport new mail - * notifications. - */ - public static final String ELEMENT_NAME = "mailbox"; - - /** - * Sets the date of the most recent unread mail content on the mail server, - * in milliseconds since the UNIX epoch. - * - * @param date the date long - */ - public void setDate(long date) - { - this.date = date; - } - - /** - * Returns the date of the most recent unread mail content on the mail - * server, in milliseconds since the UNIX epoch. - * - * @return the date of the most recent unread mail content on the mail - * server, in milliseconds since the UNIX epoch. - */ - public long getDate() - { - return this.date; - } - - /** - * Returns the time when these results were generated, in milliseconds - * since the UNIX epoch. - * - * @return the time when these results were generated, in milliseconds - * since the UNIX epoch. - */ - public long getResultTime() - { - return resultTime; - } - - /** - * Sets the time these results were generated, in milliseconds since the - * UNIX epoch. - * - * @param l the resultTime long - */ - public void setResultTime(long l) - { - this.resultTime = l; - } - - /** - * Returns the number of unread mail messages - * - * @return the total number of matched (unread) mail messages - */ - public int getTotalMatched() - { - return totalMatched; - } - - /** - * Specifies the number of unread mail messages. - * - * @param totalMatched the number of matched mail messages - */ - public void setTotalMatched(int totalMatched) - { - this.totalMatched = totalMatched; - } - - /** - * Determines whether the total of unread mail messages is an estimate or - * not. - * - * @return true if the total number of mail messages is an estimate - * and false otherwise. - */ - public boolean isTotalEstimate() - { - return totalEstimate; - } - - /** - * Specifies whether the total number of unread mail messages contained in - * this object is an estimate or a precise count. - * - * @param totalEstimate true if the number of total messages here - * is an estimate and false otherwise. - */ - public void setTotalEstimate(boolean totalEstimate) - { - this.totalEstimate = totalEstimate; - } - - /** - * Returns the sub-element XML section of the IQ packet, or null if - * there isn't one. Packet extensions must be included, if any are defined. - * - * @return the child element section of the IQ XML. - */ - @Override - public String getChildElementXML() - { - logger.debug("Mailbox.getChildElementXML usage"); - String totalString = totalEstimate ? " total-estimate='1' " : ""; - return ""; - } - - /** - * Specifies an HTTP URL of the mail server that contains the messages - * indicated in this Mailbox IQ. - * - * @param url the http URL where users could check the messages that this - * IQ refers to. - */ - public void setUrl(String url) - { - this.url = url; - } - - /** - * Returns the http URL of the mail server containing the messages that - * this IQ refers to. - * - * @return the http URL of the mail server containing the messages that - * this IQ refers to. - */ - public String getUrl() - { - return url; - } - - /** - * Specifies the sender of a mail referred to by this URL. - * - * @param - */ - public void setSender(String sender) - { - this.sender = sender; - } - - /** - * Set the subject of the last mail - * - * @param subject the subjet of the email String - */ - public void setSubject(String subject) - { - this.subject = subject; - } - - /** - * Return the sender of the last mail - * - * @return the sender of the email String - */ - public String getSender() - { - return this.sender; - } - - /** - * Return the subject of the last mail - * - * @return the subject of the email String - */ - public String getSubject() - { - return this.subject; - } -} diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/MailboxProvider.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/MailboxProvider.java deleted file mode 100644 index 3954b75a3..000000000 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/MailboxProvider.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.jabber.extensions.mailnotification; - -import org.jivesoftware.smack.packet.*; -import org.jivesoftware.smack.provider.*; -import org.xmlpull.v1.XmlPullParser; - -import net.java.sip.communicator.util.*; - -/** - * A straightforward implementation of the IQProvider. Parses custom IQ packets. - * We receive IQ mailbox packets from google mail servers and we use them to - * create Mailbox objects which contain all the information from the - * packet. - * - * @author Matthieu Helleringer - * @author Alain Knaebel - */ -public class MailboxProvider - implements IQProvider -{ - /** - * Logger for this class - */ - private static final Logger logger = - Logger.getLogger(MailboxProvider.class); - - /** - * Return an IQ (i.e. Mailbox) object which will contain - * the information we get from the parser. - * - * @param parser the XmlPullParser that we can use to get - * packet details. - * - * @return a new IQ instance which is the result of the XmlPullParser. - * @throws Exception if an error occurs parsing the XML. - */ - public IQ parseIQ(final XmlPullParser parser) throws Exception - { - logger.debug("Mailbox.getChildElementXML usage"); - Mailbox iq = new Mailbox(); - iq.setFrom(parser.getAttributeValue("", "from")); - iq.setTo(parser.getAttributeValue("", "to")); - iq.setPacketID(parser.getAttributeValue("", "id")); - iq.setResultTime(Long.parseLong( - parser.getAttributeValue("", "result-time"))); - iq.setTotalMatched(Integer.parseInt( - parser.getAttributeValue("", "total-matched"))); - iq.setTotalEstimate("1".equals( - parser.getAttributeValue("", "total-estimate"))); - iq.setUrl(parser.getAttributeValue("", "url")); - - int eventType = parser.next(); - String name = parser.getName(); - if (eventType == XmlPullParser.START_TAG) - { - if ("mail-thread-info".equals(name)) - { - iq.setDate(Long.parseLong( - parser.getAttributeValue("", "date"))); - for (int i =0;i<10;i++) - { - eventType = parser.next(); - if (eventType == XmlPullParser.START_TAG) - { - name = parser.getName(); - if ("sender".equals(name)) - { - if ( "1".equals( - parser.getAttributeValue("","originator"))) - { - iq.setSender(parser. - getAttributeValue("", "address")); - } - } - } - - if (eventType == XmlPullParser.START_TAG) - { - name = parser.getName(); - if ("subject".equals(name)) - { - name = parser.nextText(); - iq.setSubject(name); - } - } - } - } - } - return iq; - } -} 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 deleted file mode 100644 index 9cc24e75e..000000000 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/NewMailNotification.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.protocol.jabber.extensions.mailnotification; - -import org.jivesoftware.smack.packet.*; -import net.java.sip.communicator.util.*; - -/** - * A straightforward IQ extension. A NewMailNotification object is - * created via the NewMailNotificationProvider. It contains the - * information we need in order to determine whether there are new mails waiting - * for us on the mail server. - * - * @author Matthieu Helleringer - * @author Alain Knaebel - * @author Emil Ivov - */ -public class NewMailNotification extends IQ -{ - /** - * Logger for this class - */ - private static final Logger logger = - Logger.getLogger(NewMailNotification.class); - - /** - * The name space for new mail notification packets. - */ - public static final String NAMESPACE = "google:mail:notify"; - - /** - * The name of the element that Google use to transport new mail - * notifications. - */ - public static final String ELEMENT_NAME = "new-mail"; - - /** - * Returns the name space of the new-mail element - * - * @return the XML name space of the new-mail element. - */ - public String getXmlsns() - { - return NAMESPACE; - } - - /** - * Returns the sub-element XML section of the IQ packet. - * - * @return the child element section of the IQ XML - */ - @Override - public String getChildElementXML() - { - logger.trace("NewMailNotification.getChildElementXML usage"); - return ""; - } -} 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 337f3c5ad..0493c4102 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 @@ -43,7 +43,7 @@ public class NewMailNotificationProvider public IQ parseIQ(final XmlPullParser parser) throws Exception { logger.debug("NewMailNotificationProvider.getChildElementXML usage"); - NewMailNotification iq = new NewMailNotification(); + NewMailNotificationIQ iq = new NewMailNotificationIQ(); iq.setFrom(parser.getAttributeValue("", "from")); iq.setTo(parser.getAttributeValue("", "to")); iq.setPacketID(parser.getAttributeValue("", "id")); diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/QueryNotify.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/QueryNotify.java index a1dec1da0..a66cccdf6 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/QueryNotify.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/QueryNotify.java @@ -16,6 +16,7 @@ * * @author Matthieu Helleringer * @author Alain Knaebel + * @author Emil Ivov */ public class QueryNotify extends IQ { @@ -26,9 +27,19 @@ public class QueryNotify extends IQ Logger.getLogger(QueryNotify.class); /** - * the value of the result time of the last packet + * The name space for new mail notification packets. */ - private long timeResult; + public static final String NAMESPACE = "google:mail:notify"; + + /** + * The value of the newer-than-time attribute in this query; + */ + private long newerThanTime = -1; + + /** + * The value of the newer-than-tid attribute in this query; + */ + private long newerThanTid = -1; /** * Returns the sub-element XML section of the IQ packet. @@ -40,18 +51,76 @@ public String getChildElementXML() { logger.debug("QueryNotify.getChildElementXML usage"); - return ""; + StringBuffer xml = new StringBuffer( + ""); + } + + /** + * Sets the value of the "newer-than-time" attribute. The value indicates + * the time of the oldest unread email to retrieve, in milliseconds since + * the UNIX epoch (00:00:00 UTC, January 1 1970). When querying for the + * first time, you should omit this attribute (i.e. not call this method or + * call it with a -1 value) to return a set of the most recent + * unread mail. The sever will return only unread mail received after this + * time. If using this attribute, you should also use newer-than-tid for + * best results. + * + * @param newerThanTime the time of the oldest unread email to retrieve or + * -1 if the newer-than-time attribute should be omitted. + */ + public void setNewerThanTime(long newerThanTime) + { + this.newerThanTime = newerThanTime; + } + + /** + * Returns the value of the "newer-than-time" attribute. The value indicates + * the time of the oldest unread email to retrieve, in milliseconds since + * the UNIX epoch (00:00:00 UTC, January 1 1970). When querying for the + * first time, you should omit this attribute (i.e. not call this method or + * call it with a -1 value) to return a set of the most recent + * unread mail. The sever will return only unread mail received after this + * time. If using this attribute, you should also use newer-than-tid for + * best results. + * + * @return the time of the oldest unread email to retrieve or -1 if + * the attribute is to be omitted. + */ + public long getNewerThanTime(long newerThanTime) + { + return this.newerThanTime; } /** - * Creates a QueryNotify instance with time as the value - * of the "newer-than-time" attribute. + * Sets the value of the "newer-than-tid" attribute. The value indicates + * the highest thread number of messages to return, where higher numbers are + * more recent email threads. The server will return only threads newer than + * that specified by this attribute. If using this attribute, you should + * also use newer-than-time for best results. When querying for the first + * time, you should omit this value. * - * @param time the value of the "newer-than-time" attribute. + * @param newerThanTid the time of the oldest unread email to retrieve or + * -1 if the newer-than-time attribute should be omitted. */ - public QueryNotify(long time) + public void setNewerThanTid(long newerThanTid) { - this.timeResult = time; + this.newerThanTid = newerThanTid; } + + + + + + + }