Jump to content
You're invited! Join our 4.6 Live Event on ZOOM 6/24 ×

Community

How to send private message


Niko Belger
 Share

Recommended Posts

1 hour ago, Niko Belger said:

how do I send a private message in IPB4? In IPB3 there were some functions for it but didn't find them in IPB4 yet

One example I use:

	/**
	 * Send pm
	 */      
	public function messageMembersSend( $member, $subject, $content )
	{
		/* Setup pm title and msg */
		$msgTitle = $subject;
		$msgPost  = $content;
		\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $msgTitle );        
		\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $msgPost );  

		/* Set the receiver */
		try
		{
			$member = \IPS\Member::load( $member );
		}
		catch( \OutOfRangeException $ex )
		{
			return; 
		}

		/* Set pm sender */
		try
		{
			$pmSender = \IPS\Member::loggedIn();
		}
		catch( \OutOfRangeException $ex )
		{
			return; 
		} 

		/* Valid sender? */
		if( !$pmSender->member_id )
		{
			return;
		}

		/* Create conversation */        
		$conversation = \IPS\core\Messenger\Conversation::createItem( $pmSender, $pmSender->ip_address, \IPS\DateTime::ts( time() ) );
		$conversation->title 		= $msgTitle;
		$conversation->to_member_id = $member->member_id;
		$conversation->save();
        
		/* Add message */ 
		$message = \IPS\core\Messenger\Message::create( $conversation, $msgPost, TRUE, NULL, NULL, $pmSender );
		$conversation->first_msg_id = $message->id;
		$conversation->save(); 

		/* Authorize everyone */       
		$conversation->authorize( $member );
		$conversation->authorize( $pmSender );

		/* Send notification */ 
		$notification = new \IPS\Notification( \IPS\Application::load('core'), 'private_message_added', $conversation, array( $conversation, $pmSender ) );
		$notification->send();                      
	}

 

Link to comment
Share on other sites

  • 3 years later...
On 9/16/2017 at 10:16 AM, Adriano Faria said:

One example I use:

	/**
	 * Send pm
	 */      
	public function messageMembersSend( $member, $subject, $content )
	{
		/* Setup pm title and msg */
		$msgTitle = $subject;
		$msgPost  = $content;
		\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $msgTitle );        
		\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $msgPost );  

		/* Set the receiver */
		try
		{
			$member = \IPS\Member::load( $member );
		}
		catch( \OutOfRangeException $ex )
		{
			return; 
		}

		/* Set pm sender */
		try
		{
			$pmSender = \IPS\Member::loggedIn();
		}
		catch( \OutOfRangeException $ex )
		{
			return; 
		} 

		/* Valid sender? */
		if( !$pmSender->member_id )
		{
			return;
		}

		/* Create conversation */        
		$conversation = \IPS\core\Messenger\Conversation::createItem( $pmSender, $pmSender->ip_address, \IPS\DateTime::ts( time() ) );
		$conversation->title 		= $msgTitle;
		$conversation->to_member_id = $member->member_id;
		$conversation->save();
        
		/* Add message */ 
		$message = \IPS\core\Messenger\Message::create( $conversation, $msgPost, TRUE, NULL, NULL, $pmSender );
		$conversation->first_msg_id = $message->id;
		$conversation->save(); 

		/* Authorize everyone */       
		$conversation->authorize( $member );
		$conversation->authorize( $pmSender );

		/* Send notification */ 
		$notification = new \IPS\Notification( \IPS\Application::load('core'), 'private_message_added', $conversation, array( $conversation, $pmSender ) );
		$notification->send();                      
	}

 

How could I set the $pmSender as the same as receiver $member?

I have tried:

public function messageMembersSend( $member, $subject, $content )
	{
		/* Setup pm title and msg */
		$msgTitle = $subject;
		$msgPost  = $content;
		\IPS\Member::load( $member )->language()->parseOutputForDisplay( $msgTitle );        
		\IPS\Member::load( $member )->language()->parseOutputForDisplay( $msgPost );  

		/* Set the receiver */
		try
		{
			$member = \IPS\Member::load( $member );
		}
		catch( \OutOfRangeException $ex )
		{
			return; 
		}

		/* Set pm sender */
		try
		{
			$pmSender = \IPS\Member::load( $member );
		}
		catch( \OutOfRangeException $ex )
		{
			return; 
		} 

		/* Valid sender? */
		if( !$pmSender->member_id )
		{
			return;
		}

		/* Create conversation */        
		$conversation = \IPS\core\Messenger\Conversation::createItem( $pmSender, $pmSender->ip_address, \IPS\DateTime::ts( time() ) );
		$conversation->title 		= $msgTitle;
		$conversation->to_member_id = $member->member_id;
		$conversation->save();
        
		/* Add message */ 
		$message = \IPS\core\Messenger\Message::create( $conversation, $msgPost, TRUE, NULL, NULL, $pmSender );
		$conversation->first_msg_id = $message->id;
		$conversation->save(); 

		/* Authorize everyone */       
		$conversation->authorize( $member );
		$conversation->authorize( $pmSender );

		/* Send notification */ 
		$notification = new \IPS\Notification( \IPS\Application::load('core'), 'private_message_added', $conversation, array( $conversation, $pmSender ) );
		$notification->send();                      
	}

But I get an error: 4C124/6 Illegal offset type in isset or empty

I am trying to send an error message to myself on a plugin.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

We use technologies, such as cookies, to customise content and advertising, to provide social media features and to analyse traffic to the site. We also share information about your use of our site with our trusted social media, advertising and analytics partners. See more about cookies and our Privacy Policy