Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
The Message
is a single displayed event in a Channel. All Messages
have a date/time, and messages that represent posts to the channel
have a (hash) ID, and displayable text, along with other attributes.
All Messages are sorted chronologically. There is no assumption that the server datetime is synchronized with the local datetime, so all of the Message ordering uses the server's date/time.
The mattermost-api retrieves a Post
from the server, briefly encodes
the useful portions of that as a ClientPost
object and then converts
it to a Message
inserting this result it into the collection of
Messages associated with a Channel. The PostID of the message
uniquely identifies that message and can be used to interact with the
server for subsequent operations relative to that message's Post
.
The date/time associated with these messages is generated by the
server.
There are also "messages" generated directly by the Matterhorn client which can be used to display additional, client-related information to the user. Examples of these client messages are: date boundaries, the "new messages" marker, errors from invoking the browser, etc. These client-generated messages will have a date/time although it is locally generated (usually by relation to an associated Post).
Most other Matterhorn operations primarily are concerned with
user-posted messages (case mMessageId of Just _
or case mType of CP
_
), but others will include client-generated messages (case mMessageId
of Nothing
or case mType of C _
).
Synopsis
- data Message = Message {
- _mText :: Blocks
- _mMarkdownSource :: Text
- _mUser :: UserRef
- _mDate :: ServerTime
- _mType :: MessageType
- _mPending :: Bool
- _mDeleted :: Bool
- _mAttachments :: Seq Attachment
- _mInReplyToMsg :: ReplyState
- _mMessageId :: Maybe MessageId
- _mReactions :: Map Text (Set UserId)
- _mOriginalPost :: Maybe Post
- _mFlagged :: Bool
- _mPinned :: Bool
- _mChannelId :: Maybe ChannelId
- isDeletable :: Message -> Bool
- isReplyable :: Message -> Bool
- isReactable :: Message -> Bool
- isEditable :: Message -> Bool
- isReplyTo :: PostId -> Message -> Bool
- isGap :: Message -> Bool
- isFlaggable :: Message -> Bool
- isPinnable :: Message -> Bool
- isEmote :: Message -> Bool
- isJoinLeave :: Message -> Bool
- isTransition :: Message -> Bool
- isNewMessagesTransition :: Message -> Bool
- mText :: Lens' Message Blocks
- mUser :: Lens' Message UserRef
- mDate :: Lens' Message ServerTime
- mType :: Lens' Message MessageType
- mPending :: Lens' Message Bool
- mDeleted :: Lens' Message Bool
- mPinned :: Lens' Message Bool
- mAttachments :: Lens' Message (Seq Attachment)
- mInReplyToMsg :: Lens' Message ReplyState
- mMessageId :: Lens' Message (Maybe MessageId)
- mReactions :: Lens' Message (Map Text (Set UserId))
- mFlagged :: Lens' Message Bool
- mOriginalPost :: Lens' Message (Maybe Post)
- mChannelId :: Lens' Message (Maybe ChannelId)
- mMarkdownSource :: Lens' Message Text
- isBotMessage :: Message -> Bool
- data MessageType
- data ThreadState
- data MentionedUser
- isPostMessage :: Message -> Bool
- messagePostId :: Message -> Maybe PostId
- data UserRef
- data ReplyState
- clientMessageToMessage :: ClientMessage -> Message
- clientPostToMessage :: ClientPost -> (Message, Set MentionedUser)
- clientPostReactionUserIds :: ClientPost -> Set UserId
- newMessageOfType :: Text -> MessageType -> ServerTime -> Message
- type Messages = ChronologicalMessages
- type ChronologicalMessages = DirectionalSeq Chronological Message
- type RetrogradeMessages = DirectionalSeq Retrograde Message
- class MessageOps a where
- addMessage :: Message -> a -> a
- noMessages :: Messages
- messagesLength :: DirectionalSeq seq a -> Int
- filterMessages :: SeqDirection seq => (a -> Bool) -> DirectionalSeq seq a -> DirectionalSeq seq a
- reverseMessages :: Messages -> RetrogradeMessages
- unreverseMessages :: RetrogradeMessages -> Messages
- splitMessages :: Maybe MessageId -> DirectionalSeq Chronological (Message, ThreadState) -> (Maybe (Message, ThreadState), (DirectionalSeq Retrograde (Message, ThreadState), DirectionalSeq Chronological (Message, ThreadState)))
- splitDirSeqOn :: SeqDirection d => (a -> Bool) -> DirectionalSeq d a -> (Maybe a, (DirectionalSeq (ReverseDirection d) a, DirectionalSeq d a))
- chronologicalMsgsWithThreadStates :: Messages -> DirectionalSeq Chronological (Message, ThreadState)
- retrogradeMsgsWithThreadStates :: RetrogradeMessages -> DirectionalSeq Retrograde (Message, ThreadState)
- findMessage :: MessageId -> Messages -> Maybe Message
- getRelMessageId :: SeqDirection dir => Maybe MessageId -> DirectionalSeq dir Message -> Maybe Message
- messagesHead :: SeqDirection seq => DirectionalSeq seq a -> Maybe a
- messagesDrop :: SeqDirection seq => Int -> DirectionalSeq seq a -> DirectionalSeq seq a
- getNextMessage :: Maybe MessageId -> Messages -> Maybe Message
- getPrevMessage :: Maybe MessageId -> Messages -> Maybe Message
- getNextMessageId :: Maybe MessageId -> Messages -> Maybe MessageId
- getPrevMessageId :: Maybe MessageId -> Messages -> Maybe MessageId
- getNextPostId :: Maybe PostId -> Messages -> Maybe PostId
- getPrevPostId :: Maybe PostId -> Messages -> Maybe PostId
- getEarliestPostMsg :: Messages -> Maybe Message
- getLatestPostMsg :: Messages -> Maybe Message
- getEarliestSelectableMessage :: Messages -> Maybe Message
- getLatestSelectableMessage :: Messages -> Maybe Message
- findLatestUserMessage :: (Message -> Bool) -> Messages -> Maybe Message
- messagesAfter :: ServerTime -> Messages -> Messages
- removeMatchesFromSubset :: (Message -> Bool) -> Maybe MessageId -> Maybe MessageId -> Messages -> (Messages, Messages)
- withFirstMessage :: SeqDirection dir => (Message -> r) -> DirectionalSeq dir Message -> Maybe r
- msgURLs :: Message -> Seq LinkChoice
- data LinkChoice = LinkChoice ServerTime UserRef (Maybe Inlines) LinkTarget
- linkUser :: Lens' LinkChoice UserRef
- linkTarget :: Lens' LinkChoice LinkTarget
- linkTime :: Lens' LinkChoice ServerTime
- linkLabel :: Lens' LinkChoice (Maybe Inlines)
Message and operations on a single Message
A Message
is any message we might want to render, either from
Mattermost itself or from a client-internal source.
Message | |
|
Instances
isDeletable :: Message -> Bool Source #
isReplyable :: Message -> Bool Source #
isReactable :: Message -> Bool Source #
isEditable :: Message -> Bool Source #
isFlaggable :: Message -> Bool Source #
isPinnable :: Message -> Bool Source #
isJoinLeave :: Message -> Bool Source #
isTransition :: Message -> Bool Source #
mAttachments :: Lens' Message (Seq Attachment) Source #
isBotMessage :: Message -> Bool Source #
data MessageType Source #
A Message
is the representation we use for storage and
rendering, so it must be able to represent either a
post from Mattermost or an internal message. This represents
the union of both kinds of post types.
Instances
Show MessageType Source # | |
Defined in Matterhorn.Types.Messages showsPrec :: Int -> MessageType -> ShowS # show :: MessageType -> String # showList :: [MessageType] -> ShowS # | |
Eq MessageType Source # | |
Defined in Matterhorn.Types.Messages (==) :: MessageType -> MessageType -> Bool # (/=) :: MessageType -> MessageType -> Bool # |
data ThreadState Source #
The state of a message's thread context.
NoThread | The message is not in a thread at all. |
InThreadShowParent | The message is in a thread, and the thread's root message (parent) should be displayed above this message. |
InThread | The message is in a thread but the thread's root message should not be displayed above this message. |
Instances
Show ThreadState Source # | |
Defined in Matterhorn.Types.Messages showsPrec :: Int -> ThreadState -> ShowS # show :: ThreadState -> String # showList :: [ThreadState] -> ShowS # | |
Eq ThreadState Source # | |
Defined in Matterhorn.Types.Messages (==) :: ThreadState -> ThreadState -> Bool # (/=) :: ThreadState -> ThreadState -> Bool # |
data MentionedUser Source #
Instances
Show MentionedUser Source # | |
Defined in Matterhorn.Types.Messages showsPrec :: Int -> MentionedUser -> ShowS # show :: MentionedUser -> String # showList :: [MentionedUser] -> ShowS # | |
Eq MentionedUser Source # | |
Defined in Matterhorn.Types.Messages (==) :: MentionedUser -> MentionedUser -> Bool # (/=) :: MentionedUser -> MentionedUser -> Bool # | |
Ord MentionedUser Source # | |
Defined in Matterhorn.Types.Messages compare :: MentionedUser -> MentionedUser -> Ordering # (<) :: MentionedUser -> MentionedUser -> Bool # (<=) :: MentionedUser -> MentionedUser -> Bool # (>) :: MentionedUser -> MentionedUser -> Bool # (>=) :: MentionedUser -> MentionedUser -> Bool # max :: MentionedUser -> MentionedUser -> MentionedUser # min :: MentionedUser -> MentionedUser -> MentionedUser # |
isPostMessage :: Message -> Bool Source #
There may be no user (usually an internal message), a reference to a user (by Id), or the server may have supplied a specific username (often associated with bots). The boolean flag indicates whether the user reference is for a message from a bot.
data ReplyState Source #
The ReplyState
of a message represents whether a message
is a reply, and if so, to what message
Instances
Show ReplyState Source # | |
Defined in Matterhorn.Types.Messages showsPrec :: Int -> ReplyState -> ShowS # show :: ReplyState -> String # showList :: [ReplyState] -> ShowS # | |
Eq ReplyState Source # | |
Defined in Matterhorn.Types.Messages (==) :: ReplyState -> ReplyState -> Bool # (/=) :: ReplyState -> ReplyState -> Bool # |
clientMessageToMessage :: ClientMessage -> Message Source #
Convert a ClientMessage
to a Message
. A ClientMessage
is
one that was generated by the Matterhorn client and which the
server knows nothing about. For example, an error message
associated with passing a link to the local browser.
clientPostToMessage :: ClientPost -> (Message, Set MentionedUser) Source #
Builds a message from a ClientPost and also returns the set of usernames mentioned in the text of the message.
newMessageOfType :: Text -> MessageType -> ServerTime -> Message Source #
Message Collections
type Messages = ChronologicalMessages Source #
type ChronologicalMessages = DirectionalSeq Chronological Message Source #
A wrapper for an ordered, unique list of Message
values.
This type has (and promises) the following instances: Show, Functor, Monoid, Foldable, Traversable
type RetrogradeMessages = DirectionalSeq Retrograde Message Source #
There are also cases where the list of Message
values are kept
in reverse order (most recent -> oldest); these cases are
represented by the RetrogradeMessages
type.
class MessageOps a where Source #
addMessage :: Message -> a -> a Source #
addMessage inserts a date in proper chronological order, with the following extra functionality: * no duplication (by PostId) * no duplication (adjacent UnknownGap entries)
Instances
messagesLength :: DirectionalSeq seq a -> Int Source #
filterMessages :: SeqDirection seq => (a -> Bool) -> DirectionalSeq seq a -> DirectionalSeq seq a Source #
reverseMessages :: Messages -> RetrogradeMessages Source #
Reverse the order of the messages
unreverseMessages :: RetrogradeMessages -> Messages Source #
Unreverse the order of the messages
splitMessages :: Maybe MessageId -> DirectionalSeq Chronological (Message, ThreadState) -> (Maybe (Message, ThreadState), (DirectionalSeq Retrograde (Message, ThreadState), DirectionalSeq Chronological (Message, ThreadState))) Source #
Searches for the specified MessageId and returns a tuple where the first element is the Message associated with the MessageId (if it exists), and the second element is another tuple: the first element of the second is all the messages from the beginning of the list to the message just before the MessageId message (or all messages if not found) *in reverse order*, and the second element of the second are all the messages that follow the found message (none if the message was never found) in *forward* order.
splitDirSeqOn :: SeqDirection d => (a -> Bool) -> DirectionalSeq d a -> (Maybe a, (DirectionalSeq (ReverseDirection d) a, DirectionalSeq d a)) Source #
chronologicalMsgsWithThreadStates :: Messages -> DirectionalSeq Chronological (Message, ThreadState) Source #
retrogradeMsgsWithThreadStates :: RetrogradeMessages -> DirectionalSeq Retrograde (Message, ThreadState) Source #
findMessage :: MessageId -> Messages -> Maybe Message Source #
findMessage searches for a specific message as identified by the PostId. The search starts from the most recent messages because that is the most likely place the message will occur.
getRelMessageId :: SeqDirection dir => Maybe MessageId -> DirectionalSeq dir Message -> Maybe Message Source #
messagesHead :: SeqDirection seq => DirectionalSeq seq a -> Maybe a Source #
messagesDrop :: SeqDirection seq => Int -> DirectionalSeq seq a -> DirectionalSeq seq a Source #
getNextMessage :: Maybe MessageId -> Messages -> Maybe Message Source #
Look forward for the first Message with an ID that follows the specified Id and return it. If no input Id supplied, get the latest (most recent chronologically) Message in the input set.
getPrevMessage :: Maybe MessageId -> Messages -> Maybe Message Source #
Look backward for the first Message with an ID that follows the specified MessageId and return it. If no input MessageId supplied, get the latest (most recent chronologically) Message in the input set.
getNextMessageId :: Maybe MessageId -> Messages -> Maybe MessageId Source #
Look forward for the first Message with an ID that follows the specified MessageId and return that found Message's ID; if no input MessageId is specified, return the latest (most recent chronologically) MessageId (if any) in the input set.
getPrevMessageId :: Maybe MessageId -> Messages -> Maybe MessageId Source #
Look backwards for the first Message with an ID that comes before the specified MessageId and return that found Message's ID; if no input MessageId is specified, return the latest (most recent chronologically) MessageId (if any) in the input set.
getNextPostId :: Maybe PostId -> Messages -> Maybe PostId Source #
Look forward for the first Message with an ID that follows the specified PostId and return that found Message's PostID; if no input PostId is specified, return the latest (most recent chronologically) PostId (if any) in the input set.
getPrevPostId :: Maybe PostId -> Messages -> Maybe PostId Source #
Look backwards for the first Post with an ID that comes before the specified PostId.
getEarliestPostMsg :: Messages -> Maybe Message Source #
Find the earliest message that is a Post (as opposed to a local message) (if any).
getLatestPostMsg :: Messages -> Maybe Message Source #
Find the most recent message that is a Post (as opposed to a local message) (if any).
getEarliestSelectableMessage :: Messages -> Maybe Message Source #
Find the oldest message that is a message with an ID.
getLatestSelectableMessage :: Messages -> Maybe Message Source #
Find the most recent message that is a message with an ID.
findLatestUserMessage :: (Message -> Bool) -> Messages -> Maybe Message Source #
Find the most recent message that is a message posted by a user that matches the test (if any), skipping local client messages and any user event that is not a message (i.e. find a normal message or an emote).
Operations on any Message type
messagesAfter :: ServerTime -> Messages -> Messages Source #
Return all messages that were posted after the specified date/time.
removeMatchesFromSubset :: (Message -> Bool) -> Maybe MessageId -> Maybe MessageId -> Messages -> (Messages, Messages) Source #
Removes any Messages (all types) for which the predicate is true
from the specified subset of messages (identified by a starting and
ending MessageId, inclusive) and returns the resulting list (from
start to finish, irrespective of firstId
and lastId
) and the
list of removed items.
start | end | operates-on | (test) case --------------------------------------------------------|------------- Nothing | Nothing | entire list | C1 Nothing | Just found | start --> found] | C2 Nothing | Just missing | nothing [suggest invalid] | C3 Just found | Nothing | [found --> end | C4 Just found | Just found | [found --> found] | C5 Just found | Just missing | [found --> end | C6 Just missing | Nothing | nothing [suggest invalid] | C7 Just missing | Just found | start --> found] | C8 Just missing | Just missing | nothing [suggest invalid] | C9
removeMatchesFromSubset matchPred fromId toId msgs = (remaining, removed)
withFirstMessage :: SeqDirection dir => (Message -> r) -> DirectionalSeq dir Message -> Maybe r Source #
Performs an operation on the first Message, returning just the result of that operation, or Nothing if there were no messages. Note that the message is not necessarily a posted user message.
data LinkChoice Source #
This type represents links to things in the 'open links' view.
Instances
Show LinkChoice Source # | |
Defined in Matterhorn.Types.Messages showsPrec :: Int -> LinkChoice -> ShowS # show :: LinkChoice -> String # showList :: [LinkChoice] -> ShowS # | |
Eq LinkChoice Source # | |
Defined in Matterhorn.Types.Messages (==) :: LinkChoice -> LinkChoice -> Bool # (/=) :: LinkChoice -> LinkChoice -> Bool # |