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( data class SenderInfo(
val userId: String, val userId: String,
/** /**
* Consider using [getDisambiguatedDisplayName] * Consider using [disambiguatedDisplayName]
*/ */
val displayName: String?, val displayName: String?,
val isUniqueDisplayName: Boolean, val isUniqueDisplayName: Boolean,
val avatarUrl: String? val avatarUrl: String?
) { ) {
fun getDisambiguatedDisplayName(): String { val disambiguatedDisplayName: String
return when { get() = when {
displayName.isNullOrBlank() -> userId displayName.isNullOrBlank() -> userId
isUniqueDisplayName -> displayName 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( data class GetUploadsResult(
// List of fetched Events, most recent first // List of fetched Events, most recent first
val events: List<UploadEvent>, val uploadEvents: List<UploadEvent>,
// token to get more events // token to get more events
val nextToken: String, val nextToken: String,
// True if there are more event to load // True if there are more event to load
val hasMore: Boolean 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 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 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?, private fun resolveRoomMemberName(roomMemberSummary: RoomMemberSummaryEntity?,
roomMemberHelper: RoomMemberHelper): String? { roomMemberHelper: RoomMemberHelper): String? {
if (roomMemberSummary == null) return null if (roomMemberSummary == null) return null

View file

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

View file

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

View file

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

View file

@ -458,7 +458,7 @@ class RoomDetailFragment @Inject constructor(
autoCompleter.enterSpecialMode() autoCompleter.enterSpecialMode()
// switch to expanded bar // switch to expanded bar
composerLayout.composerRelatedMessageTitle.apply { composerLayout.composerRelatedMessageTitle.apply {
text = event.senderInfo.getDisambiguatedDisplayName() text = event.senderInfo.disambiguatedDisplayName
setTextColor(ContextCompat.getColor(requireContext(), getColorFromUserId(event.root.senderId))) 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( val data = BasedMergedItem.Data(
userId = mergedEvent.root.senderId ?: "", userId = mergedEvent.root.senderId ?: "",
avatarUrl = mergedEvent.senderInfo.avatarUrl, avatarUrl = mergedEvent.senderInfo.avatarUrl,
memberName = mergedEvent.senderInfo.getDisambiguatedDisplayName(), memberName = mergedEvent.senderInfo.disambiguatedDisplayName,
localId = mergedEvent.localId, localId = mergedEvent.localId,
eventId = mergedEvent.root.eventId ?: "" eventId = mergedEvent.root.eventId ?: ""
) )
@ -159,7 +159,7 @@ class MergedHeaderItemFactory @Inject constructor(private val avatarRenderer: Av
val data = BasedMergedItem.Data( val data = BasedMergedItem.Data(
userId = mergedEvent.root.senderId ?: "", userId = mergedEvent.root.senderId ?: "",
avatarUrl = mergedEvent.senderInfo.avatarUrl, avatarUrl = mergedEvent.senderInfo.avatarUrl,
memberName = mergedEvent.senderInfo.getDisambiguatedDisplayName(), memberName = mergedEvent.senderInfo.disambiguatedDisplayName,
localId = mergedEvent.localId, localId = mergedEvent.localId,
eventId = mergedEvent.root.eventId ?: "" eventId = mergedEvent.root.eventId ?: ""
) )

View file

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

View file

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

View file

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

View file

@ -111,7 +111,7 @@ class ViewReactionsViewModel @AssistedInject constructor(@Assisted
event.root.eventId!!, event.root.eventId!!,
summary.key, summary.key,
event.root.senderId ?: "", event.root.senderId ?: "",
event.senderInfo.getDisambiguatedDisplayName(), event.senderInfo.disambiguatedDisplayName,
dateFormatter.formatRelativeDateTime(event.root.originServerTs) 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 // Ok room is not known in store, but we can still display something
val body = displayableEventFormatter.format(event, false) val body = displayableEventFormatter.format(event, false)
val roomName = stringProvider.getString(R.string.notification_unknown_room_name) val roomName = stringProvider.getString(R.string.notification_unknown_room_name)
val senderDisplayName = event.senderInfo.getDisambiguatedDisplayName() val senderDisplayName = event.senderInfo.disambiguatedDisplayName
val notifiableEvent = NotifiableMessageEvent( val notifiableEvent = NotifiableMessageEvent(
eventId = event.root.eventId!!, eventId = event.root.eventId!!,
@ -126,7 +126,7 @@ class NotifiableEventResolver @Inject constructor(private val stringProvider: St
val body = displayableEventFormatter.format(event, false).toString() val body = displayableEventFormatter.format(event, false).toString()
val roomName = room.roomSummary()?.displayName ?: "" val roomName = room.roomSummary()?.displayName ?: ""
val senderDisplayName = event.senderInfo.getDisambiguatedDisplayName() val senderDisplayName = event.senderInfo.disambiguatedDisplayName
val notifiableEvent = NotifiableMessageEvent( val notifiableEvent = NotifiableMessageEvent(
eventId = event.root.eventId!!, 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 -> override fun invalidate() = withState(viewModel) { state ->
renderRoomSummary(state) renderRoomSummary(state)
} }

View file

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

View file

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

View file

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