Skip to content

Commit

Permalink
Note to Self
Browse files Browse the repository at this point in the history
- 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

Signed-off-by: Julius Linus <[email protected]>
  • Loading branch information
rapterjet2004 committed Oct 2, 2023
1 parent 703f2c0 commit d112a6f
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2230,7 +2230,10 @@ class ChatActivity :
}

private fun checkShowCallButtons() {
if (isReadOnlyConversation() || shouldShowLobby()) {
if (isReadOnlyConversation() ||
shouldShowLobby() ||
ConversationUtils.isNoteToSelfConversation(currentConversation)
) {
disableCallButtons()
} else {
enableCallButtons()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
}
}

Expand All @@ -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)
Expand Down Expand Up @@ -828,6 +838,15 @@ class ConversationInfoActivity :
binding.avatarImage.loadSystemAvatar()
}

Conversation.ConversationType.DUMMY -> {
if (ConversationUtils.isNoteToSelfConversation(
ConversationModel.mapToConversationModel(conversation!!)
)
) {
binding.avatarImage.loadNoteToSelfAvatar()
}
}

else -> {
// unused atm
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -86,4 +88,8 @@ object ConversationUtils {
// Fallback for APIv1
}
}

fun isNoteToSelfConversation(currentConversation: ConversationModel?): Boolean {
return currentConversation != null && currentConversation.name == NOTE_TO_SELF
}
}
36 changes: 36 additions & 0 deletions app/src/main/res/drawable/ic_note_to_self.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
~ Nextcloud Talk application
~
~ @author Julius Linus
~ Copyright (C) 2023 Julius Linus <[email protected]>
~ @author Mario Danic
~ Copyright (C) 2017-2019 Mario Danic <[email protected]>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="48"
android:viewportHeight="48">
<group
android:translateX="12"
android:translateY="12"
>
<path
android:fillColor="#ffffff"
android:pathData="M20.71,7.04C21.1,6.65 21.1,6 20.71,5.63L18.37,3.29C18,2.9 17.35,2.9 16.96,3.29L15.12,5.12L18.87,8.87M3,17.25V21H6.75L17.81,9.93L14.06,6.18L3,17.25Z" />
</group>
</vector>

0 comments on commit d112a6f

Please sign in to comment.