Arc Forumnew | comments | leaders | submitlogin
Arc Network-Chat Project. Have some Questions, need some help
1 point by Moon1ight 5432 days ago | 6 comments
Hello Arcists, I'm pretty new to Arc and Lisp-Programming at all, and try to learn by doing. So based on blog.arc I try to make a small Chat for the local network. It's going pretty well, thanks to the great libraries and the documentation. But there are some things I really can't see a solution:

As it's supposed to be a chat it needs autorefreshing(or?). But in a way that it loads the current (new) Posts, but keeps intact the text currently typed in the textarea(Or is there another way you see?). The corresponding code is this:

   (mac textpage body
   `(chatpage
     (center
       (widtable 600
         (tag b (link blogtitle* "chat"))
	 (br 2)

	 (if (no user) (do (pr "Not logged in")(br)(link "Login" "mylogin")) 
	 
		       (do (pr "Logged in as "user)(br)(link "Logout" "mylogout") ))

	 (load-posts)
         (br 2)
	 ,@body					;So here is post-page displayed I think...
         (br 3)
	 (if (and user)		
	 (aform 				;And that is the textarea, which has to be not refreshed	
	     [let u (get-user _)
             (post-page u (addpost u (arg _ "t") (arg _ "b")))]
      	     (tab (row "Say it:")
	     	  (row (textarea "b" 10 60))
            	  (row (submit))))
	 (do(pr "For writig please ")(link "login" "mylogin")))))))



and it's called (for example) here:

   (def post-page (user p) (textpage		
      (for i 0 7
        (awhen (posts* (- maxid* i))
          (display-post user it)
	   (br)))))
This is all working, but if refreshed, it also refreshes the textarea. How can that be changed? With Frames? By Iteration? By some special feature? Or am I to split textpage into two macros? I really have no Idea here, advice would be very appreciated. If you want I post the full sourcecode.

Another question: Is the Arclanguage forum or HN (or something similiar) open-source? I'd like to take a look on how it manages logging in, as I have problems to change the hello-page.

Edit: This is a very nice forum I have to say, great edititing and automatic code recognition! Never seen something as good as that.



2 points by rocketnia 5432 days ago | link

I'd approach this by using AJAX to replace the contents of the chat without refreshing the whole page. An iframe is a good approach too.

Once you get things working, it might be nice to switch to push techniques at some point: http://en.wikipedia.org/wiki/Comet_(programming) That way you don't have to reload the whole conversation every N seconds. This probably isn't important enough to lose sleep over, though. ^_^

Is the Arclanguage forum or HN (or something similiar) open-source?

Whatever you're using for Arc probably includes news.arc and app.arc, and those are released as specified in the "copyright" file:

  This software is copyright (c) Paul Graham and Robert Morris.  Permission
  to use it is granted under the Perl Foundations's Artistic License 2.0.
Here's text of the license itself: http://www.opensource.org/licenses/artistic-license-2.0.php

In essence, it's a license that allows a lot of freedom but states that you can only distribute a modified version "provided that you clearly document how it differs from the Standard Version." I think the point is so that people who consider your modifications to be shoddy work or copyright infringement don't go complaining to Paul Graham or Robert Morris.

This is a very nice forum I have to say, great edititing and automatic code recognition! Never seen something as good as that.

You're one of the luckier ones, I guess. :) Complete editing instructions are at http://arclanguage.org/formatdoc in case you're interested.

-----

1 point by Moon1ight 5432 days ago | link

Thanks a lot for the quick answer, but:

I'd approach this by using AJAX to replace the contents of the chat without refreshing the whole page. An iframe is a good approach too.

Is that possible to do _in Arc_ (By something with tag ?) or do I need something else as well? I'm really not very expirienced and would have no idea how to combine my Arc-Sourcecode with something completely external... or how to implement these Comet-techniques.

Is it actually possible to make normal Frames or iFrames with the tag-macro?

Thanks for news.arc, I haven't seen it for some reason, seems like it's worth reading.

-----

2 points by thaddeus 5431 days ago | link

Here's an option:

  HTML Layout:

  <html>
  <head>
    <script type="text/javascript">
      (pr (get+xmlhttp (string "chatlog?room=" room "&max=" maxm))
          (checkif+xmlhttp (string "checkchat?room=" room))
    </script>
  </head>
  <body onLoad="javascript: GetData();">
     <div id='chatlog'  ....>
     </div>
   </body>
  <html>

  Services:
1. chatlog?room=1&max=20 , this service returns the conversation data you would like placed in your div having an id of 'chatlog'. The room is the id for a conversation and max is the number of items you want returned from the conversation history.

2. checkchat?room=1, this service checks to see if there's been an update in the chatlog since the last time the user checked. So you need to store the last time checked, and compare that to the timestamp of when the chatlog, for that room, was last updated. Comparing the two will return either Y or N. Y will trigger the update. There's javascript noted below that will auto check this for you.

  Javascript: 

  (def get+xmlhttp (url) 
     (string 
	"function GetData(){
	  if (window.XMLHttpRequest){
          var xmlHttp = new XMLHttpRequest ();}
          if (window.ActiveXObject){
          var xmlHttp = new ActiveXObject(\"Microsoft.XMLHTTP\");}
          xmlHttp.open (\"GET\",\"" url "\", false);
          xmlHttp.send (null);
          var targetNode = document.getElementById (\"chatlog\");
          targetNode.innerHTML = xmlHttp.responseText;};"))

  (def checkif+xmlhttp (url)
    (string 
	   "function CheckChatLog(){
	      if (window.XMLHttpRequest){
                var textHttp = new XMLHttpRequest ();}
                if (window.ActiveXObject){
                var textHttp = new ActiveXObject(\"Microsoft.XMLHTTP\");}
                textHttp.open (\"GET\",\"" url "\", false);
                textHttp.send (null);
                if (textHttp.responseText == \"Y\") GetData();};	     
           window.setInterval(\"CheckChatLog()\",5000);"))

The 'CheckChatLog' function checks the 'checkchat' service to see if there's been an update. If there has been, then 'GetData' is called which pushes the data into your 'chatlog' div.

Notice 'checkif+xmlhttp' has 'window.setInterval', so the js will periodically run 'CheckChatLog' for you - you may want to tweak the 5000 time interval.

I hope that's useful. I created one a year or so ago, which haven't touched it since, so if something doesn't make sense, ask away.

-----

2 points by akkartik 5431 days ago | link

Doing an ajax get will require javascript. Look at votejs* in news.arc.

Frames and iframes can be rendered using tag but you'll need to update html.arc to recognize their html attributes. Surprisingly this isn't fixed in anarki, but see if you can figure out what to do at http://github.com/nex3/arc/blob/3201b34f3ed89e6305b0d99066e4...

-----

1 point by Moon1ight 5430 days ago | link

On Frames: As the starttags <frameset attributes...> and <frame attbibutes...> aren't the same as the end tags, I'd have to do macros like (mac tab...), or ? This should be possible... and then add the attributes, yeah. I will try it soon, thanks.

When I have a frame, how can I tell the code, to autorefresh it and only it?

And does a frame need a .html-file to read? or can scr="...", the attribute of a frame, be the name of a (defop xyz...)?

-----

3 points by Moon1ight 5427 days ago | link

SOLVED.

I have defined attributes for iframe and the meta-tag in html.arc, after which it was easy to put the posts into an iframe and to set a meta-refresh on it.

Thanks to all of you, without your help I probably hadn't even thought about messing with html.arc and frames this hard. If someone wants I'll post the sourcecode of it, maybe it's useful.

-----