We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Add "Send Message" button to user profile toolbar | Forum

JB TECH
JB TECH May 19 '18

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

JB TECH
JB TECH May 23 '18
Bumping due to the horrendous amount of spam still affecting this website.
Blaire
Blaire Jun 11 '18
I don't use the chat through Oxwall or cometchat. (I use arrowchat just out of personal preference, I suppose.) I can see this feature being very helpful, very handy for helping people increase interactions on a site.

Have you considered somehow developing this change into a plugin so that you can sell it in the store here and make a few dollars for your work? Perhaps you should. :)
JB TECH
JB TECH Jun 19 '18

Thanks! It's just a small change, and it might find it's way into an official Oxwall update if the changes in the respiratory (ever) get published (assuming Oxwall is still being updated in the background of all this silence).


gami
gami Jan 7 '19

hi jake,


thanks for the type. is that now for the normal messanger of oxwall? I do not get that unfortunately ... :-( You can not make the php file available :-)

JB TECH
JB TECH Jan 8 '19

Gami,


You need to follow the instructions in the original post. Add the code to your current version of Mailbox (the Oxwall 1.8 version).


-Jake

kalvindarwan
kalvindarwan Dec 20 '23
Each and every one of our driveways is built top of the line. All of our driveways will not only be able to handle everyday traffic without cracking, but also withstand the occasional house party as well. Danville's Concrete & Masonry Co.
James Walter
James Walter Jan 1
You get your car serviced regularly to prevent it from breaking down, so why not do the same for your truck? Ontario Mobile Mechanic