~singpolyma/cheogram

ref: 56e23b4519d46be8adae6f7fa018fa35fb38140e cheogram/CommandAction.hs -rw-r--r-- 1.3 KiB
56e23b45Christopher Vollick Change JID Command a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module CommandAction where

import Data.XML.Types as XML (Element(..), Node(NodeContent, NodeElement), Content(ContentText), isNamed, elementText, elementChildren, attributeText)

import qualified Data.Text as T
import qualified Data.XML.Types as XML

import Util

data Action = ActionNext | ActionPrev | ActionCancel | ActionComplete

actionContent :: Action -> Content
actionContent ActionNext     = ContentText $ s"next"
actionContent ActionPrev     = ContentText $ s"prev"
actionContent ActionCancel   = ContentText $ s"cancel"
actionContent ActionComplete = ContentText $ s"complete"

actionCmd :: Action -> T.Text
actionCmd ActionNext     = s"next"
actionCmd ActionPrev     = s"back"
actionCmd ActionCancel   = s"cancel"
actionCmd ActionComplete = s"finish"

actionFromXMPP :: T.Text -> Maybe Action
actionFromXMPP xmpp
	| xmpp == s"next"     = Just ActionNext
	| xmpp == s"prev"     = Just ActionPrev
	| xmpp == s"complete" = Just ActionComplete
	| otherwise           = Nothing

actionToEl :: Action -> [Element]
actionToEl ActionNext = [Element (s"{http://jabber.org/protocol/commands}next") [] []]
actionToEl ActionPrev = [Element (s"{http://jabber.org/protocol/commands}prev") [] []]
actionToEl ActionComplete = [Element (s"{http://jabber.org/protocol/commands}complete") [] []]
actionToEl ActionCancel = []