Uploads: auto-review

This commit is contained in:
Benoit Marty 2020-05-20 14:27:10 +02:00
parent a95102a78f
commit f0f3e8ddb9
18 changed files with 36 additions and 48 deletions

View file

@ -19,17 +19,16 @@ package im.vector.matrix.android.api.session.room.sender
data class SenderInfo(
val userId: String,
/**
* Consider using [getDisambiguatedDisplayName]
* Consider using [disambiguatedDisplayName]
*/
val displayName: String?,
val isUniqueDisplayName: Boolean,
val avatarUrl: String?
) {
fun getDisambiguatedDisplayName(): String {
return when {
val disambiguatedDisplayName: String
get() = when {
displayName.isNullOrBlank() -> userId
isUniqueDisplayName -> displayName
else -> "$displayName (${userId})"
else -> "$displayName ($userId)"
}
}
}

View file

@ -18,10 +18,9 @@ package im.vector.matrix.android.api.session.room.uploads
data class GetUploadsResult(
// List of fetched Events, most recent first
val events: List<UploadEvent>,
val uploadEvents: List<UploadEvent>,
// token to get more events
val nextToken: String,
// True if there are more event to load
val hasMore: Boolean
)

View file

@ -156,4 +156,4 @@ fun PublicRoom.toMatrixItem() = MatrixItem.RoomItem(roomId, name ?: getPrimaryAl
fun RoomMemberSummary.toMatrixItem() = MatrixItem.UserItem(userId, displayName, avatarUrl)
fun SenderInfo.toMatrixItem() = MatrixItem.UserItem(userId, getDisambiguatedDisplayName(), avatarUrl)
fun SenderInfo.toMatrixItem() = MatrixItem.UserItem(userId, disambiguatedDisplayName, avatarUrl)

View file

@ -126,7 +126,7 @@ internal class RoomDisplayNameResolver @Inject constructor(private val context:
return name ?: roomId
}
/** See [im.vector.matrix.android.api.session.room.timeline.TimelineEvent.getDisambiguatedDisplayName] */
/** See [im.vector.matrix.android.api.session.room.sender.SenderInfo.disambiguatedDisplayName] */
private fun resolveRoomMemberName(roomMemberSummary: RoomMemberSummaryEntity?,
roomMemberHelper: RoomMemberHelper): String? {
if (roomMemberSummary == null) return null

View file

@ -202,7 +202,7 @@ internal class LocalEchoEventFactory @Inject constructor(
permalink,
stringProvider.getString(R.string.message_reply_to_prefix),
userLink,
originalEvent.senderInfo.getDisambiguatedDisplayName(),
originalEvent.senderInfo.disambiguatedDisplayName,
body.takeFormatted(),
createTextContent(newBodyText, newBodyAutoMarkdown).takeFormatted()
)

View file

@ -91,9 +91,8 @@ internal class DefaultGetUploadsTask @Inject constructor(
}
}
return GetUploadsResult(
events = uploadEvents,
uploadEvents = uploadEvents,
nextToken = chunk.end ?: "",
hasMore = chunk.hasMore()
)

View file

@ -260,6 +260,7 @@ dependencies {
def autofill_version = "1.0.0"
def work_version = '2.3.3'
def arch_version = '2.1.0'
def lifecycle_version = '2.2.0'
implementation project(":matrix-sdk-android")
implementation project(":matrix-sdk-android-rx")
@ -282,7 +283,7 @@ dependencies {
implementation "com.gabrielittner.threetenbp:lazythreetenbp:0.7.0"
implementation "com.squareup.moshi:moshi-adapters:$moshi_version"
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshi_version"
// Log

View file

@ -458,7 +458,7 @@ class RoomDetailFragment @Inject constructor(
autoCompleter.enterSpecialMode()
// switch to expanded bar
composerLayout.composerRelatedMessageTitle.apply {
text = event.senderInfo.getDisambiguatedDisplayName()
text = event.senderInfo.disambiguatedDisplayName
setTextColor(ContextCompat.getColor(requireContext(), getColorFromUserId(event.root.senderId)))
}

View file

@ -88,7 +88,7 @@ class MergedHeaderItemFactory @Inject constructor(private val avatarRenderer: Av
val data = BasedMergedItem.Data(
userId = mergedEvent.root.senderId ?: "",
avatarUrl = mergedEvent.senderInfo.avatarUrl,
memberName = mergedEvent.senderInfo.getDisambiguatedDisplayName(),
memberName = mergedEvent.senderInfo.disambiguatedDisplayName,
localId = mergedEvent.localId,
eventId = mergedEvent.root.eventId ?: ""
)
@ -159,7 +159,7 @@ class MergedHeaderItemFactory @Inject constructor(private val avatarRenderer: Av
val data = BasedMergedItem.Data(
userId = mergedEvent.root.senderId ?: "",
avatarUrl = mergedEvent.senderInfo.avatarUrl,
memberName = mergedEvent.senderInfo.getDisambiguatedDisplayName(),
memberName = mergedEvent.senderInfo.disambiguatedDisplayName,
localId = mergedEvent.localId,
eventId = mergedEvent.root.eventId ?: ""
)

View file

@ -45,7 +45,7 @@ class DisplayableEventFormatter @Inject constructor(
return stringProvider.getString(R.string.encrypted_message)
}
val senderName = timelineEvent.senderInfo.getDisambiguatedDisplayName()
val senderName = timelineEvent.senderInfo.disambiguatedDisplayName
when (timelineEvent.root.getClearType()) {
EventType.MESSAGE -> {

View file

@ -47,20 +47,20 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
fun format(timelineEvent: TimelineEvent): CharSequence? {
return when (val type = timelineEvent.root.getClearType()) {
EventType.STATE_ROOM_JOIN_RULES -> formatJoinRulesEvent(timelineEvent.root, timelineEvent.senderInfo.getDisambiguatedDisplayName())
EventType.STATE_ROOM_JOIN_RULES -> formatJoinRulesEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
EventType.STATE_ROOM_CREATE -> formatRoomCreateEvent(timelineEvent.root)
EventType.STATE_ROOM_NAME -> formatRoomNameEvent(timelineEvent.root, timelineEvent.senderInfo.getDisambiguatedDisplayName())
EventType.STATE_ROOM_TOPIC -> formatRoomTopicEvent(timelineEvent.root, timelineEvent.senderInfo.getDisambiguatedDisplayName())
EventType.STATE_ROOM_MEMBER -> formatRoomMemberEvent(timelineEvent.root, timelineEvent.senderInfo.getDisambiguatedDisplayName())
EventType.STATE_ROOM_ALIASES -> formatRoomAliasesEvent(timelineEvent.root, timelineEvent.senderInfo.getDisambiguatedDisplayName())
EventType.STATE_ROOM_CANONICAL_ALIAS -> formatRoomCanonicalAliasEvent(timelineEvent.root, timelineEvent.senderInfo.getDisambiguatedDisplayName())
EventType.STATE_ROOM_HISTORY_VISIBILITY -> formatRoomHistoryVisibilityEvent(timelineEvent.root, timelineEvent.senderInfo.getDisambiguatedDisplayName())
EventType.STATE_ROOM_GUEST_ACCESS -> formatRoomGuestAccessEvent(timelineEvent.root, timelineEvent.senderInfo.getDisambiguatedDisplayName())
EventType.STATE_ROOM_ENCRYPTION -> formatRoomEncryptionEvent(timelineEvent.root, timelineEvent.senderInfo.getDisambiguatedDisplayName())
EventType.STATE_ROOM_TOMBSTONE -> formatRoomTombstoneEvent(timelineEvent.senderInfo.getDisambiguatedDisplayName())
EventType.STATE_ROOM_NAME -> formatRoomNameEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
EventType.STATE_ROOM_TOPIC -> formatRoomTopicEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
EventType.STATE_ROOM_MEMBER -> formatRoomMemberEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
EventType.STATE_ROOM_ALIASES -> formatRoomAliasesEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
EventType.STATE_ROOM_CANONICAL_ALIAS -> formatRoomCanonicalAliasEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
EventType.STATE_ROOM_HISTORY_VISIBILITY -> formatRoomHistoryVisibilityEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
EventType.STATE_ROOM_GUEST_ACCESS -> formatRoomGuestAccessEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
EventType.STATE_ROOM_ENCRYPTION -> formatRoomEncryptionEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
EventType.STATE_ROOM_TOMBSTONE -> formatRoomTombstoneEvent(timelineEvent.senderInfo.disambiguatedDisplayName)
EventType.CALL_INVITE,
EventType.CALL_HANGUP,
EventType.CALL_ANSWER -> formatCallEvent(timelineEvent.root, timelineEvent.senderInfo.getDisambiguatedDisplayName())
EventType.CALL_ANSWER -> formatCallEvent(timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName)
EventType.MESSAGE,
EventType.REACTION,
EventType.KEY_VERIFICATION_START,

View file

@ -65,13 +65,13 @@ class MessageInformationDataFactory @Inject constructor(private val session: Ses
val showInformation =
addDaySeparator
|| event.senderInfo.avatarUrl != nextEvent?.senderInfo?.avatarUrl
|| event.senderInfo.getDisambiguatedDisplayName() != nextEvent?.senderInfo?.getDisambiguatedDisplayName()
|| event.senderInfo.disambiguatedDisplayName != nextEvent?.senderInfo?.disambiguatedDisplayName
|| (nextEvent.root.getClearType() != EventType.MESSAGE && nextEvent.root.getClearType() != EventType.ENCRYPTED)
|| isNextMessageReceivedMoreThanOneHourAgo
|| isTileTypeMessage(nextEvent)
val time = dateFormatter.formatMessageHour(date)
val formattedMemberName = span(event.senderInfo.getDisambiguatedDisplayName()) {
val formattedMemberName = span(event.senderInfo.disambiguatedDisplayName) {
textColor = colorProvider.getColor(getColorFromUserId(event.root.senderId))
}

View file

@ -111,7 +111,7 @@ class ViewReactionsViewModel @AssistedInject constructor(@Assisted
event.root.eventId!!,
summary.key,
event.root.senderId ?: "",
event.senderInfo.getDisambiguatedDisplayName(),
event.senderInfo.disambiguatedDisplayName,
dateFormatter.formatRelativeDateTime(event.root.originServerTs)
)

View file

@ -93,7 +93,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St
// Ok room is not known in store, but we can still display something
val body = displayableEventFormatter.format(event, false)
val roomName = stringProvider.getString(R.string.notification_unknown_room_name)
val senderDisplayName = event.senderInfo.getDisambiguatedDisplayName()
val senderDisplayName = event.senderInfo.disambiguatedDisplayName
val notifiableEvent = NotifiableMessageEvent(
eventId = event.root.eventId!!,
@ -126,7 +126,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St
val body = displayableEventFormatter.format(event, false).toString()
val roomName = room.roomSummary()?.displayName ?: ""
val senderDisplayName = event.senderInfo.getDisambiguatedDisplayName()
val senderDisplayName = event.senderInfo.disambiguatedDisplayName
val notifiableEvent = NotifiableMessageEvent(
eventId = event.root.eventId!!,

View file

@ -87,14 +87,6 @@ class RoomUploadsFragment @Inject constructor(
}
}
/*
override fun onDestroyView() {
super.onDestroyView()
// Clear your view, unsubscribe...
}
*/
override fun invalidate() = withState(viewModel) { state ->
renderRoomSummary(state)
}

View file

@ -96,7 +96,7 @@ class RoomUploadsViewModel @AssistedInject constructor(
token = result.nextToken
val groupedEvents = result.events
val groupedUploadEvents = result.uploadEvents
.groupBy {
it.contentWithAttachmentContent.msgType == MessageType.MSGTYPE_IMAGE
|| it.contentWithAttachmentContent.msgType == MessageType.MSGTYPE_VIDEO
@ -105,13 +105,13 @@ class RoomUploadsViewModel @AssistedInject constructor(
setState {
copy(
asyncEventsRequest = Success(Unit),
mediaEvents = this.mediaEvents + groupedEvents[true].orEmpty(),
fileEvents = this.fileEvents + groupedEvents[false].orEmpty(),
mediaEvents = this.mediaEvents + groupedUploadEvents[true].orEmpty(),
fileEvents = this.fileEvents + groupedUploadEvents[false].orEmpty(),
hasMore = result.hasMore
)
}
} catch (failure: Throwable) {
// TODO Post fail
_viewEvents.post(RoomUploadsViewEvents.Failure(failure))
setState {
copy(
asyncEventsRequest = Fail(failure)
@ -163,7 +163,6 @@ class RoomUploadsViewModel @AssistedInject constructor(
action.uploadEvent.contentWithAttachmentContent.getFileUrl(),
action.uploadEvent.contentWithAttachmentContent.encryptedFileInfo?.toElementToDecrypt(),
it)
}
_viewEvents.post(RoomUploadsViewEvents.FileReadyForSaving(file, action.uploadEvent.contentWithAttachmentContent.body))
} catch (failure: Throwable) {

View file

@ -37,4 +37,3 @@ data class RoomUploadsViewState(
constructor(args: RoomProfileArgs) : this(roomId = args.roomId)
}

View file

@ -70,7 +70,7 @@ class UploadsFileController @Inject constructor(
id(uploadEvent.eventId)
title(uploadEvent.contentWithAttachmentContent.body)
subtitle(stringProvider.getString(R.string.uploads_files_subtitle,
uploadEvent.senderInfo.getDisambiguatedDisplayName(),
uploadEvent.senderInfo.disambiguatedDisplayName,
dateFormatter.formatRelativeDateTime(uploadEvent.root.originServerTs)))
listener(object : UploadsFileItem.Listener {
override fun onItemClicked() {