Firefox PHP

private message API

Posted by hyuuu 
private message API
August 30, 2009 04:02AM
Hi there,
I was hoping the API would provide me with a function that is like something like phorum_user_new_private_message_total() or something but I realize, there is nothing there about private message.

Without going into the database directly is it possible, through an API somewhere that I may have missed, to access or manipulate private messages.

Thanks.
Re: private message API
August 30, 2009 10:51AM
The private messaging system has not yet been turned into API calls. It is planned for a future release, but currently you will have to use the db interaction code for this.

phorum_db_pm_checknew() is the call that you can use to check if the user has any new messages at all.

phorum_db_pm_messagecount() is the call that can return the total number of messages and the number of unread messages for a given mailbox. This call with the inbox as the mailbox could be what you need.

That last function might be a bit heavy if executed often on pages. You could also opt for a stripped down query to find the total number of unread messages (would also catch unread messages in other folders than the inbox). Something like this would do I think:

    global $PHORUM;
    $user_id = $PHORUM['user']['user_id'];

    $count = phorum_db_interact(
        DB_RETURN_VALUE,
        "SELECT count(*)
         FROM   {$PHORUM['pm_xref_table']}
         WHERE  user_id   = $user_id AND
                read_flag = 0"
    );

An idea for the future is to redundantly store the number of new messages in the user data, updating this counter after a user receives, reads or deletes a PM. That would make the number of messages available as part of the user data, without requiring extra queries. Until then, you can use the above options.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Sorry, only registered users may post in this forum.

Click here to login