Skip to content

Commit

Permalink
Ticket #4558 - Build-in API support: Use socket in Connections actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Aug 21, 2024
1 parent f9b1fdd commit b0f4e14
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions inc/classes/BxDolConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,13 @@ public function onAdded($iInitiator, $iContent, $iMutual)
{
$this->checkAllowedConnect ($iInitiator, $iContent, true, $iMutual, false);

/**
* Update recommendations.
*/
$bMutual = false;
if($this->_aObject['type'] == BX_CONNECTIONS_TYPE_ONE_WAY || ($bMutual = ($this->_aObject['type'] == BX_CONNECTIONS_TYPE_MUTUAL && $iMutual))) {
$oProfileQuery = BxDolProfileQuery::getInstance();

/**
* Update recommendations.
*/
if($this->_aObject['profile_initiator']) {
$aInitiator = $oProfileQuery->getInfoById($iInitiator);
if(bx_srv($aInitiator['type'], 'act_as_profile'))
Expand All @@ -389,6 +389,19 @@ public function onAdded($iInitiator, $iContent, $iMutual)
if(bx_srv($aContent['type'], 'act_as_profile'))
BxDolRecommendation::updateData($iContent);
}

/**
* Call socket.
*/
if(($oSockets = BxDolSockets::getInstance()) && $oSockets->isEnabled()){
$sMessage = json_encode([
'object' => $this->_sObject,
'action' => 'added'
]);

$oSockets->sendEvent('sys_connections', $iInitiator , 'changed', $sMessage);
$oSockets->sendEvent('sys_connections', $iContent , 'changed', $sMessage);
}
}
}

Expand Down Expand Up @@ -432,7 +445,24 @@ public function removeConnection ($iInitiator, $iContent)
return true;
}

public function onRemoved($iInitiator, $iContent) {}
/**
* TODO: Improve - add $iMutual like in onAdded
*/
public function onRemoved($iInitiator, $iContent)
{
/**
* Call socket.
*/
if(($oSockets = BxDolSockets::getInstance()) && $oSockets->isEnabled()){
$sMessage = json_encode([
'object' => $this->_sObject,
'action' => 'deleted'
]);

$oSockets->sendEvent('sys_connections', $iInitiator , 'changed', $sMessage);
$oSockets->sendEvent('sys_connections', $iContent , 'changed', $sMessage);
}
}

/**
* Compound function, which calls getCommonContent, getConnectedContent or getConnectedInitiators depending on $sContentType
Expand Down

0 comments on commit b0f4e14

Please sign in to comment.