1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: namespaces assocs kernel sequences accessors hashtables
4 urls db.types db.tuples math.parser fry logging combinators
5 html.templates.chloe.syntax
6 http http.server http.server.filters http.server.redirection
12 IN: furnace.conversations
14 TUPLE: conversation < scope session ;
16 : <conversation> ( id -- conversation )
17 conversation new-server-state ;
19 conversation "CONVERSATIONS" {
20 { "session" "SESSION" BIG-INTEGER +not-null+ }
23 CONSTANT: conversation-id-key "__c"
25 TUPLE: conversations < server-state-manager ;
27 : <conversations> ( responder -- responder' )
28 conversations new-server-state-manager ;
32 SYMBOL: conversation-id
34 : cget ( key -- value )
35 conversation get scope-get ;
37 : cset ( value key -- )
38 conversation get scope-set ;
40 : cchange ( key quot -- )
41 conversation get scope-change ; inline
43 : get-conversation ( id -- conversation )
44 dup [ conversation get-state ] when check-session ;
46 : request-conversation-id ( request -- id )
47 conversation-id-key swap request-params at string>number ;
49 : request-conversation ( request -- conversation )
50 request-conversation-id get-conversation ;
52 : save-conversation-after ( conversation -- )
53 conversations get save-scope-after ;
55 : set-conversation ( conversation -- )
58 [ id>> conversation-id set ]
59 [ save-conversation-after ]
63 : init-conversations ( conversations -- )
65 request get request-conversation
68 M: conversations call-responder*
69 [ init-conversations ]
74 : empty-conversastion ( -- conversation )
75 conversation empty-scope
76 session get id>> >>session ;
78 : touch-conversation ( conversation -- )
79 conversations get touch-state ;
81 : add-conversation ( conversation -- )
82 [ touch-conversation ] [ insert-tuple ] bi ;
84 : begin-conversation ( -- )
88 [ set-conversation ] bi
91 : end-conversation ( -- )
95 : <continue-conversation> ( url -- response )
101 : restore-conversation ( seq -- )
104 [ '[ _ key? ] filter ]
105 [ '[ [ _ at ] keep set ] each ]
109 M: conversations modify-form