chat_get_posts

one of the documented procedures in this installation of the ACS
Usage:
chat_get_posts   db   chat_room_id   number_of_posts
What it does:
Returns a Tcl list. The first element is 1 or 0, depending on whether or not there are more postings than requested (1 if there are more_p). The second element is the last NUMBER_OF_POSTS messages in a chat room, as an HTML fragment, separated by BR tags
Defined in: /web/philip/tcl/chat-defs.tcl

Source code:



    set reverse_p 0
    if {[ad_parameter MostRecentOnTopP chat]} {
	set reverse_p 1
    }

    # we keep the query the same regardless of the order because in fact
    # we're going to be flushing the db connection; we only want the most
    # most recent N rows so we have to start at the top to hit the index and 
    # not suck 9000 old rows out of the db
    set selection [ns_db select $db "select to_char(creation_date, 'HH24:MI:SS') as time, 
 nvl(msg_bowdlerized, msg) as filtered_msg, first_names, last_name, creation_user, system_note_p
from chat_msgs, users
where chat_msgs.creation_user = users.user_id
 and chat_room_id = $chat_room_id
 and chat_msgs.approved_p = 't'
order by creation_date desc"]

    set counter 0
    set chat_rows ""
    
    while { [ns_db getrow $db $selection] } {
	if { $counter >= $number_of_posts } {
	    # flush out the db connection and throw away the rest of the rows
	    ns_db flush $db 
	    # return and tell the caller that there were more 
	    return [list 1 $chat_rows]
	}
	set_variables_after_query 
	incr counter

	set filtered_msg [link_urls [ns_quotehtml $filtered_msg]]

	if { $system_note_p == "t" } {
	    set row "<a target=newwindow href=\"/shared/community-member?user_id=$creation_user\">$first_names $last_name</a><font color=brown>($time) $filtered_msg</font><br>\n"
	} else {
	    set row "<a target=newwindow href=\"/shared/community-member?user_id=$creation_user\">$first_names $last_name</a> ($time) $filtered_msg<br>\n"
	}

	if { $reverse_p } {
	    append chat_rows $row
	} else {
	    set chat_rows "$row$chat_rows"
	}
    }
    # we got everything in the table but there aren't more to be had
    return [list 0 $chat_rows]


philg@mit.edu