1# Fossil Chat 2 3## Introduction 4 5As of version 2.14, 6Fossil supports a developer chatroom feature. The chatroom provides an 7ephemeral discussion venue for insiders. Design goals include: 8 9 * **Simple but functional** → 10 Fossil chat is designed to provide a convenient real-time 11 communication mechanism for geographically dispersed developers. 12 Fossil chat is *not* intended as a replacement or competitor for 13 IRC, Slack, Discord, Telegram, Google Hangouts, etc. 14 15 * **Low administration** → 16 You can activate the chatroom in seconds without having to 17 mess with configuration files or install new software. 18 In an existing [server setup](./server/), 19 simply enable the [C capability](/setup_ucap_list) for users 20 whom you want to give access to the chatroom. 21 22 * **Ephemeral** → 23 Chat messages do not sync to peer repositories, and they are 24 automatically deleted after a configurable delay (default: 7 days). 25 Individual messages or the entire conversation 26 can be deleted at any time without impacting any other part 27 of the system. 28 29Fossil chat is designed for use by insiders - people with check-in 30privileges or higher. It is not intended as a general-purpose gathering 31place for random passers-by on the internet. 32Fossil chat seeks to provide a communication venue for discussion 33that does *not* become part of the permanent record for the project. 34For persistent and durable discussion, use the [Forum](./forum.wiki). 35Because the conversation is intended to be ephemeral, the chat messages 36are local to a single repository. Chat content does not sync. 37 38 39## Setup 40 41A Fossil repository must be functioning as a [server](./server/) in order 42for chat to work. 43To activate chat, simply add the [C capability](/setup_ucap_list) 44to every user who is authorized to participate. Anyone who can read chat 45can also post to chat. 46 47Setup ("s") and Admin ("a") users always have access to chat, without needing 48the "C" capability. A common configuration is to add the "C" capability 49to "Developer" so that any individual user who has the "v" capability will 50also have access to chat. 51 52There are also some settings under /Admin/Chat that control the 53behavior of chat, though the default settings are reasonable so in most 54cases those settings can be ignored. The settings control things like 55the amount of time that chat messages are retained before being purged 56from the repository database. 57 58## <a id="usage"></a>Usage 59 60For users with appropriate permissions, simply browse to the 61[/chat](/help?cmd=/chat) to start up a chat session. The default 62skin includes a "Chat" entry on the menu bar on wide screens for 63people with chat privilege. There is also a "Chat" option on 64the [Sitemap page](/sitemap), which means that chat will appear 65as an option under the hamburger menu for many [skins](./customskin.md). 66 67As of version 2.17, chat messages are subject to [fossil's 68full range of markdown processing](/md_rules). Because chat messages are 69stored as-is when they arrive from a client, this change applies 70retroactively to messages stored by previous fossil versions. 71 72Files may be sent via chat using the file selection element at the 73bottom of the page. If the desktop environment system supports it, 74files may be dragged and dropped onto that element. Files are not 75automatically sent - selection of a file can be cancelled using the 76Cancel button which appears only when a file is selected. When the 77Send button is pressed, any pending text is submitted along with the 78selected file. Image files sent this way will, by default, appear 79inline in messages, but each user may toggle that via the settings 80popup menu, such that images instead appear as downloadable links. 81Non-image files always appear in messages as download links. 82 83### Deletion of Messages 84 85Any user may *locally* delete a given message by clicking on the "tab" 86at the top of the message and clicking the button which appears. Such 87deletions are local-only, and the messages will reappear if the page 88is reloaded. The user who posted a given message, or any Admin users, 89may additionally choose to globally delete a message from the chat 90record, which deletes it not only from their own browser but also 91propagates the removal to all connected clients the next time they 92poll for new messages. 93 94### <a id='notifications'></a>Customizing New-message Notification Sounds 95 96By default, the list of new-message notification sounds is limited to 97a few built in to the fossil binary. In addition, any 98[unversioned files](./unvers.wiki) named `alert-sounds/*.{mp3,wav,ogg}` 99will be included in that list. To switch sounds, tap the "settings" 100button. 101 102### <a id='connection'></a> Who's Online? 103 104Because the chat app has to be able to work over transient CGI-based 105connections, as opposed to a stable socket connection to the server, 106real-time tracking of "who's online" is not feasible. As of version 1072.17, chat offers an optional feature, toggleable in the settings, 108which can list users who have posted messages in the client's current 109list of loaded messages. This is not the same thing as tracking who's 110online, but it gives an overview of which users have been active most 111recently, noting that "lurkers" (people who post no messages) will not 112show up in that list, nor does the chat infrastructure have a way to 113track and present those. That list can be used to filter messages on a 114specific user by tapping on that user's name, tapping a second time to 115remove the filter. 116 117Sidebar: message deletion is a type of message and deletions count 118towards updates in the recent activity list (counted for the person 119who performed the deletion, not the author of the deleted 120comment). That can potentially lead to odd corner cases where a user 121shows up in the list but has no messages which are currently visible 122because they were deleted, or an admin user who has not posted 123anything but deleted a message. That is a known minor cosmetic-only 124bug with a resolution of "will not fix." 125 126 127## Implementation Details 128 129*You do not need to understand how Fossil chat works in order to use it. 130But many developers prefer to know how their tools work. 131This section is provided for the benefit of those curious developers.* 132 133The [/chat](/help?cmd=/chat) webpage downloads a small amount of HTML 134and a small amount of javascript to run the chat session. The 135javascript uses XMLHttpRequest (XHR) to download chat content, post 136new content, or delete historical messages. The following web 137interfaces are used by the XHR: 138 139 * **/chat-poll** → 140 Downloads chat content as JSON. 141 Chat messages are numbered sequentially. 142 The client tells the server the largest chat message it currently 143 holds, and the server sends back subsequent messages. If there 144 are no subsequent messages, the /chat-poll page blocks until new 145 messages are available. 146 147 * **/chat-send** → 148 Sends a new chat message to the server. 149 150 * **/chat-delete** → 151 Deletes a chat message. 152 153Fossil chat uses the venerable "hanging GET" or 154"[long polling](wikipedia:/wiki/Push_technology#Long_polling)" 155technique to recieve asynchronous notification of new messages. 156This is done because long polling works well with CGI and SCGI, 157which are the usual mechanisms for setting up a Fossil server. 158More advanced notification techniques such as 159[Server-sent events](wikipedia:/wiki/Server-sent_events) and especially 160[WebSockets](wikipedia:/wiki/WebSocket) might seem more appropriate for 161a chat system, but those technologies are not compatible with CGI. 162 163Downloading of posted files and images uses a separate, non-XHR interface: 164 165 * **/chat-download** → 166 Fetches the file content associated with a post (one file per 167 post, maximum). In the UI, this is accessed via links to uploaded 168 files and via inlined image tags. 169 170Chat messages are stored on the server-side in the CHAT table of 171the repository. 172 173~~~ 174 CREATE TABLE repository.chat( 175 msgid INTEGER PRIMARY KEY AUTOINCREMENT, 176 mtime JULIANDAY, 177 ltime TEXT, 178 xfrom TEXT, 179 xmsg TEXT, 180 fname TEXT, 181 fmime TEXT, 182 mdel INT, 183 file BLOB) 184 ); 185~~~ 186 187The CHAT table is not cross-linked with any other tables in the repository 188schema. An administrator can "DROP TABLE chat;" at any time, without 189harm (apart from deleting all chat history, of course). The CHAT table 190is dropped when running [fossil scrub --verily](/help?cmd=scrub). 191 192On the server-side, message text is stored exactly as entered by the 193users. The /chat-poll page queries the CHAT table and constructs a 194JSON reply described in the [/chat-poll 195documentation](/help?cmd=/chat-poll). The message text is translated 196into HTML before being converted to JSON so that the text can be 197safely added to the display using assignment to `innerHTML`. Though 198`innerHTML` assignment is generally considered unsafe, it is only so 199with untrusted content from untrusted sources. The chat content goes 200through sanitization steps which eliminate any potential security 201vulnerabilities of assigning that content to `innerHTML`. 202