From 9a5a429888409fb4e52432e86f8dca49d4e97cdb Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 8 Mar 2014 05:59:31 +0100 Subject: step two towards nicer notifications. mark read if carbon arrives --- .../services/XmppConnectionService.java | 23 +++++++++++----------- src/eu/siacs/conversations/utils/UIHelper.java | 12 ++++++----- 2 files changed, 18 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index f2fc9c908..6495b4ab8 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -101,33 +101,37 @@ public class XmppConnectionService extends Service { public void onMessagePacketReceived(Account account, MessagePacket packet) { Message message = null; - boolean notify = false; + boolean notify = true; if ((packet.getType() == MessagePacket.TYPE_CHAT)) { String pgpBody = MessageParser.getPgpBody(packet); if (pgpBody != null) { message = MessageParser.parsePgpChat(pgpBody, packet, account, service); - notify = false; + message.markUnread(); } else if (packet.hasChild("body") && (packet.getBody().startsWith("?OTR"))) { message = MessageParser.parseOtrChat(packet, account, service); - notify = true; + message.markUnread(); } else if (packet.hasChild("body")) { message = MessageParser.parsePlainTextChat(packet, account, service); - notify = true; + message.markUnread(); } else if (packet.hasChild("received") || (packet.hasChild("sent"))) { message = MessageParser.parseCarbonMessage(packet, account, service); + message.getConversation().markRead(); + notify = false; } } else if (packet.getType() == MessagePacket.TYPE_GROUPCHAT) { message = MessageParser .parseGroupchat(packet, account, service); if (message != null) { - notify = (message.getStatus() == Message.STATUS_RECIEVED); + if (message.getStatus() == Message.STATUS_RECIEVED) { + message.markUnread(); + } } } else if (packet.getType() == MessagePacket.TYPE_ERROR) { message = MessageParser.parseError(packet, account, service); @@ -149,9 +153,6 @@ public class XmppConnectionService extends Service { Log.d(LOGTAG, "error trying to parse date" + e.getMessage()); } } - if (notify) { - message.markUnread(); - } Conversation conversation = message.getConversation(); conversation.getMessages().add(message); if (packet.getType() != MessagePacket.TYPE_ERROR) { @@ -160,12 +161,10 @@ public class XmppConnectionService extends Service { if (convChangedListener != null) { convChangedListener.onConversationListChanged(); } else { - if (notify) { NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(2342, UIHelper - .getUnreadMessageNotification( - getApplicationContext(),getConversations())); - } + .getNotification( + getApplicationContext(),getConversations(),notify)); } } }; diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java index fecfaa61b..7ae2b745e 100644 --- a/src/eu/siacs/conversations/utils/UIHelper.java +++ b/src/eu/siacs/conversations/utils/UIHelper.java @@ -107,8 +107,8 @@ public class UIHelper { return bitmap; } - public static Notification getUnreadMessageNotification(Context context, - List conversations) { + public static Notification getNotification(Context context, + List conversations, boolean notify) { String targetUuid = ""; List unread = new ArrayList(); @@ -169,9 +169,11 @@ public class UIHelper { mBuilder.setStyle(style); } mBuilder.setSmallIcon(R.drawable.notification); - mBuilder.setLights(0xffffffff, 2000, 4000); - if (ringtone != null) { - mBuilder.setSound(Uri.parse(ringtone)); + if (notify) { + mBuilder.setLights(0xffffffff, 2000, 4000); + if (ringtone != null) { + mBuilder.setSound(Uri.parse(ringtone)); + } } TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); -- cgit v1.2.3