Skip to content

Commit

Permalink
Clean code after Benoit's review
Browse files Browse the repository at this point in the history
  • Loading branch information
ganfra committed Jan 15, 2020
1 parent d6e6092 commit 52de14b
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package im.vector.matrix.android.api.pushrules

import im.vector.matrix.android.api.session.events.model.Event
import im.vector.matrix.android.api.session.room.model.PowerLevelsContent
import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsHelper
import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsHelper

class SenderNotificationPermissionCondition(val key: String) : Condition(Kind.sender_notification_permission) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,35 @@ import im.vector.matrix.android.api.util.Cancelable
import im.vector.matrix.android.api.util.JsonDict
import im.vector.matrix.android.api.util.Optional

/**
* This interface defines methods to handling profile information. It's implemented at the session level.
*/
interface ProfileService {

companion object Constants {
const val DISPLAY_NAME_KEY = "displayname"
const val AVATAR_URL_KEY = "avatar_url"
}

/**
* Return the current dispayname for this user
* @param userId the userId param to look for
*
*/
fun getDisplayName(userId: String, matrixCallback: MatrixCallback<Optional<String>>): Cancelable

/**
* Return the current avatarUrl for this user.
* @param userId the userId param to look for
*
*/
fun getAvatarUrl(userId: String, matrixCallback: MatrixCallback<Optional<String>>): Cancelable

/**
* Get the combined profile information for this user.
* This may return keys which are not limited to displayname or avatar_url.
* @param userId the userId param to look for
*
*/
fun getProfile(userId: String, matrixCallback: MatrixCallback<JsonDict>): Cancelable
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package im.vector.matrix.android.api.session.room.model

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsConstants
import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsConstants

/**
* Class representing the EventType.EVENT_TYPE_STATE_ROOM_POWER_LEVELS state event content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

package im.vector.matrix.android.api.session.room.powerlevers
package im.vector.matrix.android.api.session.room.powerlevels

object PowerLevelsConstants {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

package im.vector.matrix.android.api.session.room.powerlevers
package im.vector.matrix.android.api.session.room.powerlevels

import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.room.model.PowerLevelsContent
Expand Down Expand Up @@ -64,9 +64,7 @@ class PowerLevelsHelper(private val powerLevelsContent: PowerLevelsContent) {
* @return the level
*/
fun notificationLevel(key: String): Int {
val value = powerLevelsContent.notifications[key]
?: return PowerLevelsConstants.DEFAULT_ROOM_MODERATOR_LEVEL
return when (value) {
return when (val value = powerLevelsContent.notifications[key]) {
// the first implementation was a string value
is String -> value.toInt()
is Int -> value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ interface ProfileAPI {
* @param userId the user id to fetch profile info
*/
@GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "profile/{userId}")
fun getProfile(@Path("userId") roomId: String): Call<JsonDict>
fun getProfile(@Path("userId") userId: String): Call<JsonDict>
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package im.vector.riotx.features.roommemberprofile

/**
* Transient events for RoomProfile
* Transient events for RoomMemberProfile
*/
sealed class RoomMemberProfileViewEvents {
data class Loading(val message: CharSequence) : RoomMemberProfileViewEvents()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import im.vector.matrix.android.api.session.room.Room
import im.vector.matrix.android.api.session.room.members.roomMemberQueryParams
import im.vector.matrix.android.api.session.room.model.PowerLevelsContent
import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsConstants
import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsHelper
import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsConstants
import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsHelper
import im.vector.matrix.android.api.util.MatrixItem
import im.vector.matrix.android.api.util.toMatrixItem
import im.vector.matrix.android.api.util.toOptional
Expand Down Expand Up @@ -196,7 +196,7 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v
if (isIgnored) {
session.unIgnoreUserIds(listOf(state.userId), ignoreActionCallback)
} else {
session.ignoreUserIds(listOf(initialState.userId), ignoreActionCallback)
session.ignoreUserIds(listOf(state.userId), ignoreActionCallback)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ class RoomProfileController @Inject constructor(private val stringProvider: Stri
if (data == null) {
return
}

val roomSummary = data.roomSummary()

val roomSummary = data.roomSummary() ?: return
// Security
buildProfileSection(stringProvider.getString(R.string.room_profile_section_security))
val learnMoreSubtitle = if (data.isEncrypted) {
val learnMoreSubtitle = if (roomSummary.isEncrypted) {
R.string.room_profile_encrypted_subtitle
} else {
R.string.room_profile_not_encrypted_subtitle
Expand All @@ -73,10 +71,10 @@ class RoomProfileController @Inject constructor(private val stringProvider: Stri
icon = R.drawable.ic_room_profile_notification,
action = { callback?.onNotificationsClicked() }
)
val numberOfMembers = roomSummary?.joinedMembersCount?.toString() ?: "-"
val numberOfMembers = roomSummary.joinedMembersCount ?: 0
buildProfileAction(
id = "member_list",
title = stringProvider.getString(R.string.room_profile_section_more_member_list, numberOfMembers),
title = stringProvider.getQuantityString(R.plurals.room_profile_section_more_member_list, numberOfMembers, numberOfMembers),
icon = R.drawable.ic_room_profile_member_list,
action = { callback?.onMemberListClicked() }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*
*/

@file:Suppress("DEPRECATION")

package im.vector.riotx.features.roomprofile

import android.os.Bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ class RoomProfileViewModel @AssistedInject constructor(@Assisted initialState: R
room.rx().liveRoomSummary()
.unwrap()
.execute {
copy(
roomSummary = it,
isEncrypted = room.isEncrypted()
)
copy(roomSummary = it)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import im.vector.matrix.android.api.session.room.model.RoomSummary

data class RoomProfileViewState(
val roomId: String,
val roomSummary: Async<RoomSummary> = Uninitialized,
val isEncrypted: Boolean = false
val roomSummary: Async<RoomSummary> = Uninitialized
) : MvRxState {

constructor(args: RoomProfileArgs) : this(roomId = args.roomId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import im.vector.matrix.android.api.session.room.members.roomMemberQueryParams
import im.vector.matrix.android.api.session.room.model.Membership
import im.vector.matrix.android.api.session.room.model.PowerLevelsContent
import im.vector.matrix.android.api.session.room.model.RoomMemberSummary
import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsConstants
import im.vector.matrix.android.api.session.room.powerlevers.PowerLevelsHelper
import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsConstants
import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsHelper
import im.vector.matrix.rx.mapOptional
import im.vector.matrix.rx.rx
import im.vector.matrix.rx.unwrap
Expand Down
5 changes: 4 additions & 1 deletion vector/src/main/res/values/strings_riotX.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
<string name="room_profile_section_more">More</string>
<string name="room_profile_section_more_settings">Room settings</string>
<string name="room_profile_section_more_notifications">Notifications</string>
<string name="room_profile_section_more_member_list">"%1$s people"</string>
<plurals name="room_profile_section_more_member_list">
<item quantity="one">"One person"</item>
<item quantity="other">"%1$d people"</item>
</plurals>
<string name="room_profile_section_more_uploads">Uploads</string>
<string name="room_profile_section_more_leave">Leave Room</string>
<string name="room_profile_leaving_room">"Leaving the room..."</string>
Expand Down

0 comments on commit 52de14b

Please sign in to comment.