From 018500c0002cb50b704435bb5a1883b6de21880d Mon Sep 17 00:00:00 2001 From: Emil Ivov Date: Tue, 8 Sep 2009 15:45:28 +0000 Subject: [PATCH] More work on GMail nofitications. --- ...ionSetBasicInstantMessagingJabberImpl.java | 47 ++++++++++++++++++- .../mailnotification/MailThreadInfo.java | 18 ++++++- 2 files changed, 62 insertions(+), 3 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 a9562313e..17b65e19a 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetBasicInstantMessagingJabberImpl.java @@ -52,6 +52,19 @@ public class OperationSetBasicInstantMessagingJabberImpl private boolean keepAliveEnabled = false; + /** + * The maximum number of unread threads that we'd be notifying the user of. + */ + private static final String PNAME_MAX_GMAIL_THREADS_PER_NOTIFICATION + = "net.java.sip.communicator.impl.protocol.jabber." + +"MAX_GMAIL_THREADS_PER_NOTIFICATION"; + + /** + * Determines whether or not we are to deliver GMail notifications to the + * user. + */ + private boolean enableGmailNotifications = false; + /** * The task sending packets */ @@ -321,7 +334,8 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt) //subscribe for Google (GMail or Google Apps) notifications //for new mail messages. - subscribeForGmailNotifications(); + if (enableGmailNotifications) + subscribeForGmailNotifications(); // run keep alive thread @@ -718,12 +732,41 @@ private String createMailboxDescription(MailboxIQ mailboxIQ) Iterator threads = mailboxIQ.threads(); - while(threads.hasNext()) + String maxThreadsStr = (String)JabberActivator.getConfigurationService() + .getProperty(PNAME_MAX_GMAIL_THREADS_PER_NOTIFICATION); + + int maxThreads = 5; + + try + { + if(maxThreadsStr != null) + maxThreads = Integer.parseInt(maxThreadsStr); + } + catch (NumberFormatException e) + { + logger.debug("Failed to parse max threads count: "+maxThreads + +". Going for default."); + } + + //print a maximum of MAX_THREADS + for (int i = 0; i < maxThreads && threads.hasNext(); i++) { message.append(threads.next().createHtmlDescription()); } message.append("

"); + int threadCount = mailboxIQ.getThreadCount(); + if(threadCount > maxThreads) + { + message.append(threadCount - maxThreads + + " more unread messages in your " + + " inbox.
"); + } + + + + // + return message.toString(); } /** diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/MailThreadInfo.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/MailThreadInfo.java index c98b89cc1..a628bb62b 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/MailThreadInfo.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/mailnotification/MailThreadInfo.java @@ -156,7 +156,9 @@ public class Sender public String getFirstName() { if(name == null || name.trim().length() == 0) + { return null; + } String[] names = name.split("\\s"); @@ -601,7 +603,21 @@ private String createParticipantNames() String name = firstNamesOnly? sender.getFirstName() : sender.name; if (name == null) - name = sender.address; + { + //if there's no name then use the user part of the address + if (sender.address != null) + { + int atIndex = sender.address.indexOf("@"); + + if(atIndex != -1) + return sender.address.substring(0, atIndex); + else + name = sender.address; + } + else + name = "unknown"; + } + if (!sender.unread && maximumReadAllowed == 0) continue;