Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

#2645: Only update the threadLastSeen if its later than the current one #2699

Merged

Conversation

tomwhale
Copy link

@tomwhale tomwhale commented Apr 3, 2018

Status

  • WIP
  • Ready for review
  • Needs testing

Deploy after merge (delete what needn't be deployed)

  • athena

Copy link
Contributor

@mxstbr mxstbr left a comment

Choose a reason for hiding this comment

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

Thanks so much, this is great! Just one tiny nitpick to make sure we don't encounter annoying bugs, then we'll be good 💯

@@ -29,6 +29,17 @@ export default async (job: Job<UserThreadLastSeenJobData>) => {
const record = await getUsersThread(userId, threadId);

if (record) {
if (record.lastSeen > date) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make sure to wrap these in new Date calls since they might be unix timestamps or date objects and we might be comparing proverbial apples to oranges:

if (new Date(record.lastSeen).getTime() > new Date(date).getTime())

shared/types.js Outdated
@@ -328,6 +328,7 @@ export type DBUsersThreads = {
receiveNotifications: boolean,
threadId: string,
userId: string,
lastSeen: Date,
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 be lastSeen: Date | number because I'm not certain we always store Dates in the db. (and not unix timestamps) Mind trying that and seeing if it breaks things? If it does, don't worry about it.

@mxstbr
Copy link
Contributor

mxstbr commented Apr 4, 2018

Thank you! Now flow fails due to a typing error, I think you'll just have to change athena/models/usersThreads.js:21:4 to return Promise<?DBUserThread>?

@mxstbr
Copy link
Contributor

mxstbr commented Apr 4, 2018

Hmm that Flow error is very weird. I'll try figuring it out locally, one sec.

@mxstbr
Copy link
Contributor

mxstbr commented Apr 4, 2018

I tried the same thing, but that throws another error. I think Flow wants us to explicitly check whether lastSeen is a Date before passing it to new Date?

@mxstbr
Copy link
Contributor

mxstbr commented Apr 4, 2018

Could that be it?

@tomwhale
Copy link
Author

tomwhale commented Apr 4, 2018

Sorry, only just seen your replies! I'll give that a go later.

@mxstbr
Copy link
Contributor

mxstbr commented Apr 4, 2018

No worries—if you can't fix that flow error just mark it as // $FlowIssue, I tried for a bit but have no clue how to fix it either 😕

@brianlovin
Copy link
Contributor

brianlovin commented Apr 4, 2018

The flow issue here is pretty weird, I dug into it last night. Basically if we change the type def to the callsite of the getUsersThread function, it works.

Before:

const record = await getUsersThread(userId, threadId);

After:

const record: ?DBUsersThreads = await getUsersThread(userId, threadId);

Then there will be a flow issue on line 39 where it cant coerce record.lastSeen to a string, so just add a .toString() there :)

@brianlovin
Copy link
Contributor

Ref: facebook/flow#5294

@brianlovin
Copy link
Contributor

Thanks for the fixes! We're working on the failing e2e tests in #2674

@brianlovin brianlovin merged commit a26d014 into withspectrum:alpha Apr 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants