Skip to content

Commit

Permalink
add rest of SpreedFeatures to Enums
Browse files Browse the repository at this point in the history
delete method hasSpreedFeatureCapability that accepts capability name as string

Signed-off-by: Marcel Hibbe <[email protected]>
  • Loading branch information
mahibi committed Mar 5, 2024
1 parent 528abff commit ba812ca
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ 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.CapabilitiesUtil.hasSpreedFeatureCapability
import com.nextcloud.talk.utils.SpreedFeatures
import com.nextcloud.talk.utils.ConversationUtils
import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.CapabilitiesUtil.hasSpreedFeatureCapability

import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import eu.davidea.flexibleadapter.items.IFilterable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
import com.nextcloud.talk.utils.CapabilitiesUtil
import com.nextcloud.talk.utils.SpreedFeatures
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
Expand Down Expand Up @@ -107,7 +108,7 @@ class ConversationsListBottomDialog(
private fun initItemsVisibility() {
val hasFavoritesCapability = CapabilitiesUtil.hasSpreedFeatureCapability(
currentUser.capabilities?.spreedCapability!!,
"favorites"
SpreedFeatures.FAVORITES
)
val canModerate = conversation.canModerate(currentUser)

Expand All @@ -120,17 +121,15 @@ class ConversationsListBottomDialog(

binding.conversationMarkAsRead.visibility = setVisibleIf(
conversation.unreadMessages > 0 && CapabilitiesUtil.hasSpreedFeatureCapability(
currentUser
.capabilities?.spreedCapability!!,
"chat-read-marker"
currentUser.capabilities?.spreedCapability!!,
SpreedFeatures.CHAT_READ_MARKER
)
)

binding.conversationMarkAsUnread.visibility = setVisibleIf(
conversation.unreadMessages <= 0 && CapabilitiesUtil.hasSpreedFeatureCapability(
currentUser
.capabilities?.spreedCapability!!,
"chat-unread"
currentUser.capabilities?.spreedCapability!!,
SpreedFeatures.CHAT_UNREAD
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class MessageActionsDialog(

private val isMessageEditable = CapabilitiesUtil.hasSpreedFeatureCapability(
spreedCapabilities,
"edit-messages"
SpreedFeatures.EDIT_MESSAGES
) && messageHasRegularText && !isOlderThanTwentyFourHours && isUserAllowedToEdit

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -166,7 +166,7 @@ class MessageActionsDialog(
)
initMenuRemindMessage(
!message.isDeleted && CapabilitiesUtil.hasSpreedFeatureCapability
(spreedCapabilities, "remind-me-later")
(spreedCapabilities, SpreedFeatures.REMIND_ME_LATER)
)
initMenuMarkAsUnread(
message.previousMessageId > NO_PREVIOUS_MESSAGE_ID &&
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/nextcloud/talk/utils/ApiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@ object ApiUtils {
val spreedCapabilities = user.capabilities!!.spreedCapability
for (version in versions) {
if (spreedCapabilities != null) {
if (hasSpreedFeatureCapability(spreedCapabilities, "signaling-v$version")) {
if (spreedCapabilities.features!!.contains("signaling-v$version")) {
return version
}
if (version == API_V2 &&
hasSpreedFeatureCapability(spreedCapabilities, "sip-support") &&
!hasSpreedFeatureCapability(spreedCapabilities, "signaling-v3")
hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.SIP_SUPPORT) &&
!hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.SIGNALING_V3)
) {
return version
}
if (version == API_V1 &&
!hasSpreedFeatureCapability(spreedCapabilities, "signaling-v3")
!hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.SIGNALING_V3)
) {
// Has no capability, we just assume it is always there when there is no v3 or later
return version
Expand All @@ -180,7 +180,7 @@ object ApiUtils {
@Throws(NoSupportedApiException::class)
fun getChatApiVersion(spreedCapabilities: SpreedCapability, versions: IntArray): Int {
for (version in versions) {
if (version == API_V1 && hasSpreedFeatureCapability(spreedCapabilities, "chat-v2")) {
if (version == API_V1 && hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.CHAT_V2)) {
// Do not question that chat-v2 capability shows the availability of api/v1/ endpoint *see no evil*
return version
}
Expand Down
28 changes: 16 additions & 12 deletions app/src/main/java/com/nextcloud/talk/utils/CapabilitiesUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,20 @@ enum class SpreedFeatures(val value: String) {
TEMP_USER_AVATAR_API("temp-user-avatar-api"),
PHONEBOOK_SEARCH("phonebook-search"),
GEO_LOCATION_SHARING("geo-location-sharing"),
TALK_POLLS("talk-polls")
TALK_POLLS("talk-polls"),
FAVORITES("favorites"),
CHAT_READ_MARKER("chat-read-marker"),
CHAT_UNREAD("chat-unread"),
EDIT_MESSAGES("edit-messages"),
REMIND_ME_LATER("remind-me-later"),
CHAT_V2("chat-v2"),
SIP_SUPPORT("sip-support"),
SIGNALING_V3("signaling-v3"),
ROOM_DESCRIPTION("room-description"),
UNIFIED_SEARCH("unified-search"),
LOCKED_ONE_TO_ONE("locked-one-to-one-rooms"),
CHAT_PERMISSION("chat-permission"),
CONVERSATION_PERMISSION("conversation-permissions")
}

@Suppress("TooManyFunctions")
Expand Down Expand Up @@ -89,15 +102,6 @@ object CapabilitiesUtil {
return false
}

@JvmStatic
@Deprecated("Add your capability to Capability enums and use hasSpreedFeatureCapability with enum.")
fun hasSpreedFeatureCapability(spreedCapabilities: SpreedCapability, capabilityName: String): Boolean {
if (spreedCapabilities.features != null) {
return spreedCapabilities.features!!.contains(capabilityName)
}
return false
}

fun getMessageMaxLength(spreedCapabilities: SpreedCapability): Int {
if (spreedCapabilities.config?.containsKey("chat") == true) {
val chatConfigHashMap = spreedCapabilities.config!!["chat"]
Expand Down Expand Up @@ -147,11 +151,11 @@ object CapabilitiesUtil {
}

fun isConversationDescriptionEndpointAvailable(spreedCapabilities: SpreedCapability): Boolean {
return hasSpreedFeatureCapability(spreedCapabilities, "room-description")
return hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.ROOM_DESCRIPTION)
}

fun isUnifiedSearchAvailable(spreedCapabilities: SpreedCapability): Boolean {
return hasSpreedFeatureCapability(spreedCapabilities, "unified-search")
return hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.UNIFIED_SEARCH)
}

fun isAbleToCall(spreedCapabilities: SpreedCapability): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object ConversationUtils {

fun isLockedOneToOne(conversation: ConversationModel, spreedCapabilities: SpreedCapability): Boolean {
return conversation.type == ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL &&
CapabilitiesUtil.hasSpreedFeatureCapability(spreedCapabilities, "locked-one-to-one-rooms")
CapabilitiesUtil.hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.LOCKED_ONE_TO_ONE)
}

fun canModerate(conversation: ConversationModel, spreedCapabilities: SpreedCapability): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ParticipantPermissions(
private fun hasConversationPermissions(): Boolean {
return CapabilitiesUtil.hasSpreedFeatureCapability(
spreedCapabilities,
"conversation-permissions"
SpreedFeatures.CONVERSATION_PERMISSION
)
}

Expand Down Expand Up @@ -90,7 +90,7 @@ class ParticipantPermissions(
}

fun hasChatPermission(): Boolean {
if (CapabilitiesUtil.hasSpreedFeatureCapability(spreedCapabilities, "chat-permission")) {
if (CapabilitiesUtil.hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.CHAT_PERMISSION)) {
return hasChatPermission
}
// if capability is not available then the spreed version doesn't support to restrict this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.nextcloud.talk.data.user.model.User;
import com.nextcloud.talk.models.json.generic.GenericOverall;
import com.nextcloud.talk.utils.ApiUtils;
import com.nextcloud.talk.utils.SpreedFeatures;
import com.nextcloud.talk.utils.UserIdUtils;
import com.nextcloud.talk.utils.CapabilitiesUtil;

Expand Down Expand Up @@ -158,8 +159,10 @@ public void onComplete() {
});

} else if ("conversation_info_message_notifications_dropdown".equals(key)) {
if (CapabilitiesUtil.hasSpreedFeatureCapability(conversationUser.getCapabilities().getSpreedCapability(), "notification" +
"-levels")) {
if (CapabilitiesUtil.hasSpreedFeatureCapability(
conversationUser.getCapabilities().getSpreedCapability(),
SpreedFeatures.NOTIFICATION_LEVELS)
) {
if (TextUtils.isEmpty(messageNotificationLevel) || !messageNotificationLevel.equals(value)) {
int intValue;
switch (value) {
Expand Down

0 comments on commit ba812ca

Please sign in to comment.