Merge pull request #3351 from nextcloud/issue-786-note-to-self

Note To Self ✏️
This commit is contained in:
Marcel Hibbe 2023-10-24 13:58:36 +02:00 committed by GitHub
commit 128e57dbf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 108 additions and 5 deletions

View file

@ -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 ->

View file

@ -2248,7 +2248,10 @@ class ChatActivity :
}
private fun checkShowCallButtons() {
if (isReadOnlyConversation() || shouldShowLobby()) {
if (isReadOnlyConversation() ||
shouldShowLobby() ||
ConversationUtils.isNoteToSelfConversation(currentConversation)
) {
disableCallButtons()
} else {
enableCallButtons()

View file

@ -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
}

View file

@ -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<Drawable>(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()
}

View file

@ -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")

View file

@ -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
}
}

View file

@ -0,0 +1,42 @@
<!--
~ Copyright (c) 2023 Nextcloud Talk application
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
~ SOFTWARE.
-->
<vector
android:height="24dp"
android:width="24dp"
android:viewportHeight="54"
android:viewportWidth="54"
xmlns:android="http://schemas.android.com/apk/res/android">
<group
android:translateX="12"
android:translateY="12">
<path android:fillColor="#B4ACBC" android:pathData="M20.343,2.293C20.156,2.105 19.901,2 19.636,2H7C5.895,2 5,2.895 5,4V28C5,29.105 5.895,30 7,30H25C26.105,30 27,29.105 27,28V9.364C27,9.099 26.895,8.844 26.707,8.657L20.343,2.293Z"/>
<path android:fillColor="#F3EEF8" android:pathData="M19.682,3L7,3C6.448,3 6,3.448 6,4V28C6,28.552 6.448,29 7,29L25,29C25.552,29 26,28.552 26,28V9.453L19.682,3Z"/>
<path android:fillColor="#998EA4" android:pathData="M9.5,12H22.5C22.776,12 23,12.224 23,12.5C23,12.776 22.776,13 22.5,13H9.5C9.224,13 9,12.776 9,12.5C9,12.224 9.224,12 9.5,12ZM9.5,15C9.224,15 9,15.224 9,15.5C9,15.776 9.224,16 9.5,16H22.5C22.776,16 23,15.776 23,15.5C23,15.224 22.776,15 22.5,15H9.5ZM9,18.5C9,18.224 9.224,18 9.5,18H22.5C22.776,18 23,18.224 23,18.5C23,18.776 22.776,19 22.5,19H9.5C9.224,19 9,18.776 9,18.5ZM9.5,21C9.224,21 9,21.224 9,21.5C9,21.776 9.224,22 9.5,22H17.5C17.776,22 18,21.776 18,21.5C18,21.224 17.776,21 17.5,21H9.5Z"/>
<path android:fillColor="#CDC4D6" android:pathData="M26,9.453H21.389C20.446,9.453 19.682,8.689 19.682,7.746V3L26,9.453Z"/>
<path android:fillColor="#FF822D" android:pathData="M26.766,20.172L25.686,16.941L22.89,14.935L12.283,22.784L13.431,25.94L16.158,28.022L26.766,20.172Z"/>
<path android:fillColor="#FFCE7C" android:pathData="M11.106,26.654L11.277,27.548L12.113,28.016L16.152,28.01L12.292,22.794L11.106,26.654Z"/>
<path android:fillColor="#402A32" android:pathData="M10.686,28.018L11.105,26.655L12.112,28.016L10.686,28.018Z"/>
<path android:fillColor="#F92F60" android:pathData="M26.521,12.248C27.409,11.592 28.661,11.779 29.318,12.667L30.814,14.689C31.471,15.577 31.284,16.829 30.396,17.486L28.338,19.01L25.533,16.941L24.462,13.772L26.521,12.248Z"/>
<path android:fillColor="#D3D3D3" android:pathData="M24.462,13.772L28.338,19.01L26.766,20.172L22.891,14.935L24.462,13.772Z"/>
</group>
</vector>