Skip to content

Commit db48a6f

Browse files
committed
Issues-213
1 parent d6eb747 commit db48a6f

File tree

3 files changed

+67
-14
lines changed

3 files changed

+67
-14
lines changed

vanilla/applications/vanilla/models/class.commentmodel.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ public function lookup(array $where = [], $permissionFilter = true, $limit = nul
541541
* @param array $comment
542542
* @param array $discussion
543543
*/
544-
private function notifyNewComment(?array $comment, ?array $discussion) {
544+
public function notifyNewComment(?array $comment, ?array $discussion) {
545545
if ($comment === null || $discussion === null) {
546546
return;
547547
}
@@ -563,6 +563,13 @@ private function notifyNewComment(?array $comment, ?array $discussion) {
563563
$discussionUserID = $discussion["InsertUserID"] ?? null;
564564
$format = $comment["Format"] ?? null;
565565

566+
$mediaModel = new MediaModel();
567+
$sqlWhere = [
568+
'ForeignTable' => 'comment',
569+
'ForeignID' => $commentID
570+
];
571+
$mediaData = $mediaModel->getWhere($sqlWhere)->resultArray();
572+
566573
// Prepare the notification queue.
567574
$data = [
568575
"ActivityType" => "Comment",
@@ -577,6 +584,7 @@ private function notifyNewComment(?array $comment, ?array $discussion) {
577584
"Data" => [
578585
"Name" => $discussion["Name"] ?? null,
579586
"Category" => $category["Name"] ?? null,
587+
"Media" => $mediaData
580588
]
581589
];
582590

@@ -1362,10 +1370,12 @@ public function save2($CommentID, $Insert, $CheckExisting = true, $IncUser = fal
13621370
if ($Discussion->CategoryID > 0) {
13631371
CategoryModel::instance()->incrementLastComment($Fields);
13641372
}
1365-
$this->notifyNewComment(
1366-
$Fields ? (array)$Fields : null,
1367-
$Discussion ? (array)$Discussion : null
1368-
);
1373+
if(!c('EnabledPlugins.editor', false)) {
1374+
$this->notifyNewComment(
1375+
$Fields ? (array)$Fields : null,
1376+
$Discussion ? (array)$Discussion : null
1377+
);
1378+
}
13691379
}
13701380
}
13711381

vanilla/applications/vanilla/models/class.discussionmodel.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1969,6 +1969,7 @@ public function setField($rowID, $property, $value = false) {
19691969
public function save($formPostValues, $settings = false) {
19701970
// Define the primary key in this model's table.
19711971
$this->defineSchema();
1972+
$sendNewDiscussionNotification = false;
19721973

19731974
// If the site isn't configured to use categories, don't allow one to be set.
19741975
if (!c('Vanilla.Categories.Use', true)) {
@@ -2223,7 +2224,7 @@ public function save($formPostValues, $settings = false) {
22232224
$formPostValues['DiscussionID'] = $discussionID;
22242225

22252226
$discussion = $this->getID($discussionID, DATASET_TYPE_ARRAY);
2226-
$this->notifyNewDiscussion($discussion);
2227+
$sendNewDiscussionNotification = true;
22272228
}
22282229

22292230
// Get CategoryID of this discussion
@@ -2244,7 +2245,18 @@ public function save($formPostValues, $settings = false) {
22442245
$this->EventArguments['FormPostValues'] = $formPostValues;
22452246
$this->EventArguments['Fields'] = $fields;
22462247
$this->EventArguments['DiscussionID'] = $discussionID;
2248+
$this->EventArguments['SendNewDiscussionNotification'] = $sendNewDiscussionNotification;
22472249
$this->fireEvent('AfterSaveDiscussion');
2250+
2251+
2252+
//FIX: https://github.com/topcoder-platform/forums/issues/213
2253+
// If the plugin is enabled then send notifications after updating MediaTables with discussionID
2254+
if ($sendNewDiscussionNotification === true) {
2255+
if(!c('EnabledPlugins.editor', false)) {
2256+
$discussion = $this->getID($discussionID, DATASET_TYPE_ARRAY);
2257+
$this->notifyNewDiscussion($discussion);
2258+
}
2259+
}
22482260
}
22492261
}
22502262

@@ -2288,6 +2300,13 @@ public function notifyNewDiscussion($discussion, $activityModel = null, $activit
22882300
$code = "HeadlineFormat.Discussion";
22892301
}
22902302

2303+
// FIX: https://github.com/topcoder-platform/forums/issues/213
2304+
$mediaModel = new MediaModel();
2305+
$sqlWhere = [
2306+
'ForeignTable' => 'discussion',
2307+
'ForeignID' => $discussionID
2308+
];
2309+
$mediaData = $mediaModel->getWhere($sqlWhere)->resultArray();
22912310
$data = [
22922311
"ActivityType" => "Discussion",
22932312
"ActivityUserID" => $insertUserID,
@@ -2301,6 +2320,7 @@ public function notifyNewDiscussion($discussion, $activityModel = null, $activit
23012320
"Data" => [
23022321
"Name" => $name,
23032322
"Category" => $categoryName,
2323+
"Media" => $mediaData
23042324
]
23052325
];
23062326

vanilla/plugins/editor/class.editor.plugin.php

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,6 @@ public function gdn_form_beforeBodyBox_handler($sender, $args) {
670670
$sender->setValue('Format', $this->Format);
671671
}
672672

673-
674-
675673
// If force Wysiwyg enabled in settings
676674
$needsConversion = (!in_array($this->Format, ['Wysiwyg']));
677675
if (c('Garden.InputFormatter', 'Wysiwyg') == 'Wysiwyg' && $this->ForceWysiwyg == true && $needsConversion) {
@@ -1044,17 +1042,35 @@ public function saveUploads($id, $type) {
10441042
* @param object $sender
10451043
* @param array $args
10461044
*/
1047-
public function postController_afterCommentSave_handler($sender, $args) {
1048-
if (!$args['Comment']) {
1049-
return;
1050-
}
1045+
public function commentModel_afterSaveComment_handler($sender, $args) {
1046+
$commentID = $args['CommentID'];
10511047

1052-
$commentID = $args['Comment']->CommentID;
10531048
if (!$commentID) {
10541049
return;
10551050
}
10561051

10571052
$this->saveUploads($commentID, 'comment');
1053+
1054+
//FIX: See how it works `save2()` method of Comment model
1055+
//Notify users after Updating MediaTable
1056+
$commentModel = new CommentModel();
1057+
$fields = $commentModel->getID($commentID, DATASET_TYPE_ARRAY);
1058+
// Make a quick check so that only the user making the comment can make the notification.
1059+
// This check may be used in the future so should not be depended on later in the method.
1060+
if (Gdn::controller()->deliveryType() === DELIVERY_TYPE_ALL && $fields['InsertUserID'] != GDn::session()->UserID) {
1061+
return;
1062+
}
1063+
$insert = (bool) $args['Insert'];
1064+
$discussionModel = new DiscussionModel();
1065+
$discussionID = val('DiscussionID', $fields);
1066+
$discussion = $discussionModel->getID($discussionID);
1067+
if($insert) {
1068+
$commentModel->notifyNewComment(
1069+
$fields ? (array)$fields : null,
1070+
$discussion ? (array)$discussion : null
1071+
);
1072+
}
1073+
10581074
}
10591075

10601076
/**
@@ -1064,7 +1080,7 @@ public function postController_afterCommentSave_handler($sender, $args) {
10641080
* @param object $sender
10651081
* @param array $args
10661082
*/
1067-
public function postController_afterDiscussionSave_handler($sender, $args) {
1083+
public function discussionModel_afterSaveDiscussion_handler($sender, $args) {
10681084
if (!$args['Discussion']) {
10691085
return;
10701086
}
@@ -1075,8 +1091,15 @@ public function postController_afterDiscussionSave_handler($sender, $args) {
10751091
}
10761092

10771093
$this->saveUploads($discussionID, 'discussion');
1094+
1095+
$sendNewDiscussionNotification = $args['SendNewDiscussionNotification'];
1096+
if($sendNewDiscussionNotification === true) {
1097+
$discussionModel = new DiscussionModel();
1098+
$discussionModel->notifyNewDiscussion($discussionID);
1099+
}
10781100
}
10791101

1102+
10801103
/**
10811104
* Attach files to a message during save.
10821105
*

0 commit comments

Comments
 (0)