Monday, November 08, 2010 at 12:04 AM.

system.verbs.builtins.mainResponder.discuss.addMessage

on addMessage (subject, member, inResponseTo, body, flNeuterMacros=true, flNeuterTags=true, postTime=clock.now (), adrroot=nil, flcallback=true, groupname="", flEmptyBodyOk=false, adrdata=nil, flEmptySubjectOk=false) {
	<<Changes
		<<5/26/03; 6:30:19 PM by JES
			<<New optional parameter, flEmptySubjectOk. Defaults to false, preserving current behavior.
		<<4/8/03; 2:45:24 PM by JES
			<<New optional parameter, adrdata. adrdata is the address of a table. If non-nil, then all sub-elements of the table at adrdata are copied into the msgtable. Use this parameter if your application needs to store additional information in the message.
			<<mainResponder.discuss.postMessage uses this parameter to add the IP address of the client POST-ing a new message.
		<<5/30/01; 11:17:16 JES
			<<If the subject is empty, put the body of the message in the page table, so the WYSIWYG editor has a chance to give the user another shot at creating the message.
		<<8/19/99; 3:30:57 PM by DW
			<<New optional param, flEmptyBodyOk, defaults false.
			<<If true, body can be the empty string.
			<<It was ridiculous to make an XML-RPC call supply a body, when the user hasn't edited the copy yet.
		<<7/16/99; 11:36:10 GMT by AR
			<<Closed a security hole: The subject is now run thru mainResponder.neuterText.
		<<5/26/99; 01:54:34 GMT by AR
			<<Added new optional parameter, groupname. If it's the empty string (the default), we assume config.mainResponder.globals.defaultMembershipGroup.
		<<2/11/99; 11:37:21 AM by DW
			<<if html.getPageTableAddress doesn't work, we create our own table
				<<any callback should only depend on pta^.adrNewMsg being set
			<<new optional parameter, adrroot, if nil, we should find the discussion root ourselves, otherwise the caller supplied it
			<<new optional parameter, flcallback, if true we call the callbacks, otherwise not
		<<4/10/00; 2:48:59 PM by JES
			<<changed string constants to lookups in the localization table with mainResponder.getString
	bundle { //clean up subject and messagetext
		subject = string.trimWhitespace (subject);
		if subject == "" {
			if not flEmptySubjectOk {
				local (errorText = mainResponder.getString ("discuss.cantAddMsgSubjEmpty"));
				try { //put the message body in the page table so Manila can handle the error gracefully
					pta = html.getPageTableAddress ();
					pta^.errorText = errorText;
					pta^.messageBody = body};
				scriptError (errorText)}};
		subject = mainResponder.neuterText (subject, flNeuterMacros, flNeuterTags); //AR 6/16/1999
		body = string.trimWhitespace (body);
		if not flEmptyBodyOk { //8/19/99; 3:31:57 PM by DW
			if body == "" {
				scriptError (mainResponder.getString ("discuss.cantAddMsgBodyEmpty"))}};
		body = mainResponder.neuterText (body, flNeuterMacros, flNeuterTags)};
	bundle { //wipe out the member's message cache
		if groupname == "" {
			groupname = config.mainresponder.globals.defaultMembershipGroup};
		local (adrmembers = mainresponder.members.getMembershipTable (groupname));
		local (adrmember = @adrmembers^.users.[member]);
		try {delete (@adrmember^.messageListCache)}};
	
	if adrroot == nil { //2/11/99; 11:41:51 AM by DW
		adrroot = mainresponder.discuss.openroot ()};
	local (adrprefs = @adrroot^.prefs);
	local (adrmsgs = @adrroot^.messages);
	local (adrcal = @adrroot^.calendar);
	local (msgnum = adrprefs^.nextMsgNum++);
	
	local (msgtable);
	bundle { //copy info into msgtable
		new (tabletype, @msgtable);
		msgtable.body = body;
		msgtable.ctReads = 0;
		msgtable.inResponseTo = inResponseTo;
		msgtable.member = member;
		msgtable.msgnum = msgnum;
		msgtable.postTime = postTime;
		msgtable.lastUpdate = postTime;
		msgtable.responses = {};
		msgtable.subject = subject};
	
	local (name = string.padwithzeros (msgnum, 7));
	local (adrnewmsg = @adrmsgs^.[name]);
	adrnewmsg^ = msgtable;
	
	if adrdata != nil { //JES 4/8/03: copy the data table's contents into the message table
		if defined (adrdata^) {
			if typeOf (adrdata^) == tableType {
				local (adritem);
				for adritem in adrdata {
					table.assign (@adrnewmsg^.[nameOf (adritem^)], adritem^)}}}};
	
	if inResponseTo > 0 { //add this message to the parent's response list
		local (adrresponses = @adrmsgs^.[string.padwithzeros (inResponseTo, 7)].responses);
		local (listelement = {msgnum});
		if defined (adrresponses^) {
			adrresponses^ = adrresponses^ + listelement}
		else {
			adrresponses^ = listelement}};
	
	bundle { //cross-index in the calendar
		local (adrday = mainResponder.calendar.getDayAddress (adrcal, postTime));
		adrday^.[name] = subject};
	
	if flcallback { //2/11/99; 11:37:15 AM by DW
		local (pta = html.getPageTableAddress ());
		pta^.adrNewMsg = adrNewMsg;
		mainResponder.callbackLoop (@config.mainresponder.callbacks.addMessage, pta)};
	
	mainResponder.discuss.archiveMessage (adrnewmsg); //8/13/99; 10:02:37 PM by DW
	filemenu.saveMyRoot (adrroot);
	
	return (msgnum)}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.