]> Sergey Matveev's repositories - mmc.git/blob - doc/arch.texi
Short feature list
[mmc.git] / doc / arch.texi
1 @node Architecture
2 @unnumbered Architecture
3
4 Brief scheme of commands, utilities and files involved is below.
5 @file{F} means files/FIFOs/directories creation and altering.
6 @file{R} means running of external programs.
7
8 @verbatim
9 cmd/start
10   F tmux.conf
11   R tmux -f tmux.conf
12     R tail -f debug | tai64n
13     R for { cat users/status ; sleep 5 }
14     R fzf **(/) | cmd/newwin
15     R cmd/mmc | tai64n
16      F users/status
17      F users/.../{id,email,name,|in,out.rec,|status,last}
18      F chans/.../{id,info,out.rec,|users,last}
19      F file/{|get,|out}
20      R cmd/notify
21        R tmux display-message ...
22      R cmd/newwin
23        R cmd/rd/colourized
24          R cmd/rd < .../out.rec | spc
25        R cmd/wr
26          R for { rlwrap cat > .../in }
27
28 cmd/download
29   R echo ... > file/get
30   R tar xf < file/out
31
32 cmd/sb ... > history.rec
33 @end verbatim
34
35 @url{https://tools.suckless.org/ii/usage/, ii} IRC client's page has
36 many links to similar kind of chat software. There is some long-living
37 program, that deals with the messaging protocol and communicates with
38 other programs through the FIFO files.
39
40 There are user chats and group chats, both in IRC, XMPP and MM worlds.
41 Each user and channel have corresponding directory having the same name.
42 It contains @file{in} and @file{out} named pipes. Anything you write to
43 @file{in} will be send as a message to corresponding user/channel.
44 Reading from @file{out} will give you incoming messages from that
45 user/channel. That is the basic idea of the backend.
46
47 All you need is to write the frontend that will give you convenient
48 ability to deal with all that bunch of files. That is the most
49 complicated part of course. I do not like idea of having the single
50 window with consolidation of all chats, like using @command{multitail}
51 on several pipes. I do not like idea of purely CLI utility like
52 @url{https://github.com/agl/xmpp-client, github.com/agl/xmpp-client},
53 @url{https://en.wikipedia.org/wiki/MICQ, mICQ} or
54 @url{https://www.gnu.org/software/freetalk/, GNU Freetalk}, where you
55 have to carefully be aware of whom you are typing now. I like
56 @command{irssi} and @command{mcabber}, where you have got separate
57 window with per-user/channel output and input. We must have ability to
58 hide/close those windows/tabs/panes, automatically open them if they got
59 incoming events and we must be alerted about those events, at least by
60 bell character.
61
62 @url{https://github.com/tmux/tmux/wiki, tmux} is a perfect tool for
63 dynamic windows/tabs/panes management. It already has all necessary
64 functions to detect bell/alarms. It have ability to easily create you
65 own keybindings and already have massive amount of convenient hotkeys to
66 quickly navigate among all that windows. It already has history buffer
67 and ability to search in it. And it is likely to be already used by the
68 end user.
69
70 Messages have to be saved on filesystem. Unlike IRC, MM messages are
71 often multiline and can have additional metadata like unique identifiers
72 and attached files. So each message is a more complicated entity than
73 text string with appended timestamp and sender information. Each time
74 chat window is opened, I want to see tail of the corresponding history.
75 So instead of using FIFO that is @command{tee}-ed to ordinary
76 long-living file, I decided to use append-only
77 @url{https://www.gnu.org/software/recutils/, GNU Recutils}'es recfile.
78 And an additional program that translates it to convenient human
79 readable lines, also acting like @command{tail -f}.
80
81 It is crucial to read message you want to send not line by line, to be
82 able to send multiline messages in a single post. Closing the FIFO file
83 can be treated as the end of the message. To be able to use rich line
84 editing capabilities or even external editor, you can use great
85 @url{https://github.com/hanslub42/rlwrap, rlwrap} utility in an endless
86 loop.
87
88 So how all that decisions are composed together?
89
90 @itemize
91
92 @item @command{cmd/start} creates @file{debug} and @file{users/status}
93 FIFOs, prepares configuration file for @command{tmux} (actually there is
94 just single path to the command replaced with the real one) and runs it
95 with single window split on two three parts: one just shows debug
96 messages (all raw MM messages), other shows colourized list of
97 non-offline users, another one runs @command{cmd/mmc} itself.
98
99 @item @command{cmd/mmc} logs in to the server, fetches a list of all
100 known users and channels I am subscribed to. Then it creates necessary
101 @file{users/NAME} and @file{chans/NAME} directories with some basic
102 regular information files (like identifiers and email addresses) with
103 various FIFOs.
104
105 @item Reading @file{users/.../status} shows you current user's status.
106 @file{chans/.../users} shows currently subscribed users.
107
108 @item @file{out.rec} is append-only database of passed messages.
109 @file{last} contains the identifier of the last received message. After
110 you log in, it is used to fetch newly appeared messages while you were
111 offline.
112
113 @item If some user changes its status, or someone is typing, then
114 @command{cmd/mmc} calls @command{cmd/notify} command with corresponding
115 message. Currently that handler just asks @command{tmux} to
116 @command{display-message} for 1.5 seconds.
117
118 @item If new message comes in, then @command{cmd/mmc} calls
119 @command{cmd/newwin} and tells what window it has to open.
120 @command{cmd/newwin} checks if @command{tmux} has opened it already.
121 Newly created window has the name of the user/channel and is split on
122 two parts:
123     @itemize
124     @item
125     one part contains the output of @command{cmd/rd} piped through
126     @url{http://supercat.nosredna.net/, supercat} (@command{spc}) for
127     colourizing.
128     @item
129     other part holds an endless cycle of @command{rlwrap}-ed
130     @command{cat} piped to corresponding @file{in} FIFO.
131     @end itemize
132
133 @item Also you can manually open desired chat window by pressing
134 predefined keybinding, that will show you
135 @command{https://github.com/junegunn/fzf, fzf}-backed list of all known
136 users and channels.
137
138 @item @command{cmd/rd} reads @file{out.rec} file and prints last ten
139 messages (by default) in human readable form. It does not close that
140 file, but regularly checks if it is updated, to immediately print the
141 newly appeared messages. It print bell character with each message, so
142 it sets an alert for window in @command{tmux}.
143
144 @end itemize
145
146 Outside that running @command{tmux} user can use @command{cmd/download}
147 utility to download specified file's identifier. It sends it identifier
148 to @file{file/get} and reads the archive with that file from
149 @file{file/out}. File is sent inside
150 @url{https://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92_13_01,
151 pax archive} to keep its original name and MM's file identifier.