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