code cleanup

This commit is contained in:
Daniel Gultsch 2015-01-03 00:47:22 +01:00
parent 969044b113
commit 8bda54d48c
3 changed files with 22 additions and 11 deletions

View file

@ -76,6 +76,16 @@ public class Conversation extends AbstractEntity implements Blockable {
private Bookmark bookmark; private Bookmark bookmark;
private boolean messagesLeftOnServer = true;
public boolean hasMessagesLeftOnServer() {
return messagesLeftOnServer;
}
public void setHasMessagesLeftOnServer(boolean value) {
this.messagesLeftOnServer = value;
}
public Message findUnsentMessageWithUuid(String uuid) { public Message findUnsentMessageWithUuid(String uuid) {
synchronized(this.messages) { synchronized(this.messages) {
for (final Message message : this.messages) { for (final Message message : this.messages) {
@ -227,13 +237,10 @@ public class Conversation extends AbstractEntity implements Blockable {
} }
public boolean isRead() { public boolean isRead() {
return (this.messages == null) || (this.messages.size() == 0) || this.messages.get(this.messages.size() - 1).isRead(); return (this.messages.size() == 0) || this.messages.get(this.messages.size() - 1).isRead();
} }
public void markRead() { public void markRead() {
if (this.messages == null) {
return;
}
for (int i = this.messages.size() - 1; i >= 0; --i) { for (int i = this.messages.size() - 1; i >= 0; --i) {
if (messages.get(i).isRead()) { if (messages.get(i).isRead()) {
break; break;
@ -243,9 +250,6 @@ public class Conversation extends AbstractEntity implements Blockable {
} }
public Message getLatestMarkableMessage() { public Message getLatestMarkableMessage() {
if (this.messages == null) {
return null;
}
for (int i = this.messages.size() - 1; i >= 0; --i) { for (int i = this.messages.size() - 1; i >= 0; --i) {
if (this.messages.get(i).getStatus() <= Message.STATUS_RECEIVED if (this.messages.get(i).getStatus() <= Message.STATUS_RECEIVED
&& this.messages.get(i).markable) { && this.messages.get(i).markable) {
@ -260,7 +264,7 @@ public class Conversation extends AbstractEntity implements Blockable {
} }
public Message getLatestMessage() { public Message getLatestMessage() {
if ((this.messages == null) || (this.messages.size() == 0)) { if (this.messages.size() == 0) {
Message message = new Message(this, "", Message.ENCRYPTION_NONE); Message message = new Message(this, "", Message.ENCRYPTION_NONE);
message.setTime(getCreated()); message.setTime(getCreated());
return message; return message;

View file

@ -24,7 +24,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
private final XmppConnectionService mXmppConnectionService; private final XmppConnectionService mXmppConnectionService;
private final HashSet<Query> queries = new HashSet<Query>(); private final HashSet<Query> queries = new HashSet<Query>();
private ArrayList<Query> pendingQueries = new ArrayList<Query>(); private final ArrayList<Query> pendingQueries = new ArrayList<Query>();
public enum PagingOrder { public enum PagingOrder {
NORMAL, NORMAL,
@ -134,6 +134,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
if (conversation.setLastMessageTransmitted(query.getEnd())) { if (conversation.setLastMessageTransmitted(query.getEnd())) {
this.mXmppConnectionService.databaseBackend.updateConversation(conversation); this.mXmppConnectionService.databaseBackend.updateConversation(conversation);
} }
conversation.setHasMessagesLeftOnServer(query.getMessageCount() > 0);
if (query.hasCallback()) { if (query.hasCallback()) {
query.callback(); query.callback();
} else { } else {
@ -300,7 +301,7 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
public void callback() { public void callback() {
if (this.callback != null) { if (this.callback != null) {
this.callback.onMoreMessagesLoaded(messageCount,conversation); this.callback.onMoreMessagesLoaded(messageCount,conversation);
if (messageCount==0) { if (messageCount == 0) {
this.callback.informUser(R.string.no_more_history_on_server); this.callback.informUser(R.string.no_more_history_on_server);
} }
} }
@ -330,6 +331,10 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
return this.totalCount; return this.totalCount;
} }
public int getMessageCount() {
return this.messageCount;
}
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();

View file

@ -971,7 +971,9 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
if (messages.size() > 0) { if (messages.size() > 0) {
conversation.addAll(0, messages); conversation.addAll(0, messages);
callback.onMoreMessagesLoaded(messages.size(), conversation); callback.onMoreMessagesLoaded(messages.size(), conversation);
} else if (account.getStatus() == Account.State.ONLINE && account.getXmppConnection() != null && account.getXmppConnection().getFeatures().mam()) { } else if (conversation.hasMessagesLeftOnServer()
&& account.isOnlineAndConnected()
&& account.getXmppConnection().getFeatures().mam()) {
MessageArchiveService.Query query = getMessageArchiveService().query(conversation,0,timestamp - 1); MessageArchiveService.Query query = getMessageArchiveService().query(conversation,0,timestamp - 1);
if (query != null) { if (query != null) {
query.setCallback(callback); query.setCallback(callback);