refactored read marker
This commit is contained in:
parent
919c98207b
commit
3737a96dbb
|
@ -68,7 +68,7 @@ public class Conversation extends AbstractEntity {
|
|||
|
||||
private transient MucOptions mucOptions = null;
|
||||
|
||||
private transient String latestMarkableMessageId;
|
||||
//private transient String latestMarkableMessageId;
|
||||
|
||||
private byte[] symmetricKey;
|
||||
|
||||
|
@ -138,10 +138,17 @@ public class Conversation extends AbstractEntity {
|
|||
}
|
||||
}
|
||||
|
||||
public String popLatestMarkableMessageId() {
|
||||
String id = this.latestMarkableMessageId;
|
||||
this.latestMarkableMessageId = null;
|
||||
return id;
|
||||
public String getLatestMarkableMessageId() {
|
||||
for(int i = this.messages.size() - 1; i >= 0; --i) {
|
||||
if (this.messages.get(i).getStatus() <= Message.STATUS_RECEIVED && this.messages.get(i).markable) {
|
||||
if (this.messages.get(i).isRead()) {
|
||||
return null;
|
||||
} else {
|
||||
return this.messages.get(i).getRemoteMsgId();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Message getLatestMessage() {
|
||||
|
@ -405,12 +412,6 @@ public class Conversation extends AbstractEntity {
|
|||
this.nextMessage = message;
|
||||
}
|
||||
|
||||
public void setLatestMarkableMessageId(String id) {
|
||||
if (id != null) {
|
||||
this.latestMarkableMessageId = id;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSymmetricKey(byte[] key) {
|
||||
this.symmetricKey = key;
|
||||
}
|
||||
|
|
|
@ -57,9 +57,9 @@ public class Message extends AbstractEntity {
|
|||
protected boolean read = true;
|
||||
protected String remoteMsgId = null;
|
||||
|
||||
protected transient Conversation conversation = null;
|
||||
|
||||
protected transient Downloadable downloadable = null;
|
||||
protected Conversation conversation = null;
|
||||
protected Downloadable downloadable = null;
|
||||
public boolean markable = false;
|
||||
|
||||
private Message() {
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ public class MessageParser extends AbstractParser implements
|
|||
String[] fromParts = packet.getFrom().split("/", 2);
|
||||
Conversation conversation = mXmppConnectionService
|
||||
.findOrCreateConversation(account, fromParts[0], false);
|
||||
conversation.setLatestMarkableMessageId(getMarkableMessageId(packet));
|
||||
updateLastseen(packet, account, true);
|
||||
String pgpBody = getPgpBody(packet);
|
||||
Message finishedMessage;
|
||||
|
@ -37,6 +36,7 @@ public class MessageParser extends AbstractParser implements
|
|||
Message.STATUS_RECEIVED);
|
||||
}
|
||||
finishedMessage.setRemoteMsgId(packet.getId());
|
||||
finishedMessage.markable = isMarkable(packet);
|
||||
if (conversation.getMode() == Conversation.MODE_MULTI
|
||||
&& fromParts.length >= 2) {
|
||||
finishedMessage.setType(Message.TYPE_PRIVATE);
|
||||
|
@ -108,13 +108,12 @@ public class MessageParser extends AbstractParser implements
|
|||
conversation.setSymmetricKey(CryptoHelper.hexToBytes(key));
|
||||
return null;
|
||||
}
|
||||
conversation
|
||||
.setLatestMarkableMessageId(getMarkableMessageId(packet));
|
||||
Message finishedMessage = new Message(conversation,
|
||||
packet.getFrom(), body, Message.ENCRYPTION_OTR,
|
||||
Message.STATUS_RECEIVED);
|
||||
finishedMessage.setTime(getTimestamp(packet));
|
||||
finishedMessage.setRemoteMsgId(packet.getId());
|
||||
finishedMessage.markable = isMarkable(packet);
|
||||
return finishedMessage;
|
||||
} catch (Exception e) {
|
||||
String receivedId = packet.getId();
|
||||
|
@ -156,7 +155,6 @@ public class MessageParser extends AbstractParser implements
|
|||
status = Message.STATUS_RECEIVED;
|
||||
}
|
||||
String pgpBody = getPgpBody(packet);
|
||||
conversation.setLatestMarkableMessageId(getMarkableMessageId(packet));
|
||||
Message finishedMessage;
|
||||
if (pgpBody == null) {
|
||||
finishedMessage = new Message(conversation, counterPart,
|
||||
|
@ -166,6 +164,7 @@ public class MessageParser extends AbstractParser implements
|
|||
Message.ENCRYPTION_PGP, status);
|
||||
}
|
||||
finishedMessage.setRemoteMsgId(packet.getId());
|
||||
finishedMessage.markable = isMarkable(packet);
|
||||
if (status == Message.STATUS_RECEIVED) {
|
||||
finishedMessage.setTrueCounterpart(conversation.getMucOptions()
|
||||
.getTrueCounterpart(counterPart));
|
||||
|
@ -234,8 +233,6 @@ public class MessageParser extends AbstractParser implements
|
|||
String[] parts = fullJid.split("/", 2);
|
||||
Conversation conversation = mXmppConnectionService
|
||||
.findOrCreateConversation(account, parts[0], false);
|
||||
conversation.setLatestMarkableMessageId(getMarkableMessageId(packet));
|
||||
|
||||
String pgpBody = getPgpBody(message);
|
||||
Message finishedMessage;
|
||||
if (pgpBody != null) {
|
||||
|
@ -248,6 +245,7 @@ public class MessageParser extends AbstractParser implements
|
|||
}
|
||||
finishedMessage.setTime(getTimestamp(message));
|
||||
finishedMessage.setRemoteMsgId(message.getAttribute("id"));
|
||||
finishedMessage.markable = isMarkable(message);
|
||||
if (conversation.getMode() == Conversation.MODE_MULTI
|
||||
&& parts.length >= 2) {
|
||||
finishedMessage.setType(Message.TYPE_PRIVATE);
|
||||
|
@ -385,12 +383,8 @@ public class MessageParser extends AbstractParser implements
|
|||
}
|
||||
}
|
||||
|
||||
private String getMarkableMessageId(Element message) {
|
||||
if (message.hasChild("markable", "urn:xmpp:chat-markers:0")) {
|
||||
return message.getAttribute("id");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
private boolean isMarkable(Element message) {
|
||||
return message.hasChild("markable", "urn:xmpp:chat-markers:0");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue