Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIS-982] Crash when thread root message is not loaded #1263

Merged
merged 2 commits into from
Jul 9, 2021

Conversation

evsaev
Copy link
Contributor

@evsaev evsaev commented Jul 9, 2021

This PR fixes crash on ChatThreadVC when root message is not loaded

@evsaev evsaev added the 🐞 Bug An issue or PR related to a bug label Jul 9, 2021
@evsaev evsaev requested a review from VojtaStavik July 9, 2021 11:40
@evsaev evsaev self-assigned this Jul 9, 2021
Comment on lines 392 to 417
let indexPath = IndexPath(row: messageController.replies.count, section: 0)

let listChange: ListChange<_ChatMessage<ExtraData>>
switch change {
case .create(let item):
listChange = .insert(item, index: indexPath)
case .update(let item):
listChange = .update(item, index: indexPath)
case .remove(let item):
listChange = .remove(item, index: indexPath)
}

updateMessages(with: [listChange])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we were supposed to call reloadData but didChangeMessage is triggered when thread root message is updated which can happen multiple times. Reloading single cell sounds better (the index calculations are straightforward since thread root is always at the end of message list)

Comment on lines +217 to +236
let replies = Array(messageController.replies)

if let threadRootMessage = messageController.message {
return replies + [threadRootMessage]
} else {
return replies
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thread replies are evaluated from DTOs when converting messageController.replies to an array. The solution I was thinking of is appending thread root message to replies: LazyCachedMapCollection but seems it's not feasible 🤔

To not break the indexes of lazy map we would have to modify the source collection of message DTOs and a cache. It's quite straightforward with cache but the information about source collection Element type is available only in init and doesn't get stored for later use.

Don't see how we can handle this nicely on UI side (on LLC side we could tweak a replies observer to also include a thread root though)

@evsaev evsaev force-pushed the CIS-982-crash-when-thread-root-not-loaded branch from fa5c12e to 6926a83 Compare July 9, 2021 12:04
Copy link
Contributor

@VojtaStavik VojtaStavik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Your comments on this PR are valuable and I think they actually should be included in the source code, rather than here ;-)

@codecov-commenter
Copy link

codecov-commenter commented Jul 9, 2021

Codecov Report

Merging #1263 (7f31131) into main (959df0b) will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1263      +/-   ##
==========================================
- Coverage   91.40%   91.38%   -0.02%     
==========================================
  Files         219      219              
  Lines        9419     9421       +2     
==========================================
  Hits         8609     8609              
- Misses        810      812       +2     
Flag Coverage Δ
llc-tests 91.22% <ø> (-0.02%) ⬇️
llc-tests-ios12 88.07% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
Sources/StreamChat/Deprecations.swift 16.66% <0.00%> (-3.34%) ⬇️
Sources/StreamChat/Models/Channel.swift 78.43% <0.00%> (-1.17%) ⬇️
Sources/StreamChat/Database/DTOs/ChannelDTO.swift 99.06% <0.00%> (-0.01%) ⬇️
Sources/StreamChat/Models/Message.swift
...es/ChannelMemberTypingStateUpdaterMiddleware.swift
...Middlewares/UserTypingStateUpdaterMiddleware.swift 100.00% <0.00%> (ø)
Sources/StreamChat/Models/ChatMessage.swift 91.80% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 959df0b...7f31131. Read the comment docs.

@evsaev evsaev force-pushed the CIS-982-crash-when-thread-root-not-loaded branch from 6926a83 to 7f31131 Compare July 9, 2021 13:51
@evsaev evsaev merged commit 6a3a572 into main Jul 9, 2021
@evsaev evsaev deleted the CIS-982-crash-when-thread-root-not-loaded branch July 9, 2021 14:19
VojtaStavik pushed a commit that referenced this pull request Jul 9, 2021
* Handle root message not loaded when thread is opened

* Update CHANGELOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 Bug An issue or PR related to a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants