Did this with the cometchat plugin, which was much easier. Found a solution for this in the Oxwall respiratory, and tested it on a site and it works great. The code below will add a "Send Message" button in the toolbar on user profiles, so you can click it and open an Instant Message modal for that user. As it currently stands, you can only open the modal if the user is in your Chat tab list, or if they're online and you click the hard to find label on their profile picture.
Files you will edit:
mailbox/classes/event_handler.php
Step 1:
In the 'event_handler.php' file, locate the line:
public function init(){
Right above the first line of code, add the following line:
OW::getEventManager()->bind(BASE_CMP_ProfileActionToolbar::EVENT_NAME, array($this, 'sendMessageActionTool'));
Step 2:
At the near bottom of the file, (but not outside of the parent class) add the following function:
//add send button to profile tools
public function sendMessageActionTool( BASE_CLASS_EventCollector $event )
{
$params = $event->getParams();
if ( empty($params['userId']) )
{
return;
}
$userId = (int) $params['userId'];
if ( OW::getUser()->getId() == $userId )
{
return;
}
if ( BOL_UserService::getInstance()->isBlocked(OW::getUser()->getId(), $params['userId']) )
{
return;
}
$eventParams = array(
'action' => 'mailbox_invite_to_chat',
'ownerId' => $params['userId'],
'viewerId' => OW::getUser()->getId()
);
try
{
OW::getEventManager()->getInstance()->call('privacy_check_permission', $eventParams);
}
catch ( RedirectException $e )
{
return;
}
$isAuthorizedSendMessage = OW::getUser()->isAuthorized('mailbox', 'send_chat_message');
$showSendMessageButton = true;
if ( !$isAuthorizedSendMessage )
{
// check the promotion status
$promotedStatus = BOL_AuthorizationService::getInstance()->getActionStatus('mailbox', 'send_chat_message', array(
'userId' => OW::getUser()->getId()
));
$isPromoted = !empty($promotedStatus['status'])
&& $promotedStatus['status'] == BOL_AuthorizationService::STATUS_PROMOTED;
$showSendMessageButton = $isPromoted;
}
if ( $showSendMessageButton )
{
$linkId = 'mb' . rand(10, 1000000);
$linkSelector = '#' . $linkId;
$script = UTIL_JsGenerator::composeJsString('$({$linkSelector}).click(function(){
OW.trigger("base.online_now_click", [{$userId}]);
});', array('linkSelector'=>$linkSelector, 'userId'=>$params['userId']));
OW::getDocument()->addOnloadScript($script);
$resultArray = array(
BASE_CMP_ProfileActionToolbar::DATA_KEY_LABEL => 'Send Message',
BASE_CMP_ProfileActionToolbar::DATA_KEY_LINK_HREF => 'javascript://',
BASE_CMP_ProfileActionToolbar::DATA_KEY_LINK_ID => $linkId,
BASE_CMP_ProfileActionToolbar::DATA_KEY_ITEM_KEY => "mailbox.send_chat_message",
BASE_CMP_ProfileActionToolbar::DATA_KEY_LINK_ORDER => 0
);
$event->add($resultArray);
}
}//end button
Save file, clear site cache (or do this in developer mode) and it should be there. I replaced the DATA_LABEL with just a plaintext value of 'Send Message,' but you can add your own text label if you wish.
-Jake