aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/services
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2015-10-14 21:18:34 +0200
committerDaniel Gultsch <daniel@gultsch.de>2015-10-14 21:18:34 +0200
commit5f9476448f54113e27f04f38fd64959b13bcd97b (patch)
tree2b7d18f053f7164ca700e80037bcba2cac3d9247 /src/main/java/eu/siacs/conversations/services
parent0587ba2ad274907ecc35f7fb38cc9e919af93d2a (diff)
make unread status and notifications presistent across restarts
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/services/NotificationService.java42
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java13
2 files changed, 38 insertions, 17 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java
index 3ed155a8..e9095020 100644
--- a/src/main/java/eu/siacs/conversations/services/NotificationService.java
+++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java
@@ -1,6 +1,5 @@
package eu.siacs.conversations.services;
-import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -10,7 +9,6 @@ import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
-import android.os.PowerManager;
import android.os.SystemClock;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.BigPictureStyle;
@@ -115,31 +113,45 @@ public class NotificationService {
return mXmppConnectionService.getPreferences().getBoolean("always_notify_in_conference", false);
}
+ public void pushFromBacklog(final Message message) {
+ if (notify(message)) {
+ pushToStack(message);
+ }
+ }
+
+ public void finishBacklog() {
+ synchronized (notifications) {
+ mXmppConnectionService.updateUnreadCountBadge();
+ updateNotification(false);
+ }
+ }
+
+ private void pushToStack(final Message message) {
+ final String conversationUuid = message.getConversationUuid();
+ if (notifications.containsKey(conversationUuid)) {
+ notifications.get(conversationUuid).add(message);
+ } else {
+ final ArrayList<Message> mList = new ArrayList<>();
+ mList.add(message);
+ notifications.put(conversationUuid, mList);
+ }
+ }
+
public void push(final Message message) {
mXmppConnectionService.updateUnreadCountBadge();
if (!notify(message)) {
return;
}
-
final boolean isScreenOn = mXmppConnectionService.isInteractive();
-
if (this.mIsInForeground && isScreenOn && this.mOpenConversation == message.getConversation()) {
return;
}
-
synchronized (notifications) {
- final String conversationUuid = message.getConversationUuid();
- if (notifications.containsKey(conversationUuid)) {
- notifications.get(conversationUuid).add(message);
- } else {
- final ArrayList<Message> mList = new ArrayList<>();
- mList.add(message);
- notifications.put(conversationUuid, mList);
- }
+ pushToStack(message);
final Account account = message.getConversation().getAccount();
final boolean doNotify = (!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn)
- && !account.inGracePeriod()
- && !this.inMiniGracePeriod(account);
+ && !account.inGracePeriod()
+ && !this.inMiniGracePeriod(account);
updateNotification(doNotify);
if (doNotify) {
notifyPebble(message);
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 7a39bd06..cfd3ba6e 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -1072,7 +1072,14 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
for (Conversation conversation : conversations) {
conversation.addAll(0, databaseBackend.getMessages(conversation, Config.PAGE_SIZE));
checkDeletedFiles(conversation);
+ conversation.findUnreadMessages(new Conversation.OnMessageFound() {
+ @Override
+ public void onMessageFound(Message message) {
+ mNotificationService.pushFromBacklog(message);
+ }
+ });
}
+ mNotificationService.finishBacklog();
mRestoredFromDatabase = true;
Log.d(Config.LOGTAG,"restored all messages");
updateConversationUi();
@@ -1330,7 +1337,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void updateKeyInAccount(final Account account, final String alias) {
- Log.d(Config.LOGTAG,"update key in account "+alias);
+ Log.d(Config.LOGTAG, "update key in account " + alias);
try {
X509Certificate[] chain = KeyChain.getCertificateChain(XmppConnectionService.this, alias);
Pair<Jid, String> info = CryptoHelper.extractJidAndName(chain[0]);
@@ -2566,7 +2573,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
public void markRead(final Conversation conversation) {
mNotificationService.clear(conversation);
- conversation.markRead();
+ for(Message message : conversation.markRead()) {
+ databaseBackend.updateMessage(message);
+ }
updateUnreadCountBadge();
}