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-780] Update channel's lastMessageAt when saving Message #949

Merged

Conversation

skorepak
Copy link
Contributor

@skorepak skorepak commented Apr 1, 2021

Description of the pull request

update the channelDTO.lastMessageAt based on this recommendation https://getstream.slack.com/archives/CE5N802GP/p1617215048066400?thread_ts=1617214945.066200&cid=CE5N802GP

Add calculation of channelDTO.defaultSortingAt to channelDTO.willSave to update this walue every time the messages are updated.

Links

https://stream-io.atlassian.net/browse/CIS-780

@@ -273,8 +273,6 @@ extension NSManagedObjectContext: MessageDatabaseSession {
message.user = currentUserDTO.user
message.channel = channelDTO

// We should update the channel dates so the list of channels ordering is updated.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This TODO looked like related to this issue

@@ -66,6 +66,11 @@ class ChannelDTO: NSManagedObject {
$0.didChangeValue(for: \.id)
}
}

let newAt = lastMessageAt ?? createdAt
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The task says to move the calculation, but removing the calculation from saveChannel(payload:) was not possible as the parameter is required.

Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to add some description of why is this here + some better naming for the variables would be cool, too

@skorepak skorepak changed the title Update channel's lastMessageAt when saving Message [CIS-789] Update channel's lastMessageAt when saving Message Apr 1, 2021
@skorepak skorepak changed the title [CIS-789] Update channel's lastMessageAt when saving Message [CIS-780] Update channel's lastMessageAt when saving Message Apr 1, 2021
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.

Yep 👍 Let's add tests and see if everything is ok

Sources/StreamChat/Database/DTOs/MessageDTO.swift Outdated Show resolved Hide resolved
Sources/StreamChat/Database/DTOs/MessageDTO.swift Outdated Show resolved Hide resolved
@@ -66,6 +66,11 @@ class ChannelDTO: NSManagedObject {
$0.didChangeValue(for: \.id)
}
}

let newAt = lastMessageAt ?? createdAt
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to add some description of why is this here + some better naming for the variables would be cool, too

@skorepak skorepak force-pushed the CIS-780-Update-channels-lastMessageAt-when-saving-Message branch from f41a3b4 to 4f41acc Compare April 7, 2021 10:45
@codecov
Copy link

codecov bot commented Apr 7, 2021

Codecov Report

Merging #949 (e1995c2) into main (460d130) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #949   +/-   ##
=======================================
  Coverage   89.44%   89.44%           
=======================================
  Files         203      203           
  Lines        8326     8330    +4     
=======================================
+ Hits         7447     7451    +4     
  Misses        879      879           
Flag Coverage Δ
llc-tests 89.44% <100.00%> (+<0.01%) ⬆️
llc-tests-ios12 85.49% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
Sources/StreamChat/Database/DTOs/ChannelDTO.swift 100.00% <100.00%> (ø)
Sources/StreamChat/Database/DTOs/MessageDTO.swift 95.67% <100.00%> (-0.02%) ⬇️

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 460d130...e1995c2. Read the comment docs.

@skorepak skorepak force-pushed the CIS-780-Update-channels-lastMessageAt-when-saving-Message branch 2 times, most recently from c846065 to a9c9cf0 Compare April 7, 2021 14:17
@skorepak skorepak force-pushed the CIS-780-Update-channels-lastMessageAt-when-saving-Message branch from a9c9cf0 to 74b4f2d Compare April 8, 2021 08:50
@skorepak skorepak marked this pull request as ready for review April 8, 2021 09:24
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.

Great 👍 Please also add a change log with a user-facing description of the change.

Comment on lines -63 to +71
static var unique: Date { Date(timeIntervalSince1970: .random(in: 1...1_500_000_000)) }
static var unique: Date { Date(timeIntervalSince1970: .random(in: 1_000_000...1_500_000_000)) }

static func unique(before date: Date) -> Date {
Date(timeIntervalSince1970: .random(in: 1..<date.timeIntervalSince1970))
}

static func unique(after date: Date) -> Date {
Date(timeIntervalSince1970: .random(in: (date.timeIntervalSince1970 + 1)...1_500_000_000))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This should ideally go into a standalone commit

@skorepak skorepak merged commit e8f0cb1 into main Apr 8, 2021
@skorepak skorepak deleted the CIS-780-Update-channels-lastMessageAt-when-saving-Message branch April 8, 2021 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants