From 69d157c3190d41d62a8973d1b9871506bc63edf2 Mon Sep 17 00:00:00 2001
From: Hypolite Petovan <mrpetovan@gmail.com>
Date: Mon, 10 Apr 2017 00:08:14 -0400
Subject: [PATCH 1/4] Add spoiler tags for Mastodon Content Warning

---
 include/ostatus.php | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/include/ostatus.php b/include/ostatus.php
index 9b7849509..73fcb4757 100644
--- a/include/ostatus.php
+++ b/include/ostatus.php
@@ -353,14 +353,21 @@ class ostatus {
 				continue;
 			}
 
-			$item["body"] = add_page_info_to_body(html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue));
 			$item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue;
 
-			if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) OR ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
+			if ($item["object-type"] == ACTIVITY_OBJ_NOTE && $xpath->evaluate('boolean(atom:summary)', $entry)) {
+				// Mastodon Content Warning
+				$clear_text = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
+				$hidden_text = $xpath->query('atom:content/text()', $entry)->item(0)->nodeValue;
+
+				$item["body"] = add_page_info_to_body(html2bbcode($clear_text) . '[spoiler]' . html2bbcode($hidden_text) . '[/spoiler]');
+			} elseif (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) OR ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
 				$item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
 				$item["body"] = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
 			} elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) {
 				$item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
+			} else {
+				$item["body"] = add_page_info_to_body(html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue));
 			}
 			$item["object"] = $xml;
 			$item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue;

From ada5c4cc6a84e2b62da32346216fa2738c418989 Mon Sep 17 00:00:00 2001
From: Hypolite Petovan <mrpetovan@gmail.com>
Date: Mon, 10 Apr 2017 00:57:36 -0400
Subject: [PATCH 2/4] Add Content Warning support for comments too

Doh!
---
 include/ostatus.php | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/ostatus.php b/include/ostatus.php
index 73fcb4757..9c1246c85 100644
--- a/include/ostatus.php
+++ b/include/ostatus.php
@@ -354,8 +354,9 @@ class ostatus {
 			}
 
 			$item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue;
+			$item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue;
 
-			if ($item["object-type"] == ACTIVITY_OBJ_NOTE && $xpath->evaluate('boolean(atom:summary)', $entry)) {
+			if ($item["verb"] == ACTIVITY_POST && $xpath->evaluate('boolean(atom:summary)', $entry)) {
 				// Mastodon Content Warning
 				$clear_text = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
 				$hidden_text = $xpath->query('atom:content/text()', $entry)->item(0)->nodeValue;
@@ -370,7 +371,7 @@ class ostatus {
 				$item["body"] = add_page_info_to_body(html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue));
 			}
 			$item["object"] = $xml;
-			$item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue;
+
 
 			/// @TODO
 			/// Delete a message

From e45da5bcd3c987ba0b817c30261f75517a0a9eac Mon Sep 17 00:00:00 2001
From: Hypolite Petovan <mrpetovan@gmail.com>
Date: Mon, 10 Apr 2017 21:11:28 -0400
Subject: [PATCH 3/4] Rewrote code according to @annando feedback

- Normalize boolean operators
---
 include/ostatus.php | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/include/ostatus.php b/include/ostatus.php
index 9c1246c85..b8db50cd1 100644
--- a/include/ostatus.php
+++ b/include/ostatus.php
@@ -353,26 +353,25 @@ class ostatus {
 				continue;
 			}
 
+			$item["body"] = add_page_info_to_body(html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue));
 			$item["object-type"] = $xpath->query('activity:object-type/text()', $entry)->item(0)->nodeValue;
 			$item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue;
 
-			if ($item["verb"] == ACTIVITY_POST && $xpath->evaluate('boolean(atom:summary)', $entry)) {
-				// Mastodon Content Warning
+			// Mastodon Content Warning
+			if ($item["verb"] == ACTIVITY_POST AND $xpath->evaluate('boolean(atom:summary)', $entry)) {
 				$clear_text = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
-				$hidden_text = $xpath->query('atom:content/text()', $entry)->item(0)->nodeValue;
 
-				$item["body"] = add_page_info_to_body(html2bbcode($clear_text) . '[spoiler]' . html2bbcode($hidden_text) . '[/spoiler]');
-			} elseif (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) OR ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
+				$item["body"] = html2bbcode($clear_text) . '[spoiler]' . $item["body"] . '[/spoiler]';
+			}
+
+			if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) OR ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
 				$item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
 				$item["body"] = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
 			} elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) {
 				$item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
-			} else {
-				$item["body"] = add_page_info_to_body(html2bbcode($xpath->query('atom:content/text()', $entry)->item(0)->nodeValue));
 			}
 			$item["object"] = $xml;
 
-
 			/// @TODO
 			/// Delete a message
 			if ($item["verb"] == "qvitter-delete-notice") {
@@ -2060,7 +2059,7 @@ class ostatus {
 
 		$mentioned = array();
 
-		if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
+		if (($item['parent'] != $item['id']) OR ($item['parent-uri'] !== $item['uri']) OR (($item['thr-parent'] !== '') AND ($item['thr-parent'] !== $item['uri']))) {
 			$parent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `id` = %d", intval($item["parent"]));
 			$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
 

From 21bb47a2e5347ffade1ec17594ed0228237e832a Mon Sep 17 00:00:00 2001
From: Hypolite Petovan <mrpetovan@gmail.com>
Date: Tue, 11 Apr 2017 02:12:14 -0400
Subject: [PATCH 4/4] Added "braces" for @annando

---
 include/ostatus.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/ostatus.php b/include/ostatus.php
index b8db50cd1..3b263417a 100644
--- a/include/ostatus.php
+++ b/include/ostatus.php
@@ -358,7 +358,7 @@ class ostatus {
 			$item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue;
 
 			// Mastodon Content Warning
-			if ($item["verb"] == ACTIVITY_POST AND $xpath->evaluate('boolean(atom:summary)', $entry)) {
+			if (($item["verb"] == ACTIVITY_POST) AND $xpath->evaluate('boolean(atom:summary)', $entry)) {
 				$clear_text = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
 
 				$item["body"] = html2bbcode($clear_text) . '[spoiler]' . $item["body"] . '[/spoiler]';