Kaynağa Gözat

Ticket #4711 - Automations.

AntonLV 2 yıl önce
ebeveyn
işleme
5aa4ffe042

+ 2 - 0
inc/classes/BxDolCmts.php

@@ -209,6 +209,8 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
 
 
     protected $_iRememberTime = 2592000;
     protected $_iRememberTime = 2592000;
 
 
+    protected $_bLiveUpdates = true;
+
     /**
     /**
      * Constructor
      * Constructor
      * $sSystem - comments system name
      * $sSystem - comments system name

+ 19 - 20
inc/js/classes/BxDolCmts.js

@@ -111,27 +111,24 @@ BxDolCmts.prototype.cmtAfterPostSubmit = function (oCmtForm, oData)
         var oParent = oCmtForm.parents('.cmt-reply:first');
         var oParent = oCmtForm.parents('.cmt-reply:first');
 
 
         if(oData && oData.id != undefined) {
         if(oData && oData.id != undefined) {
-            var iCmtId = parseInt(oData.id);
-            if(iCmtId > 0) {
-                $this._getCmt(oCmtForm, iCmtId);
+            $this._getCmt(oCmtForm, oData.id);
 
 
-                //--- Update form
-                var iCmtParentId = parseInt(oData.parent_id);
-                if(iCmtParentId == 0)
-                    $this._getForm(undefined, {CmtParent: iCmtParentId}, function(sFormWrp) {
-                        if(sFormWrp && sFormWrp.length > 0)
-                            sFormWrp = $(sFormWrp).html();
+            //--- Update form
+            var iCmtParentId = parseInt(oData.parent_id);
+            if(iCmtParentId == 0)
+                $this._getForm(undefined, {CmtParent: iCmtParentId}, function(sFormWrp) {
+                    if(sFormWrp && sFormWrp.length > 0)
+                        sFormWrp = $(sFormWrp).html();
 
 
-                        oParent.hide().html(sFormWrp).bxProcessHtml().show();
+                    oParent.hide().html(sFormWrp).bxProcessHtml().show();
 
 
-                        $this.cmtInitFormPost(oParent.find('form'));
-                    });
-                else
-                    oParent.remove();
+                    $this.cmtInitFormPost(oParent.find('form'));
+                });
+            else
+                oParent.remove();
 
 
-                //--- Update counter
-                $this.cmtUpdateCounter(oCmtForm, oData);
-            }
+            //--- Update counter
+            $this.cmtUpdateCounter(oCmtForm, oData);
 
 
             return;
             return;
         }
         }
@@ -938,15 +935,17 @@ BxDolCmts.prototype._getCmt = function (e, iCmtId)
                     var oAdded = null;
                     var oAdded = null;
                     switch($this._sPostFormPosition) {
                     switch($this._sPostFormPosition) {
                         case 'top':
                         case 'top':
-                            oAdded = $(this).children('li.cmt:first').before($(oData.content).hide()).prev('li.cmt:hidden');
+                            oAdded = $(this).children('li.cmt:first').before($(oData.content).hide()).prevAll('li.cmt:hidden');
                             break;
                             break;
 
 
                         case 'bottom':
                         case 'bottom':
-                            oAdded = $(this).children('li.cmt:last').after($(oData.content).hide()).next('li.cmt:hidden');
+                            oAdded = $(this).children('li.cmt:last').after($(oData.content).hide()).nextAll('li.cmt:hidden');
                             break;
                             break;
                     }
                     }
 
 
-                    oAdded.bxProcessHtml().bx_anim('toggle', $this._sAnimationEffect, $this._iAnimationSpeed);
+                    oAdded.each(function() {
+                        $(this).bxProcessHtml().bx_anim('toggle', $this._sAnimationEffect, $this._iAnimationSpeed);
+                    });
                 }
                 }
                 //-- There is no comments at all ---//
                 //-- There is no comments at all ---//
                 else
                 else

+ 57 - 25
studio/classes/BxDolStudioAgentsAutomatorsCmts.php

@@ -17,12 +17,39 @@ class BxDolStudioAgentsAutomatorsCmts extends BxTemplCmts
     {
     {
         parent::__construct($sSystem, $iId, $iInit, $oTemplate);
         parent::__construct($sSystem, $iId, $iInit, $oTemplate);
 
 
-        $this->_oQueryAgents = new BxDolStudioAgentsQuery();
+        $this->_bLiveUpdates = false;
 
 
+        $this->_oQueryAgents = new BxDolStudioAgentsQuery();
         $this->_iProfileIdAi = BxDolAI::getInstance()->getProfileId(); 
         $this->_iProfileIdAi = BxDolAI::getInstance()->getProfileId(); 
         $this->_bAuto = false;
         $this->_bAuto = false;
     }
     }
 
 
+    public function actionGetCmt ()
+    {
+        if(!$this->isEnabled())
+            return echoJson([]);
+
+        if($this->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED)
+            return echoJson([]);
+
+        $mixedCmtId = bx_process_input(bx_get('Cmt'));
+        $sCmtBrowse = ($sCmtBrowse = bx_get('CmtBrowse')) !== false ? bx_process_input($sCmtBrowse, BX_DATA_TEXT) : '';
+        $sCmtDisplay = ($sCmtDisplay = bx_get('CmtDisplay')) !== false ? bx_process_input($sCmtDisplay, BX_DATA_TEXT) : '';
+
+        $aCmtIds = strpos($mixedCmtId, ',') !== false ? explode(',', $mixedCmtId) : [$mixedCmtId];
+
+        $sContent = '';
+        foreach($aCmtIds as $iCmtId)
+            $sContent .= $this->getComment((int)$iCmtId, ['type' => $sCmtBrowse], ['type' => $sCmtDisplay, 'dynamic_mode' => true]);
+
+        $aCmt = $this->getCommentRow((int)reset($aCmtIds));
+        echoJson([
+            'parent_id' => $aCmt['cmt_parent_id'],
+            'vparent_id' => $aCmt['cmt_parent_id'],
+            'content' => $sContent
+        ]);
+    }
+
     public function getCommentsBlock($aBp = [], $aDp = [])
     public function getCommentsBlock($aBp = [], $aDp = [])
     {
     {
         $aComments = parent::getCommentsBlock($aBp, ['in_designbox' => false]);
         $aComments = parent::getCommentsBlock($aBp, ['in_designbox' => false]);
@@ -101,34 +128,39 @@ class BxDolStudioAgentsAutomatorsCmts extends BxTemplCmts
     public function onPostAfter($iCmtId, $aDp = [])
     public function onPostAfter($iCmtId, $aDp = [])
     {
     {
         $mixedResult = parent::onPostAfter($iCmtId, $aDp);
         $mixedResult = parent::onPostAfter($iCmtId, $aDp);
-        if(!$this->_bAuto && $mixedResult !== false) {
-            $iObjId = (int)$this->getId();
+        if($this->_bAuto || $mixedResult === false) 
+            return $mixedResult;
+        
+        $iObjId = (int)$this->getId();
+
+        $oAI = BxDolAI::getInstance();
 
 
-            $oAI = BxDolAI::getInstance();
+        $aMessages = [
+            ['role' => 'system', 'content' => $oAI->getAutomatorInstructions($aAutomator['type'], true)],
+        ];
+
+        $aAutomator = $oAI->getAutomator($iObjId, true);
 
 
-            $aMessages = [
-                ['role' => 'system', 'content' => $oAI->getAutomatorInstructions($aAutomator['type'], true)],
+        $aComments = $this->_oQuery->getCommentsBy(['type' => 'object_id', 'object_id' => $iObjId]);
+        if($aAutomator['type'] == BX_DOL_AI_AUTOMATOR_EVENT && !empty($aAutomator['params']['trigger']))
+            $aComments[0]['cmt_text'] .= $aAutomator['params']['trigger'];
+
+        foreach($aComments as $aComment)
+            $aMessages[] = [
+                'role' => (int)$aComment['cmt_author_id'] == $this->_iProfileIdAi ? 'assistant' : 'user',
+                'content' => $aComment['cmt_text']
             ];
             ];
 
 
-            $aAutomator = $oAI->getAutomator($iObjId, true);
-
-            $aComments = $this->_oQuery->getCommentsBy(['type' => 'object_id', 'object_id' => $iObjId]);
-            if($aAutomator['type'] == BX_DOL_AI_AUTOMATOR_EVENT && !empty($aAutomator['params']['trigger']))
-                $aComments[0]['cmt_text'] .= $aAutomator['params']['trigger'];
-
-            foreach($aComments as $aComment)
-                $aMessages[] = [
-                    'role' => (int)$aComment['cmt_author_id'] == $this->_iProfileIdAi ? 'assistant' : 'user',
-                    'content' => $aComment['cmt_text']
-                ];
-
-            $sResponse = $oAI->chat($aAutomator['url'], $aAutomator['model'], $aAutomator['key'], $aAutomator['params'], $aMessages);
-            if($sResponse != 'false') 
-                $this->addAuto([
-                    'cmt_author_id' => $this->_iProfileIdAi,
-                    'cmt_parent_id' => 0,
-                    'cmt_text' => $sResponse
-                ]);
+        $sResponse = $oAI->chat($aAutomator['model_url'], $aAutomator['model_model'], $aAutomator['model_key'], $aAutomator['model_params'], $aMessages);
+        if($sResponse != 'false') {
+            $mixedResultAuto = $this->addAuto([
+                'cmt_author_id' => $this->_iProfileIdAi,
+                'cmt_parent_id' => 0,
+                'cmt_text' => $sResponse
+            ]);
+
+            if($mixedResultAuto !== false)
+                $mixedResult['id'] .= ',' . $mixedResultAuto['id'];
         }
         }
 
 
         return $mixedResult;
         return $mixedResult;

+ 2 - 2
studio/template/scripts/BxBaseStudioAgentsAutomators.php

@@ -64,7 +64,7 @@ class BxBaseStudioAgentsAutomators extends BxDolStudioAgentsAutomators
 
 
             $aModel = $oAI->getModel($iModel);
             $aModel = $oAI->getModel($iModel);
 
 
-            $bIsValid = true;/*
+            $bIsValid = true;
             switch($sType) {
             switch($sType) {
                 case BX_DOL_AI_AUTOMATOR_EVENT:
                 case BX_DOL_AI_AUTOMATOR_EVENT:
                     $sResponse = $oAI->chat($aModel['url'], $aModel['model'], $aModel['key'], $aModel['params'], $aMessages);
                     $sResponse = $oAI->chat($aModel['url'], $aModel['model'], $aModel['key'], $aModel['params'], $aMessages);
@@ -110,7 +110,7 @@ class BxBaseStudioAgentsAutomators extends BxDolStudioAgentsAutomators
                     $bIsValid = false;
                     $bIsValid = false;
                 }
                 }
             }
             }
-*/
+
             if($bIsValid) {
             if($bIsValid) {
                 if(($iId = $oForm->insert($aValsToAdd)) !== false) {
                 if(($iId = $oForm->insert($aValsToAdd)) !== false) {
                     if(($oCmts = BxDolCmts::getObjectInstance($this->_sCmts, $iId)) !== null) {
                     if(($oCmts = BxDolCmts::getObjectInstance($this->_sCmts, $iId)) !== null) {

+ 2 - 2
template/scripts/BxBaseCmts.php

@@ -198,7 +198,7 @@ class BxBaseCmts extends BxDolCmts
         $oSockets = BxDolSockets::getInstance();
         $oSockets = BxDolSockets::getInstance();
         $bSockets = $oSockets->isEnabled();
         $bSockets = $oSockets->isEnabled();
 
 
-        if(!$bSockets) {
+        if($this->_bLiveUpdates && !$bSockets) {
             //add live update
             //add live update
             $this->actionResumeLiveUpdate();
             $this->actionResumeLiveUpdate();
 
 
@@ -213,7 +213,7 @@ class BxBaseCmts extends BxDolCmts
         $sCommentsPinned = $this->getCommentsPinned(array_merge($aBp, ['pinned' => 1]), $aDp);
         $sCommentsPinned = $this->getCommentsPinned(array_merge($aBp, ['pinned' => 1]), $aDp);
         $sContentBefore = $this->_getContentBefore($aBp, $aDp);
         $sContentBefore = $this->_getContentBefore($aBp, $aDp);
         $sContentAfter = $this->_getContentAfter($aBp, $aDp);
         $sContentAfter = $this->_getContentAfter($aBp, $aDp);
-        if($bSockets)
+        if($this->_bLiveUpdates && $bSockets)
             $sContentAfter .= $this->getLiveUpdateButton();
             $sContentAfter .= $this->getLiveUpdateButton();
         $sPostFormTop = $this->getFormBoxPost($aBp, array_merge($aDp, ['type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_TOP]));
         $sPostFormTop = $this->getFormBoxPost($aBp, array_merge($aDp, ['type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_TOP]));
         $sPostFormBottom = $this->getFormBoxPost($aBp, array_merge($aDp, ['type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_BOTTOM]));
         $sPostFormBottom = $this->getFormBoxPost($aBp, array_merge($aDp, ['type' => $this->_sDisplayType, 'position' => BX_CMT_PFP_BOTTOM]));