From 1f5e306760339d8c24272abadb6306ca7ac8a6ac Mon Sep 17 00:00:00 2001 From: Nym Coy Date: Tue, 9 Aug 2016 21:02:57 +0530 Subject: [PATCH] Set object_type to ActivityObject::NOTE on notices imported from Twitter. Previously was unset which caused ActivityHandler to throw an error during onStartOpenNoticeListItemElement() and the notices would not display in the timeline. --- plugins/TwitterBridge/TwitterBridgePlugin.php | 24 +++++++++++++++++++ plugins/TwitterBridge/lib/twitterimport.php | 20 +++++++++------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/plugins/TwitterBridge/TwitterBridgePlugin.php b/plugins/TwitterBridge/TwitterBridgePlugin.php index 0a88716853..5bf63a3946 100644 --- a/plugins/TwitterBridge/TwitterBridgePlugin.php +++ b/plugins/TwitterBridge/TwitterBridgePlugin.php @@ -570,4 +570,28 @@ class TwitterBridgePlugin extends Plugin return true; } + + /** + * Set the object_type field of previously imported Twitter notices to + * ActivityObject::NOTE if they are unset. Null object_type caused a notice + * not to show on the timeline. + */ + public function onEndUpgrade() + { + printfnq("Ensuring all Twitter notices have an object_type..."); + + $notice = new Notice(); + $notice->whereAdd("source='twitter'"); + $notice->whereAdd('object_type IS NULL'); + + if ($notice->find()) { + while ($notice->fetch()) { + $orig = Notice::getKV('id', $notice->id); + $notice->object_type = ActivityObject::NOTE; + $notice->update($orig); + } + } + + printfnq("DONE.\n"); + } } diff --git a/plugins/TwitterBridge/lib/twitterimport.php b/plugins/TwitterBridge/lib/twitterimport.php index fe11695c1f..cdbe4a3a69 100644 --- a/plugins/TwitterBridge/lib/twitterimport.php +++ b/plugins/TwitterBridge/lib/twitterimport.php @@ -137,7 +137,10 @@ class TwitterImport 'twitter', array('repeat_of' => $original->id, 'uri' => $statusUri, - 'is_local' => Notice::GATEWAY)); + 'is_local' => Notice::GATEWAY, + 'object_type' => ActivityObject::NOTE, + 'verb' => ActivityVerb::POST + )); common_log(LOG_INFO, "Saved {$repeat->id} as a repeat of {$original->id}"); Notice_to_status::saveNew($repeat->id, $statusId); return $repeat; @@ -146,18 +149,19 @@ class TwitterImport $notice = new Notice(); - $notice->profile_id = $profile->id; - $notice->uri = $statusUri; - $notice->url = $statusUri; - $notice->verb = ActivityVerb::POST; - $notice->created = strftime( + $notice->profile_id = $profile->id; + $notice->uri = $statusUri; + $notice->url = $statusUri; + $notice->verb = ActivityVerb::POST; + $notice->object_type = ActivityObject::NOTE; + $notice->created = strftime( '%Y-%m-%d %H:%M:%S', strtotime($status->created_at) ); - $notice->source = 'twitter'; + $notice->source = 'twitter'; - $notice->reply_to = null; + $notice->reply_to = null; $replyTo = twitter_id($status, 'in_reply_to_status_id'); if (!empty($replyTo)) {