AltME Chat

A QuarterMaster project (result).

Current Version

Controller

%controllers/chat.r

REBOL []

arguments: [opt [set action ["9" | "10" | "11" | "12"]]]
action: "chat"

to-color: func [col [tuple!]][
mold rejoin [
skip tail to-hex col/1 -2
skip tail to-hex col/2 -2
skip tail to-hex col/3 -2
]
]

users: remove load files://altme/worlds/rebol3/users.set
users: map users func [usr][
reduce [usr/1 usr/3]
]

linkize: func [txt [string!] /local mk ch link][
txt: sanitize txt
replace/all txt "@" "-[at]-"
parse/all txt [
any [
to http:// mk: (
all [
set [link ch] load/next mk
mk: change/part mk rejoin [
{<a href="} link {">} link </a>
] ch
]
) :mk skip
]
]
txt
]

get-data: does [
remove load files://altme/worlds/rebol3/chat/500.set
]

adjust-date: func [date [date!]][
date/time: any [date/time 0:00]
date/zone: any [date/zone 0:00]

date/time: date/time - date/zone + 2:00
date/zone: none

date
]

actions: [
"chat" [
foreach message data: copy skip tail get-data -300 [
message/2: adjust-date message/2
]
render %chat.rsp
]
"9" [
remove-each message data: get-data [
message/2: adjust-date message/2
9-May-2007 <> message/2
]
render %chat.rsp
]
"10" [
remove-each message data: get-data [
message/2: adjust-date message/2
10-May-2007 <> message/2
]
render %chat.rsp
]
"11" [
remove-each message data: get-data [
message/2: adjust-date message/2
11-May-2007 <> message/2
]
render %chat.rsp
]
"12" [
remove-each message data: get-data [
message/2: adjust-date message/2
12-May-2007 <> message/2
]
render %chat.rsp
]
]

View

%views/chat/chat.rsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>AltME DevCon Chat<% unless action = "chat" [ %> - May <%= action %><% ] %></title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<meta name="generator" content="http://www.ross-gill.com/make-doc/" />
<link rel="stylesheet" type="text/css" href="http://www.ross-gill.com/styles/anywhere.css" media="all" />
<style type="text/css"><!--
th, td {font-size: 12px; border: none; padding: 5px 6px;}
th {background: none; text-align: left;}
table {border-collapse: separate; border-spacing: 1px;}
a.perma:link {color: #000;}
--></style></head>

<%
either action = "chat" [
%><body onload="window.scroll(0,document.body.scrollHeight)"><%
][
%><body><%
]
%>
<h1>AltME DevCon Chat<% unless action = "chat" [ %> - May <%= action %><% ] %></h1>

<h2 id="sect1.">Messages</h2>
<table>
<tr><th>Name</th><th>Message</th><th>Time (Paris)</th></tr>
<% foreach message data [ %><tr>
<% cols: any [message/7/2 [fg 0.0.0 bg 255.255.255]] %><%=
rejoin [<td> { id="msg} pad message/1 4 {" style="color: } to-color message/5 {; font-weight: bold;"}]
%><%= select users message/4 %></td>
<%=
rejoin [<td> { style="color: } to-color cols/fg {; background: } to-color cols/bg {"}]
%><%= replace/all linkize message/8 "^/" <br /> %></td>
<td><%: a (join %#msg pad message/1 4) /perma %><%= form-date message/2 "%e %B<br />%T" %></a></td>
</tr><% ] %>
</table>

</body></html>

Future Version

Helpers

%helpers/chat.r

REBOL []

to-color: func [col [tuple!]][
mold rejoin [
skip tail to-hex col/1 -2
skip tail to-hex col/2 -2
skip tail to-hex col/3 -2
]
]

linkize: func [txt [string!] /local mk ch link][
txt: sanitize txt
replace/all txt "@" "-[at]-"
parse/all txt [
any [
to http:// mk: (
all [
set [link ch] load/next mk
mk: change/part mk rejoin [
{<a href="} link {">} link </a>
] ch
]
) :mk skip
]
]
txt
]

adjust-date: func [date [date!]][
date/time: any [date/time 0:00]
date/zone: any [date/zone 0:00]

date/time: date/time - date/zone + 2:00
date/zone: none

date
]

Controller

%controllers/chat.r

REBOL []

default ["chat"]

on-init [
users: remove load files://altme/worlds/rebol3/users.set
users: map users func [usr][reduce [usr/1 usr/3]]
data: remove load files://altme/worlds/rebol3/chat/500.set
]

"chat" [
foreach message data: skip tail data -300 [
message/2: adjust-date message/2
]
render %chat.rsp
]

"9" [
remove-each message data [
9-May-2007 <> message/2: adjust-date message/2
]
render %chat.rsp
]

"10" [
remove-each message data [
10-May-2007 <> message/2: adjust-date message/2
]
render %chat.rsp
]

"11" [
remove-each message data [
11-May-2007 <> message/2: adjust-date message/2
]
render %chat.rsp
]

"12" [
remove-each message data [
12-May-2007 <> message/2: adjust-date message/2
]
render %chat.rsp
]

View

%views/chat/chat.rsp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>AltME DevCon Chat<% unless action = "chat" [ %> - May <%= action %><% ] %></title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<meta name="generator" content="http://www.ross-gill.com/make-doc/" />
<link rel="stylesheet" type="text/css" href="http://www.ross-gill.com/styles/anywhere.css" media="all" />
<style type="text/css"><!--

th, td {font-size: 12px; border: none; padding: 5px 6px;}
th {background: none; text-align: left;}
table {border-collapse: separate; border-spacing: 1px;}
a.perma:link {color: #000;}

--></style></head>

<%
either action = "chat" [
%><body onload="window.scroll(0,document.body.scrollHeight)"><%
][
%><body><%
]
%>
<h1>AltME DevCon Chat<% unless action = "chat" [ %> - May <%= action %><% ] %></h1>

<h2 id="sect1.">Messages</h2>
<table>
<tr><th>Name</th><th>Message</th><th>Time (Paris)</th></tr>
<% foreach message data [ %><tr>
<% cols: any [message/7/2 [fg 0.0.0 bg 255.255.255]] %><%=
rejoin [<td> { id="msg} pad message/1 4 {" style="color: } to-color message/5 {; font-weight: bold;"}]
%><%= select users message/4 %></td>
<%=
rejoin [<td> { style="color: } to-color cols/fg {; background: } to-color cols/bg {"}]
%><%= replace/all linkize message/8 "^/" <br /> %></td>
<td><%! a (join %#msg pad message/1 4) /perma %><%= form-date message/2 "%e %B<br />%T" %></a></td>
</tr><% ] %>
</table>

</body></html>