matterhorn-90000.0.0: Terminal client for the Mattermost chat system
Safe HaskellSafe-Inferred
LanguageHaskell2010

Matterhorn.Types.Messages

Description

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

Message and operations on a single Message

data Message Source #

A Message is any message we might want to render, either from Mattermost itself or from a client-internal source.

Instances

Instances details
Show Message Source # 
Instance details

Defined in Matterhorn.Types.Messages

Eq Message Source # 
Instance details

Defined in Matterhorn.Types.Messages

Methods

(==) :: Message -> Message -> Bool #

(/=) :: Message -> Message -> Bool #

MessageOps ChronologicalMessages Source # 
Instance details

Defined in Matterhorn.Types.Messages

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

Instances details
Show MessageType Source # 
Instance details

Defined in Matterhorn.Types.Messages

Eq MessageType Source # 
Instance details

Defined in Matterhorn.Types.Messages

data ThreadState Source #

The state of a message's thread context.

Constructors

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

Instances details
Show ThreadState Source # 
Instance details

Defined in Matterhorn.Types.Messages

Eq ThreadState Source # 
Instance details

Defined in Matterhorn.Types.Messages

data UserRef 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.

Instances

Instances details
Show UserRef Source # 
Instance details

Defined in Matterhorn.Types.Messages

Eq UserRef Source # 
Instance details

Defined in Matterhorn.Types.Messages

Methods

(==) :: UserRef -> UserRef -> Bool #

(/=) :: UserRef -> UserRef -> Bool #

Ord UserRef Source # 
Instance details

Defined in Matterhorn.Types.Messages

data ReplyState Source #

The ReplyState of a message represents whether a message is a reply, and if so, to what message

Constructors

NotAReply 
InReplyTo PostId 

Instances

Instances details
Show ReplyState Source # 
Instance details

Defined in Matterhorn.Types.Messages

Eq ReplyState Source # 
Instance details

Defined in Matterhorn.Types.Messages

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.

Message Collections

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 #

Methods

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)

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.

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.

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

Instances details
Show LinkChoice Source # 
Instance details

Defined in Matterhorn.Types.Messages

Eq LinkChoice Source # 
Instance details

Defined in Matterhorn.Types.Messages