include occupant resource
This commit is contained in:
parent
405eeadd95
commit
f13f15cc91
|
@ -0,0 +1,24 @@
|
||||||
|
package im.conversations.android.database;
|
||||||
|
|
||||||
|
import im.conversations.android.database.model.ChatType;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import org.jxmpp.jid.BareJid;
|
||||||
|
|
||||||
|
public interface KnownSender {
|
||||||
|
|
||||||
|
default boolean isKnownSender() {
|
||||||
|
final var chatType = getChatType();
|
||||||
|
final var membersOnlyNonAnonymous = isMembersOnlyNonAnonymous();
|
||||||
|
final var sender = getSender();
|
||||||
|
return chatType == ChatType.INDIVIDUAL
|
||||||
|
|| (Arrays.asList(ChatType.MUC, ChatType.MUC_PM).contains(chatType)
|
||||||
|
&& membersOnlyNonAnonymous
|
||||||
|
&& sender != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatType getChatType();
|
||||||
|
|
||||||
|
boolean isMembersOnlyNonAnonymous();
|
||||||
|
|
||||||
|
BareJid getSender();
|
||||||
|
}
|
|
@ -193,10 +193,10 @@ public abstract class ChatDao {
|
||||||
protected abstract void deleteStatusCodes(final long chatId);
|
protected abstract void deleteStatusCodes(final long chatId);
|
||||||
|
|
||||||
// TODO select vCardPhoto for c.type='MUC_PM'
|
// TODO select vCardPhoto for c.type='MUC_PM'
|
||||||
// TODO select real name for `sender` in membersOnlyNonAnonymous MUCs
|
|
||||||
@Transaction
|
@Transaction
|
||||||
@Query(
|
@Query(
|
||||||
"SELECT c.id,c.accountId,c.address,c.type,m.sentAt,m.outgoing,m.latestVersion as"
|
"SELECT c.id,c.accountId,c.address,c.type,m.sentAt,m.senderIdentity as"
|
||||||
|
+ " sender,m.outgoing,m.latestVersion as"
|
||||||
+ " version,m.toBare,m.toResource,m.fromBare,m.fromResource,(SELECT count(id) FROM"
|
+ " version,m.toBare,m.toResource,m.fromBare,m.fromResource,(SELECT count(id) FROM"
|
||||||
+ " message WHERE chatId=c.id) as unread,(SELECT name FROM roster WHERE"
|
+ " message WHERE chatId=c.id) as unread,(SELECT name FROM roster WHERE"
|
||||||
+ " roster.accountId=c.accountId AND roster.address=c.address) as"
|
+ " roster.accountId=c.accountId AND roster.address=c.address) as"
|
||||||
|
@ -215,7 +215,10 @@ public abstract class ChatDao {
|
||||||
+ " c.type IN ('MUC','MUC_PM') THEN (SELECT count(distinct(df.feature)) == 2 FROM"
|
+ " c.type IN ('MUC','MUC_PM') THEN (SELECT count(distinct(df.feature)) == 2 FROM"
|
||||||
+ " disco_item di JOIN disco_feature df ON di.discoId = df.discoId WHERE"
|
+ " disco_item di JOIN disco_feature df ON di.discoId = df.discoId WHERE"
|
||||||
+ " di.address=c.address AND df.feature IN('muc_membersonly','muc_nonanonymous'))"
|
+ " di.address=c.address AND df.feature IN('muc_membersonly','muc_nonanonymous'))"
|
||||||
+ " ELSE 0 END) as membersOnlyNonAnonymous FROM CHAT c LEFT JOIN message m ON (m.id"
|
+ " ELSE 0 END) as membersOnlyNonAnonymous,(CASE WHEN m.occupantId IS NOT NULL AND"
|
||||||
|
+ " c.type IN ('MUC','MUC_PM') THEN (SELECT resource FROM presence WHERE"
|
||||||
|
+ " accountId=c.accountId AND address=c.address AND occupantId=m.occupantId LIMIT"
|
||||||
|
+ " 1) ELSE NULL END) as occupantResource FROM CHAT c LEFT JOIN message m ON (m.id"
|
||||||
+ " = (SELECT id FROM message WHERE chatId=c.id ORDER by receivedAt DESC LIMIT 1))"
|
+ " = (SELECT id FROM message WHERE chatId=c.id ORDER by receivedAt DESC LIMIT 1))"
|
||||||
+ " WHERE (:accountId IS NULL OR c.accountId=:accountId) AND (:groupId IS NULL OR"
|
+ " WHERE (:accountId IS NULL OR c.accountId=:accountId) AND (:groupId IS NULL OR"
|
||||||
+ " (c.address IN(SELECT roster.address FROM roster JOIN roster_group ON"
|
+ " (c.address IN(SELECT roster.address FROM roster JOIN roster_group ON"
|
||||||
|
|
|
@ -434,10 +434,13 @@ public abstract class MessageDao {
|
||||||
+ " address=m.senderIdentity AND vCardPhoto NOT NULL LIMIT 1) as"
|
+ " address=m.senderIdentity AND vCardPhoto NOT NULL LIMIT 1) as"
|
||||||
+ " senderVcardPhoto,(SELECT thumb_id FROM avatar WHERE"
|
+ " senderVcardPhoto,(SELECT thumb_id FROM avatar WHERE"
|
||||||
+ " avatar.accountId=c.accountId AND avatar.address=m.senderIdentity) as"
|
+ " avatar.accountId=c.accountId AND avatar.address=m.senderIdentity) as"
|
||||||
+ " senderAvatar,(CASE WHEN c.type IN ('MUC','MUC_PM') THEN (SELECT vCardPhoto FROM"
|
+ " senderAvatar,(CASE WHEN m.occupantId IS NOT NULL AND c.type IN ('MUC','MUC_PM')"
|
||||||
+ " presence WHERE accountId=c.accountId AND address=c.address AND"
|
+ " THEN (SELECT vCardPhoto FROM presence WHERE accountId=c.accountId AND"
|
||||||
+ " occupantId=m.occupantId AND vCardPhoto NOT NULL LIMIT 1) ELSE NULL END) as"
|
+ " address=c.address AND occupantId=m.occupantId AND vCardPhoto NOT NULL LIMIT 1)"
|
||||||
+ " occupantVcardPhoto,modification,latestVersion as"
|
+ " ELSE NULL END) as occupantVcardPhoto,(CASE WHEN m.occupantId IS NOT NULL AND"
|
||||||
|
+ " c.type IN ('MUC','MUC_PM') THEN (SELECT resource FROM presence WHERE"
|
||||||
|
+ " accountId=c.accountId AND address=c.address AND occupantId=m.occupantId LIMIT"
|
||||||
|
+ " 1) ELSE NULL END) as occupantResource,modification,latestVersion as"
|
||||||
+ " version,inReplyToMessageEntityId,encryption,message_version.identityKey,trust,(CASE"
|
+ " version,inReplyToMessageEntityId,encryption,message_version.identityKey,trust,(CASE"
|
||||||
+ " WHEN c.type IN ('MUC','MUC_PM') THEN (SELECT count(distinct(df.feature)) == 2"
|
+ " WHEN c.type IN ('MUC','MUC_PM') THEN (SELECT count(distinct(df.feature)) == 2"
|
||||||
+ " FROM disco_item di JOIN disco_feature df ON di.discoId = df.discoId WHERE"
|
+ " FROM disco_item di JOIN disco_feature df ON di.discoId = df.discoId WHERE"
|
||||||
|
@ -447,7 +450,7 @@ public abstract class MessageDao {
|
||||||
+ " JOIN axolotl_identity ON c.accountId=axolotl_identity.accountId AND"
|
+ " JOIN axolotl_identity ON c.accountId=axolotl_identity.accountId AND"
|
||||||
+ " m.senderIdentity=axolotl_identity.address AND"
|
+ " m.senderIdentity=axolotl_identity.address AND"
|
||||||
+ " message_version.identityKey=axolotl_identity.identityKey WHERE c.id=:chatId AND"
|
+ " message_version.identityKey=axolotl_identity.identityKey WHERE c.id=:chatId AND"
|
||||||
+ " latestVersion IS NOT NULL ORDER BY m.receivedAt DESC")
|
+ " latestVersion IS NOT NULL ORDER BY m.receivedAt")
|
||||||
public abstract List<MessageWithContentReactions> getMessagesForTesting(long chatId);
|
public abstract List<MessageWithContentReactions> getMessagesForTesting(long chatId);
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
|
@ -461,10 +464,13 @@ public abstract class MessageDao {
|
||||||
+ " address=m.senderIdentity AND vCardPhoto NOT NULL LIMIT 1) as"
|
+ " address=m.senderIdentity AND vCardPhoto NOT NULL LIMIT 1) as"
|
||||||
+ " senderVcardPhoto,(SELECT thumb_id FROM avatar WHERE"
|
+ " senderVcardPhoto,(SELECT thumb_id FROM avatar WHERE"
|
||||||
+ " avatar.accountId=c.accountId AND avatar.address=m.senderIdentity) as"
|
+ " avatar.accountId=c.accountId AND avatar.address=m.senderIdentity) as"
|
||||||
+ " senderAvatar,(CASE WHEN c.type IN ('MUC','MUC_PM') THEN (SELECT vCardPhoto FROM"
|
+ " senderAvatar,(CASE WHEN m.occupantId IS NOT NULL AND c.type IN ('MUC','MUC_PM')"
|
||||||
+ " presence WHERE accountId=c.accountId AND address=c.address AND"
|
+ " THEN (SELECT vCardPhoto FROM presence WHERE accountId=c.accountId AND"
|
||||||
+ " occupantId=m.occupantId AND vCardPhoto NOT NULL LIMIT 1) ELSE NULL END) as"
|
+ " address=c.address AND occupantId=m.occupantId AND vCardPhoto NOT NULL LIMIT 1)"
|
||||||
+ " occupantVcardPhoto,modification,latestVersion as"
|
+ " ELSE NULL END) as occupantVcardPhoto,(CASE WHEN m.occupantId IS NOT NULL AND"
|
||||||
|
+ " c.type IN ('MUC','MUC_PM') THEN (SELECT resource FROM presence WHERE"
|
||||||
|
+ " accountId=c.accountId AND address=c.address AND occupantId=m.occupantId LIMIT"
|
||||||
|
+ " 1) ELSE NULL END) as occupantResource,modification,latestVersion as"
|
||||||
+ " version,inReplyToMessageEntityId,encryption,message_version.identityKey,trust,(CASE"
|
+ " version,inReplyToMessageEntityId,encryption,message_version.identityKey,trust,(CASE"
|
||||||
+ " WHEN c.type IN ('MUC','MUC_PM') THEN (SELECT count(distinct(df.feature)) == 2"
|
+ " WHEN c.type IN ('MUC','MUC_PM') THEN (SELECT count(distinct(df.feature)) == 2"
|
||||||
+ " FROM disco_item di JOIN disco_feature df ON di.discoId = df.discoId WHERE"
|
+ " FROM disco_item di JOIN disco_feature df ON di.discoId = df.discoId WHERE"
|
||||||
|
|
|
@ -6,7 +6,9 @@ import com.google.common.collect.Iterables;
|
||||||
import im.conversations.android.database.entity.MessageContentEntity;
|
import im.conversations.android.database.entity.MessageContentEntity;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.jxmpp.jid.BareJid;
|
||||||
import org.jxmpp.jid.Jid;
|
import org.jxmpp.jid.Jid;
|
||||||
|
import org.jxmpp.jid.parts.Resourcepart;
|
||||||
|
|
||||||
public class ChatOverviewItem extends ChatInfo {
|
public class ChatOverviewItem extends ChatInfo {
|
||||||
|
|
||||||
|
@ -20,11 +22,16 @@ public class ChatOverviewItem extends ChatInfo {
|
||||||
public String toResource;
|
public String toResource;
|
||||||
public Jid fromBare;
|
public Jid fromBare;
|
||||||
public String fromResource;
|
public String fromResource;
|
||||||
|
|
||||||
|
public BareJid sender;
|
||||||
|
|
||||||
public long version;
|
public long version;
|
||||||
|
|
||||||
public String vCardPhoto;
|
public String vCardPhoto;
|
||||||
public String avatar;
|
public String avatar;
|
||||||
|
|
||||||
|
public Resourcepart occupantResource;
|
||||||
|
|
||||||
public int unread;
|
public int unread;
|
||||||
|
|
||||||
@Relation(
|
@Relation(
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSortedSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Multimaps;
|
import com.google.common.collect.Multimaps;
|
||||||
|
import im.conversations.android.database.KnownSender;
|
||||||
import im.conversations.android.database.entity.MessageContentEntity;
|
import im.conversations.android.database.entity.MessageContentEntity;
|
||||||
import im.conversations.android.database.entity.MessageEntity;
|
import im.conversations.android.database.entity.MessageEntity;
|
||||||
import im.conversations.android.database.entity.MessageReactionEntity;
|
import im.conversations.android.database.entity.MessageReactionEntity;
|
||||||
|
@ -22,7 +23,7 @@ import org.jxmpp.jid.impl.JidCreate;
|
||||||
import org.jxmpp.jid.parts.Resourcepart;
|
import org.jxmpp.jid.parts.Resourcepart;
|
||||||
import org.whispersystems.libsignal.IdentityKey;
|
import org.whispersystems.libsignal.IdentityKey;
|
||||||
|
|
||||||
public class MessageWithContentReactions implements IndividualName {
|
public class MessageWithContentReactions implements IndividualName, KnownSender {
|
||||||
|
|
||||||
public long accountId;
|
public long accountId;
|
||||||
|
|
||||||
|
@ -40,8 +41,6 @@ public class MessageWithContentReactions implements IndividualName {
|
||||||
public BareJid fromBare;
|
public BareJid fromBare;
|
||||||
public Resourcepart fromResource;
|
public Resourcepart fromResource;
|
||||||
|
|
||||||
// TODO retrieve occupantResource (current resource inferred by occupant id)
|
|
||||||
|
|
||||||
public BareJid sender;
|
public BareJid sender;
|
||||||
public String senderVcardPhoto;
|
public String senderVcardPhoto;
|
||||||
public String senderAvatar;
|
public String senderAvatar;
|
||||||
|
@ -49,6 +48,7 @@ public class MessageWithContentReactions implements IndividualName {
|
||||||
public String senderNick;
|
public String senderNick;
|
||||||
|
|
||||||
public String occupantVcardPhoto;
|
public String occupantVcardPhoto;
|
||||||
|
public String occupantResource;
|
||||||
|
|
||||||
public Modification modification;
|
public Modification modification;
|
||||||
public long version;
|
public long version;
|
||||||
|
@ -98,7 +98,7 @@ public class MessageWithContentReactions implements IndividualName {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AddressWithName getAddressWithName() {
|
public AddressWithName getAddressWithName() {
|
||||||
if (isIndividual()) {
|
if (isKnownSender()) {
|
||||||
return new AddressWithName(individualAddress(), individualName());
|
return new AddressWithName(individualAddress(), individualName());
|
||||||
} else {
|
} else {
|
||||||
final Jid address = JidCreate.fullFrom(fromBare, fromResource);
|
final Jid address = JidCreate.fullFrom(fromBare, fromResource);
|
||||||
|
@ -112,7 +112,7 @@ public class MessageWithContentReactions implements IndividualName {
|
||||||
if (address == null) {
|
if (address == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (isIndividual()) {
|
if (isKnownSender()) {
|
||||||
if (this.senderAvatar != null) {
|
if (this.senderAvatar != null) {
|
||||||
return new AvatarWithAccount(accountId, address, AvatarType.PEP, this.senderAvatar);
|
return new AvatarWithAccount(accountId, address, AvatarType.PEP, this.senderAvatar);
|
||||||
}
|
}
|
||||||
|
@ -128,13 +128,6 @@ public class MessageWithContentReactions implements IndividualName {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isIndividual() {
|
|
||||||
return chatType == ChatType.INDIVIDUAL
|
|
||||||
|| (Arrays.asList(ChatType.MUC, ChatType.MUC_PM).contains(chatType)
|
|
||||||
&& membersOnlyNonAnonymous
|
|
||||||
&& sender != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String individualRosterName() {
|
public String individualRosterName() {
|
||||||
return senderRosterName;
|
return senderRosterName;
|
||||||
|
@ -150,7 +143,22 @@ public class MessageWithContentReactions implements IndividualName {
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSender() {
|
@Override
|
||||||
|
public ChatType getChatType() {
|
||||||
|
return this.chatType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMembersOnlyNonAnonymous() {
|
||||||
|
return membersOnlyNonAnonymous;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BareJid getSender() {
|
||||||
|
return this.sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSenderName() {
|
||||||
return this.fromResource == null ? null : fromResource.toString();
|
return this.fromResource == null ? null : fromResource.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="4sp"
|
android:layout_marginStart="4sp"
|
||||||
android:text="@{message.sender}"
|
android:text="@{message.senderName}"
|
||||||
android:textAppearance="?textAppearanceLabelSmall"
|
android:textAppearance="?textAppearanceLabelSmall"
|
||||||
android:textColor="?colorOnSurface"
|
android:textColor="?colorOnSurface"
|
||||||
android:visibility="@{message.isGroupChat() ? View.VISIBLE : View.GONE}"
|
android:visibility="@{message.isGroupChat() ? View.VISIBLE : View.GONE}"
|
||||||
|
|
Loading…
Reference in a new issue