added methods to count number of unread messages

This commit is contained in:
Daniel Gultsch 2015-03-02 11:53:15 +01:00
parent ff86fa6049
commit ac577fe4fd
2 changed files with 21 additions and 0 deletions

View file

@ -736,6 +736,19 @@ public class Conversation extends AbstractEntity implements Blockable {
} }
} }
public int unreadCount() {
synchronized (this.messages) {
int count = 0;
for(int i = this.messages.size() - 1; i >= 0; --i) {
if (this.messages.get(i).isRead()) {
return count;
}
++count;
}
return count;
}
}
public class Smp { public class Smp {
public static final int STATUS_NONE = 0; public static final int STATUS_NONE = 0;
public static final int STATUS_CONTACT_REQUESTED = 1; public static final int STATUS_CONTACT_REQUESTED = 1;

View file

@ -2080,6 +2080,14 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return getPreferences().getBoolean("indicate_received", false); return getPreferences().getBoolean("indicate_received", false);
} }
public int unreadCount() {
int count = 0;
for(Conversation conversation : getConversations()) {
count += conversation.unreadCount();
}
return count;
}
public void updateConversationUi() { public void updateConversationUi() {
if (mOnConversationUpdate != null) { if (mOnConversationUpdate != null) {
mOnConversationUpdate.onConversationUpdate(); mOnConversationUpdate.onConversationUpdate();