mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 02:45:53 +03:00
Render aliases and canonical alias change in the timeline
This commit is contained in:
parent
51d6b8828d
commit
e73970d61b
7 changed files with 52 additions and 2 deletions
|
@ -5,7 +5,7 @@ Features ✨:
|
|||
-
|
||||
|
||||
Improvements 🙌:
|
||||
-
|
||||
- Render aliases and canonical alias change in the timeline
|
||||
|
||||
Other changes:
|
||||
-
|
||||
|
|
|
@ -2,6 +2,19 @@
|
|||
<resources>
|
||||
|
||||
|
||||
<plurals name="notice_room_aliases_added">
|
||||
<item quantity="one">%1$s added %2$s as an address for this room.</item>
|
||||
<item quantity="other">%1$s added %2$s as addresses for this room.</item>
|
||||
</plurals>
|
||||
|
||||
<plurals name="notice_room_aliases_removed">
|
||||
<item quantity="one">%1$s removed %2$s as an address for this room.</item>
|
||||
<item quantity="other">%1$s removed %3$s as addresses for this room.</item>
|
||||
</plurals>
|
||||
|
||||
<string name="notice_room_aliases_added_and_removed">%1$s added %2$s and removed %3$s as addresses for this room.</string>
|
||||
|
||||
<string name="notice_room_canonical_alias_set">"%1$s set the main address for this room to %2$s."</string>
|
||||
<string name="notice_room_canonical_alias_unset">"%1$s removed the main address for this room."</string>
|
||||
|
||||
</resources>
|
|
@ -187,6 +187,8 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
|
|||
EventType.STATE_ROOM_NAME,
|
||||
EventType.STATE_ROOM_TOPIC,
|
||||
EventType.STATE_ROOM_MEMBER,
|
||||
EventType.STATE_ROOM_ALIASES,
|
||||
EventType.STATE_CANONICAL_ALIAS,
|
||||
EventType.STATE_HISTORY_VISIBILITY,
|
||||
EventType.CALL_INVITE,
|
||||
EventType.CALL_HANGUP,
|
||||
|
|
|
@ -45,6 +45,8 @@ class TimelineItemFactory @Inject constructor(private val messageItemFactory: Me
|
|||
EventType.STATE_ROOM_NAME,
|
||||
EventType.STATE_ROOM_TOPIC,
|
||||
EventType.STATE_ROOM_MEMBER,
|
||||
EventType.STATE_ROOM_ALIASES,
|
||||
EventType.STATE_CANONICAL_ALIAS,
|
||||
EventType.STATE_ROOM_JOIN_RULES,
|
||||
EventType.STATE_HISTORY_VISIBILITY,
|
||||
EventType.CALL_INVITE,
|
||||
|
|
|
@ -37,6 +37,8 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
|
|||
EventType.STATE_ROOM_NAME -> formatRoomNameEvent(timelineEvent.root, timelineEvent.getDisambiguatedDisplayName())
|
||||
EventType.STATE_ROOM_TOPIC -> formatRoomTopicEvent(timelineEvent.root, timelineEvent.getDisambiguatedDisplayName())
|
||||
EventType.STATE_ROOM_MEMBER -> formatRoomMemberEvent(timelineEvent.root, timelineEvent.getDisambiguatedDisplayName())
|
||||
EventType.STATE_ROOM_ALIASES -> formatRoomAliasesEvent(timelineEvent.root, timelineEvent.getDisambiguatedDisplayName())
|
||||
EventType.STATE_CANONICAL_ALIAS -> formatRoomCanonicalAliasEvent(timelineEvent.root, timelineEvent.getDisambiguatedDisplayName())
|
||||
EventType.STATE_HISTORY_VISIBILITY -> formatRoomHistoryVisibilityEvent(timelineEvent.root, timelineEvent.getDisambiguatedDisplayName())
|
||||
EventType.STATE_ROOM_TOMBSTONE -> formatRoomTombstoneEvent(timelineEvent.getDisambiguatedDisplayName())
|
||||
EventType.CALL_INVITE,
|
||||
|
@ -136,6 +138,34 @@ class NoticeEventFormatter @Inject constructor(private val sessionHolder: Active
|
|||
}
|
||||
}
|
||||
|
||||
private fun formatRoomAliasesEvent(event: Event, senderName: String?): String? {
|
||||
val eventContent: RoomAliasesContent? = event.getClearContent().toModel()
|
||||
val prevEventContent: RoomAliasesContent? = event.unsignedData?.prevContent?.toModel()
|
||||
|
||||
val addedAliases = eventContent?.aliases.orEmpty() - prevEventContent?.aliases.orEmpty()
|
||||
val removedAliases = prevEventContent?.aliases.orEmpty() - eventContent?.aliases.orEmpty()
|
||||
|
||||
return if (addedAliases.isNotEmpty() && removedAliases.isNotEmpty()) {
|
||||
sp.getString(R.string.notice_room_aliases_added_and_removed, senderName, addedAliases.joinToString(), removedAliases.joinToString())
|
||||
} else if (addedAliases.isNotEmpty()) {
|
||||
sp.getQuantityString(R.plurals.notice_room_aliases_added, addedAliases.size, senderName, addedAliases.joinToString())
|
||||
} else if (removedAliases.isNotEmpty()) {
|
||||
sp.getQuantityString(R.plurals.notice_room_aliases_removed, removedAliases.size, senderName, removedAliases.joinToString())
|
||||
} else {
|
||||
Timber.w("Alias event without any change...")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatRoomCanonicalAliasEvent(event: Event, senderName: String?): String? {
|
||||
val eventContent: RoomCanonicalAliasContent? = event.getClearContent().toModel()
|
||||
val canonicalAlias = eventContent?.canonicalAlias
|
||||
return canonicalAlias
|
||||
?.takeIf { it.isNotBlank() }
|
||||
?.let { sp.getString(R.string.notice_room_canonical_alias_set, senderName, it) }
|
||||
?: sp.getString(R.string.notice_room_canonical_alias_unset, senderName)
|
||||
}
|
||||
|
||||
private fun buildProfileNotice(event: Event, senderName: String?, eventContent: RoomMember?, prevEventContent: RoomMember?): String {
|
||||
val displayText = StringBuilder()
|
||||
// Check display name has been changed
|
||||
|
|
|
@ -33,6 +33,7 @@ import me.gujun.android.span.span
|
|||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* TODO Update this comment
|
||||
* This class compute if data of an event (such has avatar, display name, ...) should be displayed, depending on the previous event in the timeline
|
||||
*/
|
||||
class MessageInformationDataFactory @Inject constructor(private val session: Session,
|
||||
|
|
|
@ -27,6 +27,8 @@ object TimelineDisplayableEvents {
|
|||
EventType.STATE_ROOM_NAME,
|
||||
EventType.STATE_ROOM_TOPIC,
|
||||
EventType.STATE_ROOM_MEMBER,
|
||||
EventType.STATE_ROOM_ALIASES,
|
||||
EventType.STATE_CANONICAL_ALIAS,
|
||||
EventType.STATE_HISTORY_VISIBILITY,
|
||||
EventType.CALL_INVITE,
|
||||
EventType.CALL_HANGUP,
|
||||
|
|
Loading…
Reference in a new issue