Text Channel (UI)
Message Grouping Algorithm
Within this algorithm, tail refers to whether the message omits displaying the user's avatar / username.
This algorithm expects that the rendering of the output list is reversed, if you need it from oldest to newest: either reverse at the end or adapt the logic.
- Let L be the list of messages ordered from newest to oldest
- Let E be the list of elements to be rendered
- For each message M in L:
- Let tail be true
- Let date be null
- Let next be the next item in list L
- If next is not null:
- Let adate and bdate be the times the message M and the next message were created respectively
- If adate and bdate are not the same day:
- Let date be adate
- Let tail be false if one of the following conditions is satisfied:
- Message M and last do not have the same author
- The difference between bdate and adate is equal to or over 7 minutes
- The masquerades for message M and last do not match
- Message M or last is a system message
- Message M replies to one or more messages
- Else if next is null:
- Let tail be false
- Push the message to list E (type id: 0; cache key: message id:tail)
- If date is not null:
- Push date formatted as "MMMM D, YYYY" to list E (type id: 1; cache key: formatted date)
Note: the Revolt client also caches the objects produced for list E by pushing each object into a Map by their given cache key above, then retrieving them the next time the code is run OR creating a new object if one is not present. This prevents Solid.js from completely rebuilding the DOM whenever the message list updates.