Răsfoiți Sursa

Ticket #4558 - Build-in API support: Issues with Timeline Repost action.

AntonLV 2 ani în urmă
părinte
comite
7d7bbbe39b

+ 9 - 4
modules/boonex/timeline/classes/BxTimelineMenuItemActions.php

@@ -379,23 +379,28 @@ class BxTimelineMenuItemActions extends BxTemplMenuCustom
         if(!isset($this->_aEvent['reposts'])) 
             return false;
 
-        $aRepostsParams = array(
+        $aRepostsParams = [
             'show_do_repost_text' => $this->_bShowTitles,
             'show_counter' => $this->_bShowCounters,
             'show_counter_label_icon' => $this->_bShowCountersIcons,
             'dynamic_mode' => $this->_bDynamicMode
-        );
+        ];
 
+        $iOwnerId = $this->_aEvent['owner_id'];
         $sType = $this->_aEvent['type'];
         $sAction = $this->_aEvent['action'];
         $iObjectId = $this->_oModule->_oConfig->isSystem($sType, $sAction) ? $this->_aEvent['object_id'] : $this->_aEvent['id'];
 
+        $iAuthorId = $this->_oModule->getUserId();
+        if($this->_oModule->isReposted($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId)) 
+            return false;
+
         if($this->_bIsApi)
             return [
                 'id' => $aItem['id'],
                 'name' => $aItem['name'],
                 'display_type' => 'element',
-                'data' => $this->_oModule->serviceGetRepostElementBlockApi($this->_aEvent['owner_id'], $sType, $sAction, $iObjectId, $aRepostsParams)
+                'data' => $this->_oModule->serviceGetRepostElementBlockApi($iOwnerId, $sType, $sAction, $iObjectId, $aRepostsParams)
             ];
 
         $sMethodName = '';
@@ -403,7 +408,7 @@ class BxTimelineMenuItemActions extends BxTemplMenuCustom
         switch($this->_sMode) {
             case self::$_sModeActions:
                 $sMethodName = 'serviceGetRepostElementBlock';
-                $aMethodParams = [$this->_aEvent['owner_id'], $sType, $sAction, $iObjectId, $aRepostsParams];
+                $aMethodParams = [$iOwnerId, $sType, $sAction, $iObjectId, $aRepostsParams];
                 break;
 
             case self::$_sModeCounters:

+ 32 - 4
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -2811,7 +2811,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
         if(empty($aReposted) || !is_array($aReposted))
             return [];
-        
+
         $aParams = array_merge($this->_oConfig->getRepostDefaults(true), $aParams);
 
         $bPerformed = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $this->getUserId());
@@ -2819,6 +2819,17 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
 
         $sDo = isset($aParams['do']) ? $aParams['do'] : 'repost';
 
+        $sDataType = $sType;
+        $sDataAction = $sAction;
+        $iDataObjectId = $iObjectId;
+        if(($sCommonPrefix = $this->_oConfig->getPrefix('common_post')) && str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
+            $aRepostedData = unserialize($aReposted['content']);
+
+            $sDataType = $aRepostedData['type'];
+            $sDataAction = $aRepostedData['action'];
+            $iDataObjectId = $aRepostedData['object_id'];
+        }
+
         return [
             'type' => 'reposts',
             'system' => $sType . (!empty($sAction) ? '_' . $sAction : ''),
@@ -2832,9 +2843,9 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
                 'data' => [
                     'author_id' => $iOwnerId,
                     'owner_id' => $iOwnerId,
-                    'type' => $sType,
-                    'action' => $sAction,
-                    'object_id' => $iObjectId
+                    'type' => $sDataType,
+                    'action' => $sDataAction,
+                    'object_id' => $iDataObjectId
                 ]
             ],
             'counter' => []
@@ -3100,6 +3111,23 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         return $this->repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, false, $bForce);
     }
 
+    public function isReposted($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId)
+    {
+        $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
+        if(empty($aReposted) || !is_array($aReposted))
+            return false;
+
+        if(str_replace($this->_oConfig->getPrefix('common_post'), '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
+            $aRepostedData = unserialize($aReposted['content']);
+
+            $aReposted = $this->_oDb->getReposted($aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
+            if(empty($aReposted) || !is_array($aReposted))
+                return false;
+        }
+
+        return $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
+    }
+
     public function repost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $mixedData = false, $bForce = false)
     {
         $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);