discourse/plugins/chat/app/serializers/chat/last_message_serializer.rb
Martin Brennan 72bbc2fa8a
FIX: created_at datetime format inconsistencies in chat (#22611)
This commit attempts to fix an issue where we are ending
up with bad created_at date formats for last messages, which
is breaking the DM sort order and sometimes causing DM channels
to fall off the list, or show "Invalid date" on mobile.

I have not been able to consistently reproduce these issues
locally, however the serialzier for the channels index uses
MultiJSON.dump() and the Chat::Publisher uses .to_json, both of
which format created_at differently for messages.

The former is `2023-07-05T06:53:25.977Z` (iso8601).

The latter is `2023-07-14 03:59:22 UTC` (.to_s default).

Since we are doing comparison and sorting of these dates on the UI
we need consistent formatting for the JS Date parsers (and moment)
to deal with.

If the issue still occurs after this we can investigate further.
2023-07-14 16:05:01 +10:00

16 lines
519 B
Ruby

# frozen_string_literal: true
module Chat
class LastMessageSerializer < ::ApplicationSerializer
# NOTE: The channel last message does not need to serialize relations
# etc. at this point in time, since the only thing we are using is
# created_at. In future we may want to serialize more for this, at which
# point we need to check existing code so we don't introduce N1s.
attributes *Chat::MessageSerializer::BASIC_ATTRIBUTES
def created_at
object.created_at.iso8601
end
end
end