Niko Belger Posted September 16, 2017 Posted September 16, 2017 Hello, 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 Best Regards sobrenome 1
Adriano Faria Posted September 16, 2017 Posted September 16, 2017 (edited) Hover a member link and click in message. You mean, via script? Edited September 16, 2017 by Adriano Faria Niko Belger 1
DawPi Posted September 16, 2017 Posted September 16, 2017 I think so: IPS Development Gateway -> How to send private message Niko Belger and sobrenome 2
Adriano Faria Posted September 16, 2017 Posted September 16, 2017 Yeah, noticed after posting since breadcrumb barely exists in mobile. DawPi and Niko Belger 2
Adriano Faria Posted September 16, 2017 Posted September 16, 2017 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(); } deple, sobrenome, DawPi and 2 others 4 1
sobrenome Posted April 14, 2021 Posted April 14, 2021 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.
Adriano Faria Posted April 14, 2021 Posted April 14, 2021 You don’t need the part where you set the receiver (try/catch). You need to authorize only the $pmSender. Change to $pmSender->member_id In $conversation->to_membet_id. I didn’t test but I don’t see why it wouldn’t work. sobrenome 1
Recommended Posts