Skip to content

Issues-213, Issues-226 #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/vanilla/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
$Configuration['Garden']['Email']['SmtpPort'] = getenv('MAIL_SMTP_PORT');
$Configuration['Garden']['Email']['SmtpSecurity'] = getenv('MAIL_SMTP_SECURITY');
$Configuration['Garden']['UpdateToken'] = '105e786dc643fd20143d3c137b593af168560c13';
$Configuration['Garden']['InputFormatter'] = 'Rich';
$Configuration['Garden']['InputFormatter'] = 'Markdown';
$Configuration['Garden']['Version'] = 'Undefined';
$Configuration['Garden']['CanProcessImages'] = true;
$Configuration['Garden']['Theme'] = 'topcoder-theme';
$Configuration['Garden']['MobileTheme'] = 'topcoder-theme';
$Configuration['Garden']['Profile']['EditPhotos'] = false;
$Configuration['Garden']['SystemUserID'] = '1';
$Configuration['Garden']['MobileInputFormatter'] = 'Rich';
$Configuration['Garden']['MobileInputFormatter'] = 'Markdown';
$Configuration['Garden']['AllowFileUploads'] = true;
$Configuration['Garden']['EditContentTimeout'] = -1;
$Configuration['Garden']['Profile']['EditPhotos'] = false;
Expand Down
20 changes: 15 additions & 5 deletions vanilla/applications/vanilla/models/class.commentmodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public function lookup(array $where = [], $permissionFilter = true, $limit = nul
* @param array $comment
* @param array $discussion
*/
private function notifyNewComment(?array $comment, ?array $discussion) {
public function notifyNewComment(?array $comment, ?array $discussion) {
if ($comment === null || $discussion === null) {
return;
}
Expand All @@ -563,6 +563,13 @@ private function notifyNewComment(?array $comment, ?array $discussion) {
$discussionUserID = $discussion["InsertUserID"] ?? null;
$format = $comment["Format"] ?? null;

$mediaModel = new MediaModel();
$sqlWhere = [
'ForeignTable' => 'comment',
'ForeignID' => $commentID
];
$mediaData = $mediaModel->getWhere($sqlWhere)->resultArray();

// Prepare the notification queue.
$data = [
"ActivityType" => "Comment",
Expand All @@ -577,6 +584,7 @@ private function notifyNewComment(?array $comment, ?array $discussion) {
"Data" => [
"Name" => $discussion["Name"] ?? null,
"Category" => $category["Name"] ?? null,
"Media" => $mediaData
]
];

Expand Down Expand Up @@ -1362,10 +1370,12 @@ public function save2($CommentID, $Insert, $CheckExisting = true, $IncUser = fal
if ($Discussion->CategoryID > 0) {
CategoryModel::instance()->incrementLastComment($Fields);
}
$this->notifyNewComment(
$Fields ? (array)$Fields : null,
$Discussion ? (array)$Discussion : null
);
if(!c('EnabledPlugins.editor', false)) {
$this->notifyNewComment(
$Fields ? (array)$Fields : null,
$Discussion ? (array)$Discussion : null
);
}
}
}

Expand Down
22 changes: 21 additions & 1 deletion vanilla/applications/vanilla/models/class.discussionmodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,7 @@ public function setField($rowID, $property, $value = false) {
public function save($formPostValues, $settings = false) {
// Define the primary key in this model's table.
$this->defineSchema();
$sendNewDiscussionNotification = false;

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

$discussion = $this->getID($discussionID, DATASET_TYPE_ARRAY);
$this->notifyNewDiscussion($discussion);
$sendNewDiscussionNotification = true;
}

// Get CategoryID of this discussion
Expand All @@ -2244,7 +2245,18 @@ public function save($formPostValues, $settings = false) {
$this->EventArguments['FormPostValues'] = $formPostValues;
$this->EventArguments['Fields'] = $fields;
$this->EventArguments['DiscussionID'] = $discussionID;
$this->EventArguments['SendNewDiscussionNotification'] = $sendNewDiscussionNotification;
$this->fireEvent('AfterSaveDiscussion');


//FIX: https://github.com/topcoder-platform/forums/issues/213
// If the plugin is enabled then send notifications after updating MediaTables with discussionID
if ($sendNewDiscussionNotification === true) {
if(!c('EnabledPlugins.editor', false)) {
$discussion = $this->getID($discussionID, DATASET_TYPE_ARRAY);
$this->notifyNewDiscussion($discussion);
}
}
}
}

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

// FIX: https://github.com/topcoder-platform/forums/issues/213
$mediaModel = new MediaModel();
$sqlWhere = [
'ForeignTable' => 'discussion',
'ForeignID' => $discussionID
];
$mediaData = $mediaModel->getWhere($sqlWhere)->resultArray();
$data = [
"ActivityType" => "Discussion",
"ActivityUserID" => $insertUserID,
Expand All @@ -2301,6 +2320,7 @@ public function notifyNewDiscussion($discussion, $activityModel = null, $activit
"Data" => [
"Name" => $name,
"Category" => $categoryName,
"Media" => $mediaData
]
];

Expand Down
Loading