Include source message in a forked-off thread "show only" view (Cheogram)

This commit is contained in:
Arne 2023-05-23 15:05:05 +02:00
parent dc69486522
commit 34bfce7b55
4 changed files with 37 additions and 34 deletions

View file

@ -729,39 +729,32 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
return reactionEmoji;
}
public long loadMoreTimestamp() {
if (messages.size() < 1) return 0;
if (getLockThread() && messages.size() > 5000) return 0;
if (messages.get(0).getType() == Message.TYPE_STATUS && messages.size() >= 2) {
return messages.get(1).getTimeSent();
} else {
return messages.get(0).getTimeSent();
}
}
public void populateWithMessages(final List<Message> messages) {
synchronized (this.messages) {
messages.clear();
messages.addAll(filterDuplicates(this.messages));
for (int n = 0; n < messages.size(); n++) {
if (messages.get(n).isMessageDeleted()) {
messages.remove(n);
n--;
continue;
}
if (messages.get(n).getRetractId() != null) {
if (messages.get(n).getStatus() != Message.STATUS_RECEIVED) {
messages.remove(n);
n--;
continue;
}
}
}
for (Message itm : messages) {
if (itm.isMessageDeleted()) {
if (itm.getEditedList().size() > 0) {
itm.setTime(itm.getEditedList().get(0).getTimeSent());
}
}
}
messages.addAll(this.messages);
}
for (Iterator<Message> iterator = messages.iterator(); iterator.hasNext(); ) {
Message m = iterator.next();
if (m.wasMergedIntoPrevious() || (getLockThread() && (m.getThread() == null || !m.getThread().getContent().equals(getThread().getContent())))) {
Set<String> extraIds = new HashSet<>();
for (ListIterator<Message> iterator = messages.listIterator(messages.size()); iterator.hasPrevious(); ) {
Message m = iterator.previous();
if (m.wasMergedIntoPrevious() || (getLockThread() && !extraIds.contains(m.replyId()) && (m.getThread() == null || !m.getThread().getContent().equals(getThread().getContent())))) {
iterator.remove();
} else if (getLockThread() && m.getThread() != null) {
Element reply = m.getReply();
if (reply != null && reply.getAttribute("id") != null) extraIds.add(reply.getAttribute("id"));
Element reactions = m.getReactions();
if (reactions != null && reactions.getAttribute("id") != null) extraIds.add(reactions.getAttribute("id"));
}
}
}

View file

@ -514,6 +514,18 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
return this.body;
}
public Element getReply() {
if (this.payloads == null) return null;
for (Element el : this.payloads) {
if (el.getName().equals("reply") && el.getNamespace().equals("urn:xmpp:reply:0")) {
return el;
}
}
return null;
}
public String getConversationUuid() {
return conversationUuid;
}

View file

@ -775,6 +775,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
el.setAttribute("xmlns", "jabber:client");
message.addPayload(el);
}
if (el.getName().equals("reply") && el.getNamespace() != null && el.getNamespace().equals("urn:xmpp:reply:0")) {
message.addPayload(el);
}
}
if (conversationMultiMode) {
message.setMucUser(conversation.getMucOptions().findUserByFullJid(counterpart));

View file

@ -417,12 +417,7 @@ public class ConversationFragment extends XmppFragment
toggleScrollDownButton(view);
synchronized (ConversationFragment.this.messageList) {
if (firstVisibleItem < 5 && conversation != null && conversation.messagesLoaded.compareAndSet(true, false) && messageList.size() > 0) {
long timestamp;
if (messageList.get(0).getType() == Message.TYPE_STATUS && messageList.size() >= 2) {
timestamp = messageList.get(1).getTimeSent();
} else {
timestamp = messageList.get(0).getTimeSent();
}
long timestamp = conversation.loadMoreTimestamp();
activity.xmppConnectionService.loadMoreMessages(conversation, timestamp, new XmppConnectionService.OnMoreMessagesLoaded() {
@Override
public void onMoreMessagesLoaded(final int c, final Conversation conversation) {