From 8fb0fb0c0d7a760d1bea33701a794f3ab2ba6664 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sat, 27 Sep 2014 11:37:02 +0200 Subject: anwser to xmpp: style uris. fixed open conversations from android address book --- .../services/XmppConnectionService.java | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index db3ee2b91..524a3bd78 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -824,7 +824,7 @@ public class XmppConnectionService extends Service { } }); } - + public int loadMoreMessages(Conversation conversation, long timestamp) { List messages = databaseBackend.getMessages(conversation, 50, timestamp); @@ -851,8 +851,9 @@ public class XmppConnectionService extends Service { public Conversation find(List haystack, Account account, String jid) { for (Conversation conversation : haystack) { - if ((conversation.getAccount().equals(account)) - && (conversation.getContactJid().split("/",2)[0].equals(jid))) { + if ((account == null || conversation.getAccount().equals(account)) + && (conversation.getContactJid().split("/", 2)[0] + .equals(jid))) { return conversation; } } @@ -1742,4 +1743,18 @@ public class XmppConnectionService extends Service { public interface OnRosterUpdate { public void onRosterUpdate(); } + + public List findContacts(String jid) { + ArrayList contacts = new ArrayList(); + for (Account account : getAccounts()) { + if (!account.isOptionSet(Account.OPTION_DISABLED)) { + Contact contact = account.getRoster() + .getContactAsShownInRoster(jid); + if (contact != null) { + contacts.add(contact); + } + } + } + return contacts; + } } -- cgit v1.2.3 From 1ae9338fc9d5f8e1f6505445f07f4476efd8f139 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Sat, 27 Sep 2014 18:16:31 +0200 Subject: made muc passwords and prefereced encryption method persistant across restarts --- src/eu/siacs/conversations/services/XmppConnectionService.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 524a3bd78..badf1df52 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -1119,6 +1119,7 @@ public class XmppConnectionService extends Service { } pushBookmarks(conversation.getAccount()); } + databaseBackend.updateConversation(conversation); joinMuc(conversation); } } -- cgit v1.2.3 From bff23c2e232e8f9a4e64553215130079b7fc5a4f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 28 Sep 2014 15:21:56 +0200 Subject: new notification service. first draft --- .../conversations/services/EventReceiver.java | 3 +- .../conversations/services/ImageProvider.java | 2 +- .../services/NotificationService.java | 165 +++++++++++++++++++++ .../services/XmppConnectionService.java | 19 ++- 4 files changed, 177 insertions(+), 12 deletions(-) create mode 100644 src/eu/siacs/conversations/services/NotificationService.java (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/EventReceiver.java b/src/eu/siacs/conversations/services/EventReceiver.java index e2445b2a9..dfbe9db76 100644 --- a/src/eu/siacs/conversations/services/EventReceiver.java +++ b/src/eu/siacs/conversations/services/EventReceiver.java @@ -15,7 +15,8 @@ public class EventReceiver extends BroadcastReceiver { } else { mIntentForService.setAction("other"); } - if (intent.getAction().equals("ui") || DatabaseBackend.getInstance(context).hasEnabledAccounts()) { + if (intent.getAction().equals("ui") + || DatabaseBackend.getInstance(context).hasEnabledAccounts()) { context.startService(mIntentForService); } } diff --git a/src/eu/siacs/conversations/services/ImageProvider.java b/src/eu/siacs/conversations/services/ImageProvider.java index af8ab4b2c..ac78a4540 100644 --- a/src/eu/siacs/conversations/services/ImageProvider.java +++ b/src/eu/siacs/conversations/services/ImageProvider.java @@ -31,7 +31,7 @@ public class ImageProvider extends ContentProvider { if (uuids == null) { throw new FileNotFoundException(); } - String[] uuidsSplited = uuids.split("/",2); + String[] uuidsSplited = uuids.split("/", 2); if (uuidsSplited.length != 3) { throw new FileNotFoundException(); } diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java new file mode 100644 index 000000000..b004d1c58 --- /dev/null +++ b/src/eu/siacs/conversations/services/NotificationService.java @@ -0,0 +1,165 @@ +package eu.siacs.conversations.services; + +import java.util.ArrayList; +import java.util.LinkedHashMap; + +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.Uri; +import android.support.v4.app.NotificationCompat; +import android.support.v4.app.TaskStackBuilder; +import android.text.Html; + +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.ui.ConversationActivity; + +public class NotificationService { + + private XmppConnectionService mXmppConnectionService; + private NotificationManager mNotificationManager; + + private LinkedHashMap> notifications = new LinkedHashMap>(); + + public int NOTIFICATION_ID = 0x2342; + + public NotificationService(XmppConnectionService service) { + this.mXmppConnectionService = service; + this.mNotificationManager = (NotificationManager) service + .getSystemService(Context.NOTIFICATION_SERVICE); + } + + public synchronized void push(Message message) { + String conversationUuid = message.getConversationUuid(); + if (notifications.containsKey(conversationUuid)) { + notifications.get(conversationUuid).add(message); + } else { + ArrayList mList = new ArrayList(); + mList.add(message); + notifications.put(conversationUuid, mList); + } + updateNotification(true); + } + + public void clear() { + notifications.clear(); + updateNotification(false); + } + + public void clear(Conversation conversation) { + notifications.remove(conversation.getUuid()); + updateNotification(false); + } + + private void updateNotification(boolean notify) { + SharedPreferences preferences = mXmppConnectionService.getPreferences(); + + String ringtone = preferences.getString("notification_ringtone", null); + boolean vibrate = preferences.getBoolean("vibrate_on_notification", + true); + + if (notifications.size() == 0) { + mNotificationManager.cancel(NOTIFICATION_ID); + } else { + NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( + mXmppConnectionService); + mBuilder.setSmallIcon(R.drawable.ic_notification); + if (notifications.size() == 1) { + ArrayList messages = notifications.values().iterator() + .next(); + if (messages.size() >= 1) { + Conversation conversation = messages.get(0) + .getConversation(); + mBuilder.setLargeIcon(conversation.getImage( + mXmppConnectionService, 64)); + mBuilder.setContentTitle(conversation.getName()); + StringBuilder text = new StringBuilder(); + for (int i = 0; i < messages.size(); ++i) { + text.append(messages.get(i).getReadableBody( + mXmppConnectionService)); + if (i != messages.size() - 1) { + text.append("\n"); + } + } + mBuilder.setStyle(new NotificationCompat.BigTextStyle() + .bigText(text.toString())); + mBuilder.setContentText(messages.get(0).getReadableBody( + mXmppConnectionService)); + mBuilder.setTicker(messages.get(messages.size() - 1) + .getReadableBody(mXmppConnectionService)); + mBuilder.setContentIntent(createContentIntent(conversation + .getUuid())); + } else { + mNotificationManager.cancel(NOTIFICATION_ID); + return; + } + } else { + NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); + style.setBigContentTitle(notifications.size() + + " " + + mXmppConnectionService + .getString(R.string.unread_conversations)); + StringBuilder names = new StringBuilder(); + for (ArrayList messages : notifications.values()) { + if (messages.size() > 0) { + String name = messages.get(0).getConversation() + .getName(); + style.addLine(Html.fromHtml("" + + name + + " " + + messages.get(0).getReadableBody( + mXmppConnectionService))); + names.append(name); + names.append(", "); + } + } + if (names.length() >= 2) { + names.delete(names.length() - 2, names.length()); + } + mBuilder.setContentTitle(notifications.size() + + " " + + mXmppConnectionService + .getString(R.string.unread_conversations)); + mBuilder.setContentText(names.toString()); + mBuilder.setStyle(style); + } + if (notify) { + if (vibrate) { + int dat = 70; + long[] pattern = { 0, 3 * dat, dat, dat }; + mBuilder.setVibrate(pattern); + } + mBuilder.setLights(0xffffffff, 2000, 4000); + if (ringtone != null) { + mBuilder.setSound(Uri.parse(ringtone)); + } + } + Notification notification = mBuilder.build(); + mNotificationManager.notify(NOTIFICATION_ID, notification); + } + } + + private PendingIntent createContentIntent(String conversationUuid) { + TaskStackBuilder stackBuilder = TaskStackBuilder + .create(mXmppConnectionService); + stackBuilder.addParentStack(ConversationActivity.class); + + Intent viewConversationIntent = new Intent(mXmppConnectionService, + ConversationActivity.class); + viewConversationIntent.setAction(Intent.ACTION_VIEW); + viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, + conversationUuid); + viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION); + + stackBuilder.addNextIntent(viewConversationIntent); + + PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, + PendingIntent.FLAG_UPDATE_CURRENT); + return resultPendingIntent; + } +} diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index badf1df52..2ca11286f 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -93,6 +93,8 @@ public class XmppConnectionService extends Service { private MemorizingTrustManager mMemorizingTrustManager; + private NotificationService mNotificationService; + private MessageParser mMessageParser = new MessageParser(this); private PresenceParser mPresenceParser = new PresenceParser(this); private IqParser mIqParser = new IqParser(this); @@ -401,6 +403,7 @@ public class XmppConnectionService extends Service { this.mRandom = new SecureRandom(); this.mMemorizingTrustManager = new MemorizingTrustManager( getApplicationContext()); + this.mNotificationService = new NotificationService(this); this.databaseBackend = DatabaseBackend .getInstance(getApplicationContext()); this.fileBackend = new FileBackend(getApplicationContext()); @@ -1268,7 +1271,7 @@ public class XmppConnectionService extends Service { } } } - notifyUi(conversation, false); + updateConversationUi(); } public boolean renewSymmetricKey(Conversation conversation) { @@ -1577,15 +1580,6 @@ public class XmppConnectionService extends Service { return getPreferences().getBoolean("indicate_received", false); } - public void notifyUi(Conversation conversation, boolean notify) { - if (mOnConversationUpdate != null) { - mOnConversationUpdate.onConversationUpdate(); - } else { - UIHelper.updateNotification(getApplicationContext(), - getConversations(), conversation, notify); - } - } - public void updateConversationUi() { if (mOnConversationUpdate != null) { mOnConversationUpdate.onConversationUpdate(); @@ -1624,6 +1618,7 @@ public class XmppConnectionService extends Service { public void markRead(Conversation conversation) { conversation.markRead(); + mNotificationService.clear(conversation); String id = conversation.popLatestMarkableMessageId(); if (confirmMessages() && id != null) { Account account = conversation.getAccount(); @@ -1758,4 +1753,8 @@ public class XmppConnectionService extends Service { } return contacts; } + + public void pushNotification(Message message) { + this.mNotificationService.push(message); + } } -- cgit v1.2.3 From 87010e6094cc35ece98d3beadbbfbc59ea0a25b3 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 28 Sep 2014 16:33:25 +0200 Subject: more improvments for new notification service --- .../conversations/services/NotificationService.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java index b004d1c58..656e16f36 100644 --- a/src/eu/siacs/conversations/services/NotificationService.java +++ b/src/eu/siacs/conversations/services/NotificationService.java @@ -2,6 +2,9 @@ package eu.siacs.conversations.services; import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import android.app.Notification; import android.app.NotificationManager; @@ -162,4 +165,22 @@ public class NotificationService { PendingIntent.FLAG_UPDATE_CURRENT); return resultPendingIntent; } + + public static boolean wasHighlightedOrPrivate(Message message) { + String nick = message.getConversation().getMucOptions().getActualNick(); + Pattern highlight = generateNickHighlightPattern(nick); + Matcher m = highlight.matcher(message.getBody()); + return (m.find() || message.getType() == Message.TYPE_PRIVATE); + } + + private static Pattern generateNickHighlightPattern(String nick) { + // We expect a word boundary, i.e. space or start of string, followed by + // the + // nick (matched in case-insensitive manner), followed by optional + // punctuation (for example "bob: i disagree" or "how are you alice?"), + // followed by another word boundary. + return Pattern.compile("\\b" + nick + "\\p{Punct}?\\b", + Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); + } + } -- cgit v1.2.3 From 511b7a53f41f8254449e6c2c6eff795f728e7a33 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 29 Sep 2014 18:28:13 +0200 Subject: notifiy only when necessary --- .../services/NotificationService.java | 30 ++++++++++++++++++---- .../services/XmppConnectionService.java | 8 +++--- 2 files changed, 30 insertions(+), 8 deletions(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java index 656e16f36..831ce51ff 100644 --- a/src/eu/siacs/conversations/services/NotificationService.java +++ b/src/eu/siacs/conversations/services/NotificationService.java @@ -2,7 +2,6 @@ package eu.siacs.conversations.services; import java.util.ArrayList; import java.util.LinkedHashMap; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -16,7 +15,9 @@ import android.net.Uri; import android.support.v4.app.NotificationCompat; import android.support.v4.app.TaskStackBuilder; import android.text.Html; +import android.util.Log; +import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; @@ -30,6 +31,8 @@ public class NotificationService { private LinkedHashMap> notifications = new LinkedHashMap>(); public int NOTIFICATION_ID = 0x2342; + private Conversation mOpenConversation; + private boolean mIsInForeground; public NotificationService(XmppConnectionService service) { this.mXmppConnectionService = service; @@ -38,6 +41,13 @@ public class NotificationService { } public synchronized void push(Message message) { + if (this.mIsInForeground + && this.mOpenConversation == message.getConversation()) { + Log.d(Config.LOGTAG,"ignoring notification because foreground and conv matches"); + return; // simply ignore + } else { + Log.d(Config.LOGTAG,"pushed new notification"); + } String conversationUuid = message.getConversationUuid(); if (notifications.containsKey(conversationUuid)) { notifications.get(conversationUuid).add(message); @@ -46,7 +56,7 @@ public class NotificationService { mList.add(message); notifications.put(conversationUuid, mList); } - updateNotification(true); + updateNotification(!(this.mIsInForeground && this.mOpenConversation == null)); } public void clear() { @@ -93,8 +103,10 @@ public class NotificationService { .bigText(text.toString())); mBuilder.setContentText(messages.get(0).getReadableBody( mXmppConnectionService)); - mBuilder.setTicker(messages.get(messages.size() - 1) - .getReadableBody(mXmppConnectionService)); + if (notify) { + mBuilder.setTicker(messages.get(messages.size() - 1) + .getReadableBody(mXmppConnectionService)); + } mBuilder.setContentIntent(createContentIntent(conversation .getUuid())); } else { @@ -137,11 +149,11 @@ public class NotificationService { long[] pattern = { 0, 3 * dat, dat, dat }; mBuilder.setVibrate(pattern); } - mBuilder.setLights(0xffffffff, 2000, 4000); if (ringtone != null) { mBuilder.setSound(Uri.parse(ringtone)); } } + mBuilder.setLights(0xffffffff, 2000, 4000); Notification notification = mBuilder.build(); mNotificationManager.notify(NOTIFICATION_ID, notification); } @@ -183,4 +195,12 @@ public class NotificationService { Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); } + public void setOpenConversation(Conversation conversation) { + this.mOpenConversation = conversation; + } + + public void setIsInForeground(boolean foreground) { + this.mIsInForeground = foreground; + } + } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 2ca11286f..b83be7fbd 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -971,6 +971,7 @@ public class XmppConnectionService extends Service { switchToForeground(); } this.mOnConversationUpdate = listener; + this.mNotificationService.setIsInForeground(true); this.convChangedListenerCount++; } @@ -978,6 +979,7 @@ public class XmppConnectionService extends Service { this.convChangedListenerCount--; if (this.convChangedListenerCount == 0) { this.mOnConversationUpdate = null; + this.mNotificationService.setIsInForeground(false); if (checkListeners()) { switchToBackground(); } @@ -1753,8 +1755,8 @@ public class XmppConnectionService extends Service { } return contacts; } - - public void pushNotification(Message message) { - this.mNotificationService.push(message); + + public NotificationService getNotificationService() { + return this.mNotificationService; } } -- cgit v1.2.3 From 4b09f0e9d3296b4b71d3b31c9102610cc8037d20 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 2 Oct 2014 17:36:02 +0200 Subject: properly dismiss notifications --- .../conversations/services/NotificationService.java | 16 ++++++++++++++-- .../conversations/services/XmppConnectionService.java | 19 +++++++++++-------- 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java index 831ce51ff..1bc494b74 100644 --- a/src/eu/siacs/conversations/services/NotificationService.java +++ b/src/eu/siacs/conversations/services/NotificationService.java @@ -120,10 +120,11 @@ public class NotificationService { + mXmppConnectionService .getString(R.string.unread_conversations)); StringBuilder names = new StringBuilder(); + Conversation conversation = null; for (ArrayList messages : notifications.values()) { if (messages.size() > 0) { - String name = messages.get(0).getConversation() - .getName(); + conversation = messages.get(0).getConversation(); + String name = conversation.getName(); style.addLine(Html.fromHtml("" + name + " " @@ -142,6 +143,10 @@ public class NotificationService { .getString(R.string.unread_conversations)); mBuilder.setContentText(names.toString()); mBuilder.setStyle(style); + if (conversation!=null) { + mBuilder.setContentIntent(createContentIntent(conversation + .getUuid())); + } } if (notify) { if (vibrate) { @@ -153,6 +158,7 @@ public class NotificationService { mBuilder.setSound(Uri.parse(ringtone)); } } + mBuilder.setDeleteIntent(createDeleteIntent()); mBuilder.setLights(0xffffffff, 2000, 4000); Notification notification = mBuilder.build(); mNotificationManager.notify(NOTIFICATION_ID, notification); @@ -177,6 +183,12 @@ public class NotificationService { PendingIntent.FLAG_UPDATE_CURRENT); return resultPendingIntent; } + + private PendingIntent createDeleteIntent() { + Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class); + intent.setAction("clear_notification"); + return PendingIntent.getService(mXmppConnectionService, 0, intent, 0); + } public static boolean wasHighlightedOrPrivate(Message message) { String nick = message.getConversation().getMucOptions().getActualNick(); diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index b83be7fbd..0676c6030 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -90,6 +90,7 @@ public class XmppConnectionService extends Service { public long startDate; private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts"; + public static String ACTION_CLEAR_NOTIFICATION = "clear_notification"; private MemorizingTrustManager mMemorizingTrustManager; @@ -318,14 +319,16 @@ public class XmppConnectionService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { - if ((intent != null) - && (ACTION_MERGE_PHONE_CONTACTS.equals(intent.getAction()))) { - mergePhoneContactsWithRoster(); - return START_STICKY; - } else if ((intent != null) - && (Intent.ACTION_SHUTDOWN.equals(intent.getAction()))) { - logoutAndSave(); - return START_NOT_STICKY; + if (intent != null && intent.getAction() != null) { + if (intent.getAction().equals(ACTION_MERGE_PHONE_CONTACTS)) { + mergePhoneContactsWithRoster(); + return START_STICKY; + } else if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) { + logoutAndSave(); + return START_NOT_STICKY; + } else if (intent.getAction().equals(ACTION_CLEAR_NOTIFICATION)) { + mNotificationService.clear(); + } } this.wakeLock.acquire(); ConnectivityManager cm = (ConnectivityManager) getApplicationContext() -- cgit v1.2.3 From f8be57d43f83925d7f298ee1d34ef8cee32acec3 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 2 Oct 2014 18:31:19 +0200 Subject: show displayed by contact on all devices --- .../siacs/conversations/services/NotificationService.java | 14 +++++--------- .../conversations/services/XmppConnectionService.java | 6 ++++-- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java index 1bc494b74..012bac302 100644 --- a/src/eu/siacs/conversations/services/NotificationService.java +++ b/src/eu/siacs/conversations/services/NotificationService.java @@ -15,9 +15,7 @@ import android.net.Uri; import android.support.v4.app.NotificationCompat; import android.support.v4.app.TaskStackBuilder; import android.text.Html; -import android.util.Log; -import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; @@ -43,10 +41,7 @@ public class NotificationService { public synchronized void push(Message message) { if (this.mIsInForeground && this.mOpenConversation == message.getConversation()) { - Log.d(Config.LOGTAG,"ignoring notification because foreground and conv matches"); return; // simply ignore - } else { - Log.d(Config.LOGTAG,"pushed new notification"); } String conversationUuid = message.getConversationUuid(); if (notifications.containsKey(conversationUuid)) { @@ -143,9 +138,9 @@ public class NotificationService { .getString(R.string.unread_conversations)); mBuilder.setContentText(names.toString()); mBuilder.setStyle(style); - if (conversation!=null) { + if (conversation != null) { mBuilder.setContentIntent(createContentIntent(conversation - .getUuid())); + .getUuid())); } } if (notify) { @@ -183,9 +178,10 @@ public class NotificationService { PendingIntent.FLAG_UPDATE_CURRENT); return resultPendingIntent; } - + private PendingIntent createDeleteIntent() { - Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class); + Intent intent = new Intent(mXmppConnectionService, + XmppConnectionService.class); intent.setAction("clear_notification"); return PendingIntent.getService(mXmppConnectionService, 0, intent, 0); } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 0676c6030..ffef19ed1 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -1545,7 +1545,9 @@ public class XmppConnectionService extends Service { public boolean markMessage(Conversation conversation, String uuid, int status) { for (Message message : conversation.getMessages()) { - if (message.getUuid().equals(uuid)) { + if (message.getUuid().equals(uuid) + || (message.getStatus() >= Message.STATUS_SEND && uuid + .equals(message.getRemoteMsgId()))) { markMessage(message, status); return true; } @@ -1758,7 +1760,7 @@ public class XmppConnectionService extends Service { } return contacts; } - + public NotificationService getNotificationService() { return this.mNotificationService; } -- cgit v1.2.3 From cc76e15b95af16a2030b02b9a5035126d3ba18da Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 2 Oct 2014 18:54:21 +0200 Subject: avoided unecessary message searchs --- .../services/XmppConnectionService.java | 32 ++++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index ffef19ed1..ea2b59038 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -1533,26 +1533,34 @@ public class XmppConnectionService extends Service { public boolean markMessage(Account account, String recipient, String uuid, int status) { - for (Conversation conversation : getConversations()) { - if (conversation.getContactJid().equals(recipient) - && conversation.getAccount().equals(account)) { - return markMessage(conversation, uuid, status); + if (uuid == null) { + return false; + } else { + for (Conversation conversation : getConversations()) { + if (conversation.getContactJid().equals(recipient) + && conversation.getAccount().equals(account)) { + return markMessage(conversation, uuid, status); + } } + return false; } - return false; } public boolean markMessage(Conversation conversation, String uuid, int status) { - for (Message message : conversation.getMessages()) { - if (message.getUuid().equals(uuid) - || (message.getStatus() >= Message.STATUS_SEND && uuid - .equals(message.getRemoteMsgId()))) { - markMessage(message, status); - return true; + if (uuid == null) { + return false; + } else { + for (Message message : conversation.getMessages()) { + if (uuid.equals(message.getUuid()) + || (message.getStatus() >= Message.STATUS_SEND && uuid + .equals(message.getRemoteMsgId()))) { + markMessage(message, status); + return true; + } } + return false; } - return false; } public void markMessage(Message message, int status) { -- cgit v1.2.3 From f671938e842ece605f600860107ec9d2b8bfd019 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 2 Oct 2014 21:07:11 +0200 Subject: mark conversation as read when displayed marker from another client is received --- src/eu/siacs/conversations/services/XmppConnectionService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index ea2b59038..557a625b0 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -1631,16 +1631,19 @@ public class XmppConnectionService extends Service { return null; } - public void markRead(Conversation conversation) { + public void markRead(Conversation conversation, boolean calledByUi) { conversation.markRead(); mNotificationService.clear(conversation); String id = conversation.popLatestMarkableMessageId(); - if (confirmMessages() && id != null) { + if (confirmMessages() && id != null && calledByUi) { Account account = conversation.getAccount(); String to = conversation.getContactJid(); this.sendMessagePacket(conversation.getAccount(), mMessageGenerator.confirm(account, to, id)); } + if (!calledByUi) { + updateConversationUi(); + } } public void failWaitingOtrMessages(Conversation conversation) { -- cgit v1.2.3 From facd15f0373913eaafe8aa3a9a65cd02d8269aba Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 2 Oct 2014 22:17:25 +0200 Subject: check if display is off for notifications --- src/eu/siacs/conversations/services/NotificationService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java index 012bac302..eb2039091 100644 --- a/src/eu/siacs/conversations/services/NotificationService.java +++ b/src/eu/siacs/conversations/services/NotificationService.java @@ -12,6 +12,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; +import android.os.PowerManager; import android.support.v4.app.NotificationCompat; import android.support.v4.app.TaskStackBuilder; import android.text.Html; @@ -39,7 +40,12 @@ public class NotificationService { } public synchronized void push(Message message) { - if (this.mIsInForeground + + PowerManager pm = (PowerManager) mXmppConnectionService + .getSystemService(Context.POWER_SERVICE); + boolean isScreenOn = pm.isScreenOn(); + + if (this.mIsInForeground && isScreenOn && this.mOpenConversation == message.getConversation()) { return; // simply ignore } @@ -51,7 +57,7 @@ public class NotificationService { mList.add(message); notifications.put(conversationUuid, mList); } - updateNotification(!(this.mIsInForeground && this.mOpenConversation == null)); + updateNotification(!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn); } public void clear() { -- cgit v1.2.3 From 0e56ff93e9df5ef80e1f2841fb5b9dca3161cd43 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Fri, 3 Oct 2014 11:55:38 +0200 Subject: fixed possible npe --- src/eu/siacs/conversations/services/NotificationService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java index eb2039091..9428aa15a 100644 --- a/src/eu/siacs/conversations/services/NotificationService.java +++ b/src/eu/siacs/conversations/services/NotificationService.java @@ -57,7 +57,8 @@ public class NotificationService { mList.add(message); notifications.put(conversationUuid, mList); } - updateNotification(!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn); + updateNotification(!(this.mIsInForeground && this.mOpenConversation == null) + || !isScreenOn); } public void clear() { @@ -195,6 +196,9 @@ public class NotificationService { public static boolean wasHighlightedOrPrivate(Message message) { String nick = message.getConversation().getMucOptions().getActualNick(); Pattern highlight = generateNickHighlightPattern(nick); + if (message.getBody() == null || nick == null) { + return false; + } Matcher m = highlight.matcher(message.getBody()); return (m.find() || message.getType() == Message.TYPE_PRIVATE); } -- cgit v1.2.3 From b788b84c31bc53feb659e1af4dcaad98396c2de7 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Mon, 6 Oct 2014 00:33:52 +0200 Subject: refactored muc bookmark to extend element. keep all elements the server or other clients added before --- src/eu/siacs/conversations/services/XmppConnectionService.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 557a625b0..073bcdc50 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -748,7 +748,7 @@ public class XmppConnectionService extends Service { Element query = iqPacket.query("jabber:iq:private"); Element storage = query.addChild("storage", "storage:bookmarks"); for (Bookmark bookmark : account.getBookmarks()) { - storage.addChild(bookmark.toElement()); + storage.addChild(bookmark); } sendIqPacket(account, iqPacket, null); } @@ -1120,11 +1120,8 @@ public class XmppConnectionService extends Service { public void providePasswordForMuc(Conversation conversation, String password) { if (conversation.getMode() == Conversation.MODE_MULTI) { conversation.getMucOptions().setPassword(password); - if (conversation.getBookmark() != null - && conversation.getMucOptions().isPasswordChanged()) { - if (!conversation.getBookmark().autojoin()) { - conversation.getBookmark().setAutojoin(true); - } + if (conversation.getBookmark() != null) { + conversation.getBookmark().setAutojoin(true); pushBookmarks(conversation.getAccount()); } databaseBackend.updateConversation(conversation); -- cgit v1.2.3 From d5227e5c253658eb9d6bc1f7bf85397f072125d4 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Tue, 7 Oct 2014 13:37:50 +0200 Subject: refactored grace period --- .../services/NotificationService.java | 27 ++++++++++++++++++---- .../services/XmppConnectionService.java | 3 +++ 2 files changed, 25 insertions(+), 5 deletions(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java index 9428aa15a..53c4707f5 100644 --- a/src/eu/siacs/conversations/services/NotificationService.java +++ b/src/eu/siacs/conversations/services/NotificationService.java @@ -13,10 +13,12 @@ import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.PowerManager; +import android.os.SystemClock; import android.support.v4.app.NotificationCompat; import android.support.v4.app.TaskStackBuilder; import android.text.Html; +import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Message; @@ -32,6 +34,8 @@ public class NotificationService { public int NOTIFICATION_ID = 0x2342; private Conversation mOpenConversation; private boolean mIsInForeground; + + private long mEndGracePeriod = 0L; public NotificationService(XmppConnectionService service) { this.mXmppConnectionService = service; @@ -44,10 +48,9 @@ public class NotificationService { PowerManager pm = (PowerManager) mXmppConnectionService .getSystemService(Context.POWER_SERVICE); boolean isScreenOn = pm.isScreenOn(); - if (this.mIsInForeground && isScreenOn && this.mOpenConversation == message.getConversation()) { - return; // simply ignore + return; } String conversationUuid = message.getConversationUuid(); if (notifications.containsKey(conversationUuid)) { @@ -57,8 +60,8 @@ public class NotificationService { mList.add(message); notifications.put(conversationUuid, mList); } - updateNotification(!(this.mIsInForeground && this.mOpenConversation == null) - || !isScreenOn); + updateNotification((!(this.mIsInForeground && this.mOpenConversation == null) + || !isScreenOn) && !inGracePeriod()); } public void clear() { @@ -161,7 +164,9 @@ public class NotificationService { } } mBuilder.setDeleteIntent(createDeleteIntent()); - mBuilder.setLights(0xffffffff, 2000, 4000); + if (!inGracePeriod()) { + mBuilder.setLights(0xffffffff, 2000, 4000); + } Notification notification = mBuilder.build(); mNotificationManager.notify(NOTIFICATION_ID, notification); } @@ -221,4 +226,16 @@ public class NotificationService { this.mIsInForeground = foreground; } + + public void activateGracePeriod() { + this.mEndGracePeriod = SystemClock.elapsedRealtime() + (Config.CARBON_GRACE_PERIOD * 1000); + } + + public void deactivateGracePeriod() { + this.mEndGracePeriod = 0L; + } + + private boolean inGracePeriod() { + return SystemClock.elapsedRealtime() < this.mEndGracePeriod; + } } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 073bcdc50..ca69b5309 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -970,6 +970,7 @@ public class XmppConnectionService extends Service { public void setOnConversationListChangedListener( OnConversationUpdate listener) { + this.mNotificationService.deactivateGracePeriod(); if (checkListeners()) { switchToForeground(); } @@ -990,6 +991,7 @@ public class XmppConnectionService extends Service { } public void setOnAccountListChangedListener(OnAccountUpdate listener) { + this.mNotificationService.deactivateGracePeriod(); if (checkListeners()) { switchToForeground(); } @@ -1008,6 +1010,7 @@ public class XmppConnectionService extends Service { } public void setOnRosterUpdateListener(OnRosterUpdate listener) { + this.mNotificationService.deactivateGracePeriod(); if (checkListeners()) { switchToForeground(); } -- cgit v1.2.3 From 919c98207bb317e2283084dcbaa34a5216997d85 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Tue, 7 Oct 2014 15:18:09 +0200 Subject: made disabled notifications permanent across restarts --- .../siacs/conversations/services/NotificationService.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/NotificationService.java b/src/eu/siacs/conversations/services/NotificationService.java index 53c4707f5..416567071 100644 --- a/src/eu/siacs/conversations/services/NotificationService.java +++ b/src/eu/siacs/conversations/services/NotificationService.java @@ -34,7 +34,7 @@ public class NotificationService { public int NOTIFICATION_ID = 0x2342; private Conversation mOpenConversation; private boolean mIsInForeground; - + private long mEndGracePeriod = 0L; public NotificationService(XmppConnectionService service) { @@ -60,8 +60,8 @@ public class NotificationService { mList.add(message); notifications.put(conversationUuid, mList); } - updateNotification((!(this.mIsInForeground && this.mOpenConversation == null) - || !isScreenOn) && !inGracePeriod()); + updateNotification((!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn) + && !inGracePeriod()); } public void clear() { @@ -226,15 +226,15 @@ public class NotificationService { this.mIsInForeground = foreground; } - public void activateGracePeriod() { - this.mEndGracePeriod = SystemClock.elapsedRealtime() + (Config.CARBON_GRACE_PERIOD * 1000); + this.mEndGracePeriod = SystemClock.elapsedRealtime() + + (Config.CARBON_GRACE_PERIOD * 1000); } - + public void deactivateGracePeriod() { this.mEndGracePeriod = 0L; } - + private boolean inGracePeriod() { return SystemClock.elapsedRealtime() < this.mEndGracePeriod; } -- cgit v1.2.3 From 3737a96dbb517dc9d1e39d2b15cf8539cc752a45 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Tue, 7 Oct 2014 16:02:52 +0200 Subject: refactored read marker --- src/eu/siacs/conversations/services/XmppConnectionService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index ca69b5309..6aac3f934 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -1632,10 +1632,11 @@ public class XmppConnectionService extends Service { } public void markRead(Conversation conversation, boolean calledByUi) { - conversation.markRead(); mNotificationService.clear(conversation); - String id = conversation.popLatestMarkableMessageId(); + String id = conversation.getLatestMarkableMessageId(); + conversation.markRead(); if (confirmMessages() && id != null && calledByUi) { + Log.d(Config.LOGTAG,conversation.getAccount().getJid()+": sending read marker for "+conversation.getName()); Account account = conversation.getAccount(); String to = conversation.getContactJid(); this.sendMessagePacket(conversation.getAccount(), -- cgit v1.2.3 From 3d88ffc5cd4b9e500048557f9ce5f01653123526 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 8 Oct 2014 12:21:58 +0200 Subject: fixed possible logout bugs --- src/eu/siacs/conversations/services/XmppConnectionService.java | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 6aac3f934..e2c17b7e1 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -1508,6 +1508,9 @@ public class XmppConnectionService extends Service { thread.start(); scheduleWakeupCall((int) (Config.CONNECT_TIMEOUT * 1.2), false); + } else { + account.getRoster().clearPresences(); + account.setXmppConnection(null); } } }).start(); -- cgit v1.2.3 From 10411944b1bd18c0b5d7b1353f4c55eb0ec4aff6 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 8 Oct 2014 14:10:37 +0200 Subject: bullet proofing some code --- .../services/XmppConnectionService.java | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index e2c17b7e1..5aca9ce32 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -908,10 +908,12 @@ public class XmppConnectionService extends Service { public void archiveConversation(Conversation conversation) { if (conversation.getMode() == Conversation.MODE_MULTI) { - Bookmark bookmark = conversation.getBookmark(); - if (bookmark != null && bookmark.autojoin()) { - bookmark.setAutojoin(false); - pushBookmarks(bookmark.getAccount()); + if (conversation.getAccount().getStatus() == Account.STATUS_ONLINE) { + Bookmark bookmark = conversation.getBookmark(); + if (bookmark != null && bookmark.autojoin()) { + bookmark.setAutojoin(false); + pushBookmarks(bookmark.getAccount()); + } } leaveMuc(conversation); } else { @@ -1639,7 +1641,8 @@ public class XmppConnectionService extends Service { String id = conversation.getLatestMarkableMessageId(); conversation.markRead(); if (confirmMessages() && id != null && calledByUi) { - Log.d(Config.LOGTAG,conversation.getAccount().getJid()+": sending read marker for "+conversation.getName()); + Log.d(Config.LOGTAG, conversation.getAccount().getJid() + + ": sending read marker for " + conversation.getName()); Account account = conversation.getAccount(); String to = conversation.getContactJid(); this.sendMessagePacket(conversation.getAccount(), @@ -1722,16 +1725,25 @@ public class XmppConnectionService extends Service { } public void sendMessagePacket(Account account, MessagePacket packet) { - account.getXmppConnection().sendMessagePacket(packet); + XmppConnection connection = account.getXmppConnection(); + if (connection != null) { + connection.sendMessagePacket(packet); + } } public void sendPresencePacket(Account account, PresencePacket packet) { - account.getXmppConnection().sendPresencePacket(packet); + XmppConnection connection = account.getXmppConnection(); + if (connection != null) { + connection.sendPresencePacket(packet); + } } public void sendIqPacket(Account account, IqPacket packet, OnIqPacketReceived callback) { - account.getXmppConnection().sendIqPacket(packet, callback); + XmppConnection connection = account.getXmppConnection(); + if (connection != null) { + connection.sendIqPacket(packet, callback); + } } public MessageGenerator getMessageGenerator() { -- cgit v1.2.3 From c6f9b23def1684acd754e3db6712a7a5efbd5b42 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Thu, 9 Oct 2014 23:08:40 +0200 Subject: fixed npes --- .../siacs/conversations/services/XmppConnectionService.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/eu/siacs/conversations/services') diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 5aca9ce32..e6297f4ff 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -517,7 +517,8 @@ public class XmppConnectionService extends Service { MessagePacket packet = null; boolean saveInDb = true; boolean send = false; - if (account.getStatus() == Account.STATUS_ONLINE) { + if (account.getStatus() == Account.STATUS_ONLINE + && account.getXmppConnection() != null) { if (message.getType() == Message.TYPE_IMAGE) { if (message.getPresence() != null) { if (message.getEncryption() == Message.ENCRYPTION_OTR) { @@ -567,6 +568,10 @@ public class XmppConnectionService extends Service { send = true; } } + if (!account.getXmppConnection().getFeatures().sm() + && conv.getMode() != Conversation.MODE_MULTI) { + message.setStatus(Message.STATUS_SEND); + } } else { message.setStatus(Message.STATUS_WAITING); if (message.getType() == Message.TYPE_TEXT) { @@ -592,10 +597,6 @@ public class XmppConnectionService extends Service { } conv.getMessages().add(message); - if (!account.getXmppConnection().getFeatures().sm() - && conv.getMode() != Conversation.MODE_MULTI) { - message.setStatus(Message.STATUS_SEND); - } if (saveInDb) { if (message.getEncryption() == Message.ENCRYPTION_NONE || saveEncryptedMessages()) { -- cgit v1.2.3