make chat markers opportunistic in private mucs

This commit is contained in:
Daniel Gultsch 2018-01-22 23:21:24 +01:00
parent e62b0ca320
commit eee5d885ba
7 changed files with 29 additions and 25 deletions

View file

@ -788,12 +788,11 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
} }
public boolean isConversationAxolotlCapable(Conversation conversation) { public boolean isConversationAxolotlCapable(Conversation conversation) {
return conversation.getMode() == Conversation.MODE_SINGLE || (conversation.getMucOptions().nonanonymous() && conversation.getMucOptions().membersOnly()); return conversation.isSingleOrPrivateAndNonAnonymous();
} }
public Pair<AxolotlCapability, Jid> isConversationAxolotlCapableDetailed(Conversation conversation) { public Pair<AxolotlCapability, Jid> isConversationAxolotlCapableDetailed(Conversation conversation) {
if (conversation.getMode() == Conversation.MODE_SINGLE if (conversation.isSingleOrPrivateAndNonAnonymous()) {
|| (conversation.getMucOptions().membersOnly() && conversation.getMucOptions().nonanonymous())) {
final List<Jid> jids = getCryptoTargets(conversation); final List<Jid> jids = getCryptoTargets(conversation);
for (Jid jid : jids) { for (Jid jid : jids) {
if (!hasAny(jid) && (!deviceIds.containsKey(jid) || deviceIds.get(jid).isEmpty())) { if (!hasAny(jid) && (!deviceIds.containsKey(jid) || deviceIds.get(jid).isEmpty())) {

View file

@ -194,15 +194,13 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
} }
public boolean setOutgoingChatState(ChatState state) { public boolean setOutgoingChatState(ChatState state) {
if (mode == MODE_MULTI && (getNextCounterpart() != null || !isPnNA())) { if (mode == MODE_SINGLE || (isPrivateAndNonAnonymous() && getNextCounterpart() == null)) {
return false; if (this.mOutgoingChatState != state) {
} this.mOutgoingChatState = state;
if (this.mOutgoingChatState != state) { return true;
this.mOutgoingChatState = state; }
return true;
} else {
return false;
} }
return false;
} }
public ChatState getOutgoingChatState() { public ChatState getOutgoingChatState() {
@ -466,12 +464,12 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
return unread; return unread;
} }
public Message getLatestMarkableMessage() { public Message getLatestMarkableMessage(boolean isPrivateAndNonAnonymousMuc) {
synchronized (this.messages) { synchronized (this.messages) {
for (int i = this.messages.size() - 1; i >= 0; --i) { for (int i = this.messages.size() - 1; i >= 0; --i) {
final Message message = this.messages.get(i); final Message message = this.messages.get(i);
if (message.getStatus() <= Message.STATUS_RECEIVED if (message.getStatus() <= Message.STATUS_RECEIVED
&& message.markable && (message.markable || isPrivateAndNonAnonymousMuc)
&& message.getType() != Message.TYPE_PRIVATE) { && message.getType() != Message.TYPE_PRIVATE) {
return message.isRead() ? null : message; return message.isRead() ? null : message;
} }
@ -697,8 +695,12 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
/** /**
* short for is Private and Non-anonymous * short for is Private and Non-anonymous
*/ */
private boolean isPnNA() { public boolean isSingleOrPrivateAndNonAnonymous() {
return mode == MODE_SINGLE || (getMucOptions().membersOnly() && getMucOptions().nonanonymous()); return mode == MODE_SINGLE || isPrivateAndNonAnonymous();
}
public boolean isPrivateAndNonAnonymous() {
return getMucOptions().isPrivateAndNonAnonymous();
} }
public synchronized MucOptions getMucOptions() { public synchronized MucOptions getMucOptions() {
@ -866,7 +868,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
} }
public boolean alwaysNotify() { public boolean alwaysNotify() {
return mode == MODE_SINGLE || getBooleanAttribute(ATTRIBUTE_ALWAYS_NOTIFY, Config.ALWAYS_NOTIFY_BY_DEFAULT || isPnNA()); return mode == MODE_SINGLE || getBooleanAttribute(ATTRIBUTE_ALWAYS_NOTIFY, Config.ALWAYS_NOTIFY_BY_DEFAULT || isPrivateAndNonAnonymous());
} }
public boolean setAttribute(String key, String value) { public boolean setAttribute(String key, String value) {

View file

@ -424,6 +424,10 @@ public class MucOptions {
return hasFeature("muc_nonanonymous"); return hasFeature("muc_nonanonymous");
} }
public boolean isPrivateAndNonAnonymous() {
return membersOnly() && nonanonymous();
}
public boolean persistent() { public boolean persistent() {
return hasFeature("muc_persistent"); return hasFeature("muc_persistent");
} }

View file

@ -53,8 +53,7 @@ public class MessageGenerator extends AbstractGenerator {
packet.setTo(message.getCounterpart().toBareJid()); packet.setTo(message.getCounterpart().toBareJid());
packet.setType(MessagePacket.TYPE_GROUPCHAT); packet.setType(MessagePacket.TYPE_GROUPCHAT);
} }
if (conversation.getMode() == Conversation.MODE_SINGLE || if (conversation.isSingleOrPrivateAndNonAnonymous() && message.getType() != Message.TYPE_PRIVATE) {
(conversation.getMucOptions().nonanonymous() && conversation.getMucOptions().membersOnly() && message.getType() != Message.TYPE_PRIVATE)) {
packet.addChild("markable", "urn:xmpp:chat-markers:0"); packet.addChild("markable", "urn:xmpp:chat-markers:0");
} }
packet.setFrom(account.getJid()); packet.setFrom(account.getJid());

View file

@ -78,7 +78,7 @@ public class PresenceParser extends AbstractParser implements
} }
boolean isNew = mucOptions.updateUser(user); boolean isNew = mucOptions.updateUser(user);
final AxolotlService axolotlService = conversation.getAccount().getAxolotlService(); final AxolotlService axolotlService = conversation.getAccount().getAxolotlService();
if (isNew && user.getRealJid() != null && mucOptions.membersOnly() && mucOptions.nonanonymous() && axolotlService.hasEmptyDeviceList(user.getRealJid())) { if (isNew && user.getRealJid() != null && mucOptions.isPrivateAndNonAnonymous() && axolotlService.hasEmptyDeviceList(user.getRealJid())) {
axolotlService.fetchDeviceIds(user.getRealJid()); axolotlService.fetchDeviceIds(user.getRealJid());
} }
if (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && mucOptions.autoPushConfiguration()) { if (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && mucOptions.autoPushConfiguration()) {

View file

@ -2271,7 +2271,7 @@ public class XmppConnectionService extends Service {
if (mucOptions.mamSupport()) { if (mucOptions.mamSupport()) {
getMessageArchiveService().catchupMUC(conversation); getMessageArchiveService().catchupMUC(conversation);
} }
if (mucOptions.membersOnly() && mucOptions.nonanonymous()) { if (mucOptions.isPrivateAndNonAnonymous()) {
fetchConferenceMembers(conversation); fetchConferenceMembers(conversation);
if (followedInvite && conversation.getBookmark() == null) { if (followedInvite && conversation.getBookmark() == null) {
saveConversationAsBookmark(conversation, null); saveConversationAsBookmark(conversation, null);
@ -3432,15 +3432,15 @@ public class XmppConnectionService extends Service {
} }
public void sendReadMarker(final Conversation conversation) { public void sendReadMarker(final Conversation conversation) {
final Message markable = conversation.getLatestMarkableMessage(); final boolean isPrivateAndNonAnonymousMuc = conversation.getMode() == Conversation.MODE_MULTI && conversation.isPrivateAndNonAnonymous();
final Message markable = conversation.getLatestMarkableMessage(isPrivateAndNonAnonymousMuc);
if (this.markRead(conversation)) { if (this.markRead(conversation)) {
updateConversationUi(); updateConversationUi();
} }
if (confirmMessages() if (confirmMessages()
&& markable != null && markable != null
&& markable.trusted() && (markable.trusted() || isPrivateAndNonAnonymousMuc)
&& markable.getRemoteMsgId() != null && markable.getRemoteMsgId() != null) {
&& markable.getType() != Message.TYPE_PRIVATE) {
Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": sending read marker to " + markable.getCounterpart().toString()); Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": sending read marker to " + markable.getCounterpart().toString());
Account account = conversation.getAccount(); Account account = conversation.getAccount();
final Jid to = markable.getCounterpart(); final Jid to = markable.getCounterpart();

View file

@ -1385,7 +1385,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
state = ChatState.PAUSED; state = ChatState.PAUSED;
users = conversation.getMucOptions().getUsersWithChatState(state, 5); users = conversation.getMucOptions().getUsersWithChatState(state, 5);
} }
if (mucOptions.membersOnly() && mucOptions.nonanonymous()) { if (mucOptions.isPrivateAndNonAnonymous()) {
for (int i = this.messageList.size() - 1; i >= 0; --i) { for (int i = this.messageList.size() - 1; i >= 0; --i) {
final Set<ReadByMarker> markersForMessage = messageList.get(i).getReadByMarkers(); final Set<ReadByMarker> markersForMessage = messageList.get(i).getReadByMarkers();
final List<MucOptions.User> shownMarkers = new ArrayList<>(); final List<MucOptions.User> shownMarkers = new ArrayList<>();