Direct Message Look-Up (interval)

A deep dive into all messages sent and received by a user within the given timeframe.

-- [params]
-- user_id :user
-- string :interval = 1 month

SELECT 
    chat_channel_id,
    user_id,
    message,
    created_at AS reltime$time,
    created_at 
FROM chat_messages
WHERE chat_channel_id IN (
       SELECT cc.id
       FROM chat_channels cc
       JOIN chat_messages cm ON cm.chat_channel_id = cc.id
       WHERE cc.chatable_type = 'DirectMessage'
       AND cm.user_id = :user
   )
AND created_at::date > CURRENT_TIMESTAMP - INTERVAL :interval
ORDER BY chat_channel_id DESC, created_at ASC
1 Like

This one is still functional, but I have spotted that it needs a tiny tweak to account for some table changes that were made a while back. It only affects the channel ids though, so not a breaking issue.