diff --git a/internal/payload/incoming/messages.go b/internal/payload/incoming/messages.go index ba56136c1..e8e326bda 100644 --- a/internal/payload/incoming/messages.go +++ b/internal/payload/incoming/messages.go @@ -23,6 +23,9 @@ type ( FirstID uint64 `json:"firstID,string"` LastID uint64 `json:"lastID,string"` RepliesTo uint64 `json:"repliesTo,string"` + + PinnedOnly bool `json:pinned` + BookmarkedOnly bool `json:bookmarked` } MessageThreads struct { diff --git a/sam/repository/message.go b/sam/repository/message.go index 78a21d87f..db609cca8 100644 --- a/sam/repository/message.go +++ b/sam/repository/message.go @@ -139,6 +139,16 @@ func (r *message) FindMessages(filter *types.MessageFilter) (types.MessageSet, e params = append(params, filter.ToID) } + if filter.BookmarkedOnly || filter.PinnedOnly { + sql += " AND id IN (SELECT rel_message FROM message_flags WHERE flag = ?) " + + if filter.PinnedOnly { + params = append(params, types.MessageFlagBookmarkedMessage) + } else { + params = append(params, types.MessageFlagPinnedToChannel) + } + } + sql += " AND rel_channel IN " + sqlChannelAccess params = append(params, filter.CurrentUserID, types.ChannelTypePublic) diff --git a/sam/types/message.go b/sam/types/message.go index 69bcdca06..acb8e8328 100644 --- a/sam/types/message.go +++ b/sam/types/message.go @@ -54,6 +54,9 @@ type ( FromID uint64 ToID uint64 + PinnedOnly bool + BookmarkedOnly bool + Limit uint }