mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Send read receipts as messages are displayed. (#1426)
This commit is contained in:
@@ -40,7 +40,7 @@ struct RoomHeaderView: View {
|
||||
@ViewBuilder private var roomAvatar: some View {
|
||||
LoadableAvatarImage(url: context.viewState.roomAvatarURL,
|
||||
name: context.viewState.roomTitle,
|
||||
contentID: context.viewState.roomId,
|
||||
contentID: context.viewState.roomID,
|
||||
avatarSize: .room(on: .timeline),
|
||||
imageProvider: context.imageProvider)
|
||||
.accessibilityIdentifier(A11yIdentifiers.roomScreen.avatar)
|
||||
|
||||
@@ -56,13 +56,6 @@ struct RoomScreen: View {
|
||||
}
|
||||
.interactiveQuickLook(item: $context.mediaPreviewItem)
|
||||
.track(screen: .room)
|
||||
.task(id: context.viewState.roomId) {
|
||||
// Give a couple of seconds for items to load and to see them.
|
||||
try? await Task.sleep(for: .seconds(2))
|
||||
|
||||
guard !Task.isCancelled else { return }
|
||||
context.send(viewAction: .markRoomAsRead)
|
||||
}
|
||||
.onDrop(of: ["public.item"], isTargeted: $dragOver) { providers -> Bool in
|
||||
guard let provider = providers.first,
|
||||
provider.isSupportedForPasteOrDrop else {
|
||||
@@ -89,7 +82,7 @@ struct RoomScreen: View {
|
||||
|
||||
private var timeline: some View {
|
||||
timelineSwitch
|
||||
.id(context.viewState.roomId)
|
||||
.id(context.viewState.roomID)
|
||||
.environmentObject(context)
|
||||
.environment(\.timelineStyle, context.viewState.timelineStyle)
|
||||
.environment(\.readReceiptsEnabled, context.viewState.readReceiptsEnabled)
|
||||
|
||||
@@ -48,6 +48,8 @@ class TimelineTableViewController: UIViewController {
|
||||
if timelineItemsDictionary.isEmpty {
|
||||
paginateBackwardsPublisher.send()
|
||||
}
|
||||
|
||||
sendReadReceiptIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,6 +243,15 @@ class TimelineTableViewController: UIViewController {
|
||||
|
||||
coordinator.send(viewAction: .paginateBackwards)
|
||||
}
|
||||
|
||||
private func sendReadReceiptIfNeeded() {
|
||||
guard let lastVisibleItemIndexPath = tableView.indexPathsForVisibleRows?.first,
|
||||
let lastVisibleItemTimelineID = dataSource?.itemIdentifier(for: lastVisibleItemIndexPath),
|
||||
let lastVisibleItemID = timelineItemsDictionary[lastVisibleItemTimelineID]?.identifier
|
||||
else { return }
|
||||
|
||||
coordinator.send(viewAction: .sendReadReceiptIfNeeded(lastVisibleItemID))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UITableViewDelegate
|
||||
@@ -271,6 +282,18 @@ extension TimelineTableViewController: UITableViewDelegate {
|
||||
scrollToTop(animated: true)
|
||||
return false
|
||||
}
|
||||
|
||||
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
|
||||
sendReadReceiptIfNeeded()
|
||||
}
|
||||
|
||||
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
|
||||
sendReadReceiptIfNeeded()
|
||||
}
|
||||
|
||||
func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
|
||||
sendReadReceiptIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Layout Types
|
||||
|
||||
Reference in New Issue
Block a user