diff options
author | Joe Crayne <joe@jerkface.net> | 2018-11-14 01:28:47 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-11-14 01:29:41 -0500 |
commit | 2049cc83b60dca41f636190f87cb1f21707f3530 (patch) | |
tree | 2ef910cdd207229b675a38411abfd47bf074cb6b /Presence/Stanza | |
parent | 2a0902701e7c806c2cfd2561d8af1f56539e8811 (diff) |
MUC: It works.
Diffstat (limited to 'Presence/Stanza')
-rw-r--r-- | Presence/Stanza/Build.hs | 22 | ||||
-rw-r--r-- | Presence/Stanza/Parse.hs | 9 | ||||
-rw-r--r-- | Presence/Stanza/Types.hs | 55 |
3 files changed, 79 insertions, 7 deletions
diff --git a/Presence/Stanza/Build.hs b/Presence/Stanza/Build.hs index e02684f5..16552428 100644 --- a/Presence/Stanza/Build.hs +++ b/Presence/Stanza/Build.hs | |||
@@ -19,24 +19,34 @@ import LockedChan | |||
19 | import Stanza.Types | 19 | import Stanza.Types |
20 | 20 | ||
21 | makeMessage :: Text -> Text -> Text -> Text -> IO Stanza | 21 | makeMessage :: Text -> Text -> Text -> Text -> IO Stanza |
22 | makeMessage namespace from to bod = | 22 | makeMessage namespace from to bod = makeMessageEx namespace from to NormalMsg bod |
23 | |||
24 | makeMessageEx :: Text -> Text -> Text -> MessageType -> Text -> IO Stanza | ||
25 | makeMessageEx namespace from to msgtyp bod = | ||
23 | stanzaFromList typ | 26 | stanzaFromList typ |
24 | $ [ EventBeginElement (mkname namespace "message") | 27 | $ [ EventBeginElement (mkname namespace "message") |
25 | [ attr "from" from | 28 | $ addMessageType msgtyp |
26 | , attr "to" to | 29 | [ attr "from" from |
27 | ] | 30 | , attr "to" to |
31 | ] | ||
28 | , EventBeginElement (mkname namespace "body") [] | 32 | , EventBeginElement (mkname namespace "body") [] |
29 | , EventContent (ContentText bod) | 33 | , EventContent (ContentText bod) |
30 | , EventEndElement (mkname namespace "body") | 34 | , EventEndElement (mkname namespace "body") |
31 | , EventEndElement (mkname namespace "message") ] | 35 | , EventEndElement (mkname namespace "message") ] |
32 | where | 36 | where |
33 | typ = Message { msgThread = Nothing | 37 | typ = Message { msgThread = Nothing |
34 | , msgLangMap = [("", lsm)] | 38 | , msgLangMap = [("", lsm)] |
39 | , msgType = msgtyp | ||
35 | } | 40 | } |
36 | lsm = LangSpecificMessage | 41 | lsm = LangSpecificMessage |
37 | { msgBody = Just bod | 42 | { msgBody = Just bod |
38 | , msgSubject = Nothing } | 43 | , msgSubject = Nothing } |
39 | 44 | ||
45 | addMessageType ChatMsg attrs = ("type",[ContentText "chat"]) : attrs | ||
46 | addMessageType GroupChatMsg attrs = ("type",[ContentText "groupchat"]) : attrs | ||
47 | addMessageType HeadlineMsg attrs = ("type",[ContentText "headline"]) : attrs | ||
48 | addMessageType _ attrs = attrs | ||
49 | |||
40 | makeInformSubscription :: Text -> Text -> Text -> Bool -> IO Stanza | 50 | makeInformSubscription :: Text -> Text -> Text -> Bool -> IO Stanza |
41 | makeInformSubscription namespace from to approved = | 51 | makeInformSubscription namespace from to approved = |
42 | stanzaFromList (PresenceInformSubscription approved) | 52 | stanzaFromList (PresenceInformSubscription approved) |
diff --git a/Presence/Stanza/Parse.hs b/Presence/Stanza/Parse.hs index b025f418..58bf7c51 100644 --- a/Presence/Stanza/Parse.hs +++ b/Presence/Stanza/Parse.hs | |||
@@ -227,9 +227,16 @@ parseMessage ns stanza = do | |||
227 | , Map.empty ) | 227 | , Map.empty ) |
228 | return Message { | 228 | return Message { |
229 | msgLangMap = Map.toList langmap, | 229 | msgLangMap = Map.toList langmap, |
230 | msgThread = if msgThreadContent th/="" then Just th else Nothing | 230 | msgThread = if msgThreadContent th/="" then Just th else Nothing, |
231 | msgType = parseMessageType $ lookupAttrib "type" (tagAttrs stanza) | ||
231 | } | 232 | } |
232 | 233 | ||
234 | parseMessageType :: Maybe Text -> MessageType | ||
235 | parseMessageType (Just "chat") = ChatMsg | ||
236 | parseMessageType (Just "groupchat") = GroupChatMsg | ||
237 | parseMessageType (Just "headline") = HeadlineMsg | ||
238 | parseMessageType _ = NormalMsg | ||
239 | |||
233 | findErrorTag :: Monad m => Text -> NestingXML o m (Maybe StanzaError) | 240 | findErrorTag :: Monad m => Text -> NestingXML o m (Maybe StanzaError) |
234 | findErrorTag ns = do | 241 | findErrorTag ns = do |
235 | x <- nextElement | 242 | x <- nextElement |
diff --git a/Presence/Stanza/Types.hs b/Presence/Stanza/Types.hs index 6c5b8867..7275c8ab 100644 --- a/Presence/Stanza/Types.hs +++ b/Presence/Stanza/Types.hs | |||
@@ -70,6 +70,7 @@ data StanzaType | |||
70 | | PresenceRequestSubscription Bool | 70 | | PresenceRequestSubscription Bool |
71 | | Message { msgThread :: Maybe MessageThread | 71 | | Message { msgThread :: Maybe MessageThread |
72 | , msgLangMap :: [(Lang,LangSpecificMessage)] | 72 | , msgLangMap :: [(Lang,LangSpecificMessage)] |
73 | , msgType :: MessageType | ||
73 | } | 74 | } |
74 | | NotifyClientVersion { versionName :: Text | 75 | | NotifyClientVersion { versionName :: Text |
75 | , versionVersion :: Text } | 76 | , versionVersion :: Text } |
@@ -77,6 +78,60 @@ data StanzaType | |||
77 | | InternalCacheId Text | 78 | | InternalCacheId Text |
78 | deriving (Show,Eq) | 79 | deriving (Show,Eq) |
79 | 80 | ||
81 | data MessageType | ||
82 | = NormalMsg -- ^ The message is a standalone message that is sent outside | ||
83 | -- the context of a one-to-one conversation or groupchat, and | ||
84 | -- to which it is expected that the recipient will reply. | ||
85 | -- Typically a receiving client will present a message of type | ||
86 | -- "normal" in an interface that enables the recipient to | ||
87 | -- reply, but without a conversation history. The default | ||
88 | -- value of the 'type' attribute is "normal". | ||
89 | |||
90 | | ChatMsg -- ^ The message is sent in the context of a one-to-one chat | ||
91 | -- session. Typically an interactive client will present a | ||
92 | -- message of type "chat" in an interface that enables one-to-one | ||
93 | -- chat between the two parties, including an appropriate | ||
94 | -- conversation history. Detailed recommendations regarding | ||
95 | -- one-to-one chat sessions are provided under Section 5.1. | ||
96 | |||
97 | | GroupChatMsg -- ^ The message is sent in the context of a multi-user chat | ||
98 | -- environment (similar to that of [IRC]). Typically a | ||
99 | -- receiving client will present a message of type | ||
100 | -- "groupchat" in an interface that enables many-to-many | ||
101 | -- chat between the parties, including a roster of parties | ||
102 | -- in the chatroom and an appropriate conversation history. | ||
103 | -- For detailed information about XMPP-based groupchat, | ||
104 | -- refer to [XEP‑0045]. | ||
105 | |||
106 | | HeadlineMsg -- ^ The message provides an alert, a notification, or other | ||
107 | -- transient information to which no reply is expected (e.g., | ||
108 | -- news headlines, sports updates, near-real-time market | ||
109 | -- data, or syndicated content). Because no reply to the | ||
110 | -- message is expected, typically a receiving client will | ||
111 | -- present a message of type "headline" in an interface that | ||
112 | -- appropriately differentiates the message from standalone | ||
113 | -- messages, chat messages, and groupchat messages (e.g., by | ||
114 | -- not providing the recipient with the ability to reply). If | ||
115 | -- the 'to' address is the bare JID, the receiving server | ||
116 | -- SHOULD deliver the message to all of the recipient's | ||
117 | -- available resources with non-negative presence priority | ||
118 | -- and MUST deliver the message to at least one of those | ||
119 | -- resources; if the 'to' address is a full JID and there is | ||
120 | -- a matching resource, the server MUST deliver the message | ||
121 | -- to that resource; otherwise the server MUST either | ||
122 | -- silently ignore the message or return an error (see | ||
123 | -- Section 8). | ||
124 | |||
125 | -- | ErrorMsg -- The message is generated by an entity that experiences an | ||
126 | -- error when processing a message received from another entity (for | ||
127 | -- details regarding stanza error syntax, refer to [XMPP‑CORE]). A client | ||
128 | -- that receives a message of type "error" SHOULD present an appropriate | ||
129 | -- interface informing the original sender regarding the nature of the | ||
130 | -- error. | ||
131 | |||
132 | deriving (Show,Read,Ord,Eq,Enum) | ||
133 | |||
134 | |||
80 | data RosterEventType | 135 | data RosterEventType |
81 | = RequestedSubscription | 136 | = RequestedSubscription |
82 | | NewBuddy -- preceded by PresenceInformSubscription True | 137 | | NewBuddy -- preceded by PresenceInformSubscription True |