From 3af7de2e78ee38c7c6235c9ad5671d150353db6f Mon Sep 17 00:00:00 2001 From: Julius Linus Date: Thu, 28 Sep 2023 10:21:31 -0500 Subject: [PATCH] Note to Self - Can not add participants to the room - Can not allow guests - Can not make read-only - Can not make listable - Can not change permissions - Can not set lobby - Can not enable SIP - Can not configure breakout rooms - Can not call - Custom Avatar Signed-off-by: Julius Linus --- .../talk/adapters/items/ConversationItem.kt | 12 ++++++ .../com/nextcloud/talk/chat/ChatActivity.kt | 5 ++- .../ConversationInfoActivity.kt | 23 +++++++++- .../talk/extensions/ImageViewExtensions.kt | 18 ++++++++ .../models/json/conversations/Conversation.kt | 5 ++- .../nextcloud/talk/utils/ConversationUtils.kt | 8 +++- app/src/main/res/drawable/ic_note_to_self.xml | 42 +++++++++++++++++++ 7 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 app/src/main/res/drawable/ic_note_to_self.xml diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt b/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt index 85133c9d8..4906bb7bc 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.kt @@ -41,13 +41,16 @@ import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedA import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.databinding.RvItemConversationWithLastMessageBinding import com.nextcloud.talk.extensions.loadConversationAvatar +import com.nextcloud.talk.extensions.loadNoteToSelfAvatar import com.nextcloud.talk.extensions.loadSystemAvatar import com.nextcloud.talk.extensions.loadUserAvatar +import com.nextcloud.talk.models.domain.ConversationModel import com.nextcloud.talk.models.json.chat.ChatMessage import com.nextcloud.talk.models.json.conversations.Conversation import com.nextcloud.talk.models.json.conversations.Conversation.ConversationType import com.nextcloud.talk.ui.StatusDrawable import com.nextcloud.talk.ui.theme.ViewThemeUtils +import com.nextcloud.talk.utils.ConversationUtils import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew.hasSpreedFeatureCapability import eu.davidea.flexibleadapter.FlexibleAdapter @@ -181,6 +184,15 @@ class ConversationItem( } } + ConversationType.DUMMY -> { + if (ConversationUtils.isNoteToSelfConversation( + ConversationModel.mapToConversationModel(model) + ) + ) { + holder.binding.dialogAvatar.loadNoteToSelfAvatar() + } + } + ConversationType.ROOM_GROUP_CALL, ConversationType.FORMER_ONE_TO_ONE, ConversationType.ROOM_PUBLIC_CALL -> diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index 887d44233..7518d446b 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -2248,7 +2248,10 @@ class ChatActivity : } private fun checkShowCallButtons() { - if (isReadOnlyConversation() || shouldShowLobby()) { + if (isReadOnlyConversation() || + shouldShowLobby() || + ConversationUtils.isNoteToSelfConversation(currentConversation) + ) { disableCallButtons() } else { enableCallButtons() diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt index 631db4239..3d0b3f1f9 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -65,10 +65,12 @@ import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.databinding.ActivityConversationInfoBinding import com.nextcloud.talk.events.EventStatus import com.nextcloud.talk.extensions.loadConversationAvatar +import com.nextcloud.talk.extensions.loadNoteToSelfAvatar import com.nextcloud.talk.extensions.loadSystemAvatar import com.nextcloud.talk.extensions.loadUserAvatar import com.nextcloud.talk.jobs.DeleteConversationWorker import com.nextcloud.talk.jobs.LeaveConversationWorker +import com.nextcloud.talk.models.domain.ConversationModel import com.nextcloud.talk.models.json.conversations.Conversation import com.nextcloud.talk.models.json.conversations.RoomOverall import com.nextcloud.talk.models.json.converters.EnumNotificationLevelConverter @@ -81,6 +83,7 @@ import com.nextcloud.talk.models.json.participants.ParticipantsOverall import com.nextcloud.talk.repositories.conversations.ConversationsRepository import com.nextcloud.talk.shareditems.activities.SharedItemsActivity import com.nextcloud.talk.utils.ApiUtils +import com.nextcloud.talk.utils.ConversationUtils import com.nextcloud.talk.utils.DateConstants import com.nextcloud.talk.utils.DateUtils import com.nextcloud.talk.utils.bundle.BundleKeys @@ -714,8 +717,14 @@ class ConversationInfoActivity : conversationUser ).setupGuestAccess() } - - binding.notificationSettingsView.notificationSettings.visibility = VISIBLE + if (ConversationUtils.isNoteToSelfConversation( + ConversationModel.mapToConversationModel(conversation!!) + ) + ) { + binding.notificationSettingsView.notificationSettings.visibility = GONE + } else { + binding.notificationSettingsView.notificationSettings.visibility = VISIBLE + } } } @@ -731,6 +740,7 @@ class ConversationInfoActivity : private fun initExpiringMessageOption() { if (conversation!!.isParticipantOwnerOrModerator && + !ConversationUtils.isNoteToSelfConversation(ConversationModel.mapToConversationModel(conversation!!)) && CapabilitiesUtilNew.hasSpreedFeatureCapability(conversationUser, "message-expiration") ) { databaseStorageModule?.setMessageExpiration(conversation!!.messageExpiration) @@ -828,6 +838,15 @@ class ConversationInfoActivity : binding.avatarImage.loadSystemAvatar() } + Conversation.ConversationType.DUMMY -> { + if (ConversationUtils.isNoteToSelfConversation( + ConversationModel.mapToConversationModel(conversation!!) + ) + ) { + binding.avatarImage.loadNoteToSelfAvatar() + } + } + else -> { // unused atm } diff --git a/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt b/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt index f2d6c439f..b16e30419 100644 --- a/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt +++ b/app/src/main/java/com/nextcloud/talk/extensions/ImageViewExtensions.kt @@ -267,6 +267,24 @@ fun ImageView.loadSystemAvatar(): io.reactivex.disposables.Disposable { ) } +fun ImageView.loadNoteToSelfAvatar(): io.reactivex.disposables.Disposable { + val data: Any = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val layers = arrayOfNulls(2) + layers[0] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_background) + layers[1] = ContextCompat.getDrawable(context, R.drawable.ic_note_to_self) + val layerDrawable = LayerDrawable(layers) + layerDrawable + } else { + R.mipmap.ic_launcher + } + + return DisposableWrapper( + load(data) { + transformations(CircleCropTransformation()) + } + ) +} + fun ImageView.loadChangelogBotAvatar(): io.reactivex.disposables.Disposable { return loadSystemAvatar() } diff --git a/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.kt b/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.kt index b7b3f1547..057e5d724 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.kt +++ b/app/src/main/java/com/nextcloud/talk/models/json/conversations/Conversation.kt @@ -29,6 +29,7 @@ import android.os.Parcelable import com.bluelinelabs.logansquare.annotation.JsonField import com.bluelinelabs.logansquare.annotation.JsonObject import com.nextcloud.talk.data.user.model.User +import com.nextcloud.talk.models.domain.ConversationModel import com.nextcloud.talk.models.json.chat.ChatMessage import com.nextcloud.talk.models.json.converters.ConversationObjectTypeConverter import com.nextcloud.talk.models.json.converters.EnumLobbyStateConverter @@ -37,6 +38,7 @@ import com.nextcloud.talk.models.json.converters.EnumParticipantTypeConverter import com.nextcloud.talk.models.json.converters.EnumReadOnlyConversationConverter import com.nextcloud.talk.models.json.converters.EnumRoomTypeConverter import com.nextcloud.talk.models.json.participants.Participant.ParticipantType +import com.nextcloud.talk.utils.ConversationUtils import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew import kotlinx.parcelize.Parcelize @@ -187,7 +189,8 @@ data class Conversation( fun canModerate(conversationUser: User): Boolean { return isParticipantOwnerOrModerator && !isLockedOneToOne(conversationUser) && - type != ConversationType.FORMER_ONE_TO_ONE + type != ConversationType.FORMER_ONE_TO_ONE && + !ConversationUtils.isNoteToSelfConversation(ConversationModel.mapToConversationModel(this)) } @Deprecated("Use ConversationUtil") diff --git a/app/src/main/java/com/nextcloud/talk/utils/ConversationUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/ConversationUtils.kt index cc125ff0a..a4c2414a8 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ConversationUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/ConversationUtils.kt @@ -27,6 +27,7 @@ import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew object ConversationUtils { private val TAG = ConversationUtils::class.java.simpleName + private const val NOTE_TO_SELF = "Note to self" fun isPublic(conversation: ConversationModel): Boolean { return ConversationType.ROOM_PUBLIC_CALL == conversation.type @@ -52,7 +53,8 @@ object ConversationUtils { fun canModerate(conversation: ConversationModel, conversationUser: User): Boolean { return isParticipantOwnerOrModerator(conversation) && !isLockedOneToOne(conversation, conversationUser) && - conversation.type != ConversationType.FORMER_ONE_TO_ONE + conversation.type != ConversationType.FORMER_ONE_TO_ONE && + !isNoteToSelfConversation(conversation) } fun isLobbyViewApplicable(conversation: ConversationModel, conversationUser: User): Boolean { @@ -86,4 +88,8 @@ object ConversationUtils { // Fallback for APIv1 } } + + fun isNoteToSelfConversation(currentConversation: ConversationModel?): Boolean { + return currentConversation != null && currentConversation.name == NOTE_TO_SELF + } } diff --git a/app/src/main/res/drawable/ic_note_to_self.xml b/app/src/main/res/drawable/ic_note_to_self.xml new file mode 100644 index 000000000..a79fd0572 --- /dev/null +++ b/app/src/main/res/drawable/ic_note_to_self.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + +