Slash::Messages - Send messages for Slash
use Slash::Utility;my $messages = getObject('Slash::Messages');my $msg_id = $messages->create($uid, $message_type, $message);
# ...my $msg = $messages->get($msg_id);$messages->send($msg);$messages->delete($msg_id);
# ...$messages->process($msg_id);
More to come.
create(TO_ID, TYPE, MESSAGE [, FROM_ID, ALTTO]) Will drop a serialized message into message_drop. The UID of the user the message is sent to. Must match a valid uid in the users table. The message type. Preferably a number, but will also handle strings (but those are subject to change by a site admin!). It is best to stick with a number. This is either the exact text to send, or it is a hashref containing the data to send. To override the default "subject" of the message, pass it in as the "subject" key. Pass the name of the template in as the "template_name" key. If "subject" is a template, then pass it as a hashref, with "template_name" as one of the keys.
NOTE: You cannot re-use the same MESSAGE reference for multiple messages. The data is manipulated. You must pass in a new data structure each time through. This should be fixed in future versions. Either the UID of the user sending the message, or 0 to denote a system message (0 is default). This is an alternate "TO" address (e.g., to send a message from a user of the system to a user outside the system). The created message's "id" in the message_drop table. Whatever templates are passed in.
create_web(MESSAGE) Create a message record in message_web. A rendered message hashref. The message ID.
process(MESSAGES) Process a list of messages, sending them and deleting them when sent. A list of messages. Each message may be a rendered message hashref or a message ID. An array of
checkMessageCodes(CODE, UIDS) Returns a list of UIDs from UIDS that are set to recieve messages for CODE. Message code to test. List of UIDs to test. List of UIDs from UIDS that are set to receive messages for CODE.
get(ID) Get message with ID from messages queue. The message ID of the message to get. A hashref containing the rendered message.
gets([COUNT]) Get the next COUNT messages from the messages queue. A number of messages to fetch. Will fetch the oldest messages. If COUNT is false, will fetch all messages. An arrayref of hashrefs of rendered messages.
delete(IDS) Delete the messages of the given IDS from the messages queue. A list of message IDS to delete. Number of messages deleted. Maybe we should log the deletions somewhere? Creation date, uid, type, and deletion date?
render(MESSAGE [, NOTEMPLATE]) Given message data from the database, renders the message by filling in the user's information from the database, getting the description for the message code, and rendering the templates as appropriate. This method should always be called after getting the data from the database, and before using the data. It is called automatically by the get* methods. The hashref of data from the database (see the get* methods). Boolean for whether or not the templates should be processed. In the get() and gets() methods, this boolean is false, because the raw unrendered template data is stored in those messages. But for the getWeb() and getWebByUID() methods, the templates have already been rendered and stored in the messages_web table, so the templates should not be processed. The hashref containing the rendered message data.
callTemplate(DATA, MESSAGE) A wrapper for calling templates in Slash::Messages. It tries to figure out the right page/section to call the template in, etc. It sets the Nocomm parameter in its call to slashDisplay(). This can either be a template name, or a hashref of template data. If a hashref, the _NAME parameter is the template name. The _PAGE and _SECTION parameters may also be set. These will all be set appropriately by the create() method. The rest of the key/value pairs will be passed to the template. The message hashref. This will be assigned to the "msg" template variable, e.g., so you can call "msg.mode" and "msg.id" in the template. The rendered template.
getDescription(CODETYPE, KEY) Given a codetype, will fetch a description if KEY is a code, and code if KEY is a description. KEY is determined to be a code if it is an integer. A type of code, such as "deliverymodes" or "messagecodes". A code or description. This is a little bit tricky.
In scalar context, if KEY is code, return description; if KEY is description, return code. In list context, always return a list of (code, description).
messagedLog(ERROR) Will dispatch error message to main::messagedLog() (if exists) or errorLog(). main::messagedLog() will normally exist only when the message_delivery task is running under slashd. Error message to log. goto() is used, so this function will not show up in a stack trace. Slash(3). $Id: Messages.pm,v 1.1.2.21 2002/01/02 18:58:46 pudge Exp $