Skip to content

Commit

Permalink
Filtered out unwanted state events for DMs (#2361)
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 authored Jan 19, 2024
1 parent a64ad5d commit faeab89
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,10 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
// Otherwise check if we need to add anything to the top of the timeline.
switch timelineProvider.backPaginationState {
case .timelineStartReached:
let timelineStart = TimelineStartRoomTimelineItem(name: roomProxy.displayName ?? roomProxy.name)
newTimelineItems.insert(timelineStart, at: 0)
if !roomProxy.isEncryptedOneToOneRoom {
let timelineStart = TimelineStartRoomTimelineItem(name: roomProxy.displayName ?? roomProxy.name)
newTimelineItems.insert(timelineStart, at: 0)
}
canBackPaginate = false
case .paginating:
newTimelineItems.insert(PaginationIndicatorRoomTimelineItem(), at: 0)
Expand All @@ -317,7 +319,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
private func buildTimelineItem(for itemProxy: TimelineItemProxy) -> RoomTimelineItemProtocol? {
switch itemProxy {
case .event(let eventTimelineItem):
let timelineItem = timelineItemFactory.buildTimelineItem(for: eventTimelineItem)
let timelineItem = timelineItemFactory.buildTimelineItem(for: eventTimelineItem, isDM: roomProxy.isEncryptedOneToOneRoom)

// When backup is enabled just show the timeline items, they will most likely
// resolve eventually. If we don't know the backup state then we assume the session is not verified yet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
self.stateEventStringBuilder = stateEventStringBuilder
}

func buildTimelineItem(for eventItemProxy: EventTimelineItemProxy) -> RoomTimelineItemProtocol? {
func buildTimelineItem(for eventItemProxy: EventTimelineItemProxy, isDM: Bool) -> RoomTimelineItemProtocol? {
let isOutgoing = eventItemProxy.isOwn

switch eventItemProxy.content.kind() {
Expand All @@ -55,8 +55,14 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol {
case .message:
return buildMessageTimelineItem(eventItemProxy, isOutgoing)
case .state(_, let content):
if isDM, content == .roomCreate {
return nil
}
return buildStateTimelineItem(for: eventItemProxy, state: content, isOutgoing: isOutgoing)
case .roomMembership(userId: let userID, change: let change):
if isDM, change == .joined, userID == self.userID {
return nil
}
return buildStateMembershipChangeTimelineItem(for: eventItemProxy, member: userID, membershipChange: change, isOutgoing: isOutgoing)
case .profileChange(let displayName, let prevDisplayName, let avatarUrl, let prevAvatarUrl):
return buildStateProfileChangeTimelineItem(for: eventItemProxy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ import Foundation

@MainActor
protocol RoomTimelineItemFactoryProtocol {
func buildTimelineItem(for eventItemProxy: EventTimelineItemProxy) -> RoomTimelineItemProtocol?
func buildTimelineItem(for eventItemProxy: EventTimelineItemProxy, isDM: Bool) -> RoomTimelineItemProtocol?
}
1 change: 1 addition & 0 deletions changelog.d/2329.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed unnecessary state events for DMs.

0 comments on commit faeab89

Please sign in to comment.