From da528776db796d44cd48ab5f018034919ee49ba0 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 23 Mar 2023 12:36:33 +0100 Subject: [PATCH] include membersOnlyNonAnonymous in chat info --- .../android/database/dao/ChatDao.java | 21 ++++++++++++------- .../android/database/model/ChatInfo.java | 2 ++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/im/conversations/android/database/dao/ChatDao.java b/app/src/main/java/im/conversations/android/database/dao/ChatDao.java index 80060706b..3b7129eb1 100644 --- a/app/src/main/java/im/conversations/android/database/dao/ChatDao.java +++ b/app/src/main/java/im/conversations/android/database/dao/ChatDao.java @@ -193,6 +193,7 @@ public abstract class ChatDao { protected abstract void deleteStatusCodes(final long chatId); // TODO select vCardPhoto for c.type='MUC_PM' + // TODO select real name for `sender` in membersOnlyNonAnonymous MUCs @Transaction @Query( "SELECT c.id,c.accountId,c.address,c.type,m.sentAt,m.outgoing,m.latestVersion as" @@ -210,11 +211,14 @@ public abstract class ChatDao { + " WHEN c.type='INDIVIDUAL' THEN (SELECT vCardPhoto FROM presence WHERE" + " accountId=c.accountId AND address=c.address AND vCardPhoto NOT NULL LIMIT 1)" + " ELSE NULL END) as vCardPhoto,(SELECT thumb_id FROM avatar WHERE" - + " avatar.accountId=c.accountId AND avatar.address=c.address) as avatar FROM CHAT" - + " c LEFT JOIN message m ON (m.id = (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 (c.address IN(SELECT" - + " roster.address FROM roster JOIN roster_group ON" + + " avatar.accountId=c.accountId AND avatar.address=c.address) as avatar,(CASE WHEN" + + " c.type='MUC' THEN (SELECT count(distinct(df.feature)) == 2 FROM 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')) ELSE 0 END) as" + + " membersOnlyNonAnonymous FROM CHAT c LEFT JOIN message m ON (m.id = (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" + + " (c.address IN(SELECT roster.address FROM roster JOIN roster_group ON" + " roster.id=roster_group.rosterItemId WHERE roster.accountId=c.accountId AND" + " roster_group.groupId=:groupId) OR c.address IN(SELECT address FROM bookmark" + " JOIN bookmark_group ON bookmark.id=bookmark_group.bookmarkId WHERE" @@ -231,8 +235,11 @@ public abstract class ChatDao { + " disco_identity identity ON disco_item.discoId=identity.discoId WHERE" + " disco_item.accountId=c.accountId AND disco_item.address=c.address LIMIT 1) as" + " discoIdentityName,(SELECT name FROM bookmark WHERE" - + " bookmark.accountId=c.accountId AND bookmark.address=c.address) as bookmarkName" - + " FROM chat c WHERE c.id=:chatId") + + " bookmark.accountId=c.accountId AND bookmark.address=c.address) as" + + " bookmarkName,(CASE WHEN c.type='MUC' THEN (SELECT count(distinct(df.feature))" + + " == 2 FROM 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'))" + + " ELSE 0 END) as membersOnlyNonAnonymous FROM chat c WHERE c.id=:chatId") public abstract LiveData getChatInfo(final long chatId); public PagingSource getChatOverview(final ChatFilter chatFilter) { diff --git a/app/src/main/java/im/conversations/android/database/model/ChatInfo.java b/app/src/main/java/im/conversations/android/database/model/ChatInfo.java index 69cfca5bd..f200e01ad 100644 --- a/app/src/main/java/im/conversations/android/database/model/ChatInfo.java +++ b/app/src/main/java/im/conversations/android/database/model/ChatInfo.java @@ -14,6 +14,8 @@ public class ChatInfo { public String discoIdentityName; public String bookmarkName; + public boolean membersOnlyNonAnonymous; + public String name() { return switch (type) { case MUC -> mucName();