Fixes duplicated transmissions and not working undo of like/dislike

This commit is contained in:
Michael 2018-10-27 11:09:23 +00:00
parent f2ddcbe632
commit 73f596cc46
7 changed files with 30 additions and 43 deletions

View file

@ -830,9 +830,6 @@ function item_post(App $a) {
// We don't fork a new process since this is done anyway with the following command // We don't fork a new process since this is done anyway with the following command
Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], "CreateShadowEntry", $post_id); Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], "CreateShadowEntry", $post_id);
// Call the background process that is delivering the item to the receivers
Worker::add(PRIORITY_HIGH, "Notifier", $notify_type, $post_id);
logger('post_complete'); logger('post_complete');
if ($api_source) { if ($api_source) {

View file

@ -691,9 +691,6 @@ function photos_post(App $a)
$arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="'.$p[0]['type'].'" href="' . System::baseUrl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>'; $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="'.$p[0]['type'].'" href="' . System::baseUrl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
$item_id = Item::insert($arr); $item_id = Item::insert($arr);
if ($item_id) {
Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
}
} }
} }
} }
@ -919,10 +916,6 @@ function photos_post(App $a)
// Update the photo albums cache // Update the photo albums cache
Photo::clearAlbumCache($page_owner_uid); Photo::clearAlbumCache($page_owner_uid);
if ($visible) {
Worker::add(PRIORITY_HIGH, "Notifier", 'wall-new', $item_id);
}
Addon::callHooks('photo_post_end', $item_id); Addon::callHooks('photo_post_end', $item_id);
// addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook

View file

@ -128,9 +128,6 @@ function poke_init(App $a)
$arr['object'] .= '</link></object>' . "\n"; $arr['object'] .= '</link></object>' . "\n";
$item_id = Item::insert($arr); $item_id = Item::insert($arr);
if ($item_id) {
Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
}
Addon::callHooks('post_local_end', $arr); Addon::callHooks('post_local_end', $arr);

View file

@ -1827,9 +1827,17 @@ class Item extends BaseObject
check_user_notification($current_post); check_user_notification($current_post);
if ($notify) { if ($notify) {
Worker::add(['priority' => $priority, 'dont_fork' => true], "Notifier", $notify_type, $current_post); Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $notify_type, $current_post);
} elseif (!empty($parent) && $parent['origin']) { } elseif ($item['visible'] && ((!empty($parent) && $parent['origin']) || $item['origin'])) {
Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], "Notifier", "comment-import", $current_post); if ($item['gravity'] == GRAVITY_ACTIVITY) {
$cmd = $item['origin'] ? 'activity-new' : 'activity-import';
} elseif ($item['gravity'] == GRAVITY_COMMENT) {
$cmd = $item['origin'] ? 'comment-new' : 'comment-import';
} else {
$cmd = 'wall-new';
}
Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', $cmd, $current_post);
} }
return $current_post; return $current_post;
@ -3103,6 +3111,11 @@ class Item extends BaseObject
'unseen' => 1, 'unseen' => 1,
]; ];
$signed = Diaspora::createLikeSignature($item_contact, $new_item);
if (!empty($signed)) {
$new_item['diaspora_signed_text'] = $signed;
}
$new_item_id = self::insert($new_item); $new_item_id = self::insert($new_item);
// If the parent item isn't visible then set it to visible // If the parent item isn't visible then set it to visible
@ -3110,15 +3123,10 @@ class Item extends BaseObject
self::update(['visible' => true], ['id' => $item['id']]); self::update(['visible' => true], ['id' => $item['id']]);
} }
// Save the author information for the like in case we need to relay to Diaspora
Diaspora::storeLikeSignature($item_contact, $new_item_id);
$new_item['id'] = $new_item_id; $new_item['id'] = $new_item_id;
Addon::callHooks('post_local_end', $new_item); Addon::callHooks('post_local_end', $new_item);
Worker::add(PRIORITY_HIGH, "Notifier", "like", $new_item_id);
return true; return true;
} }

View file

@ -549,16 +549,20 @@ class Transmitter
* Creates the activity or fetches it from the cache * Creates the activity or fetches it from the cache
* *
* @param integer $item_id * @param integer $item_id
* @param boolean $force Force new cache entry
* *
* @return array with the activity * @return array with the activity
*/ */
public static function createCachedActivityFromItem($item_id) public static function createCachedActivityFromItem($item_id, $force = false)
{ {
$cachekey = 'APDelivery:createActivity:' . $item_id; $cachekey = 'APDelivery:createActivity:' . $item_id;
if (!$force) {
$data = Cache::get($cachekey); $data = Cache::get($cachekey);
if (!is_null($data)) { if (!is_null($data)) {
return $data; return $data;
} }
}
$data = ActivityPub\Transmitter::createActivityFromItem($item_id); $data = ActivityPub\Transmitter::createActivityFromItem($item_id);

View file

@ -4113,14 +4113,14 @@ class Diaspora
} }
/** /**
* @brief Stores the signature for likes that are created on our system * @brief Creates the signature for likes that are created on our system
* *
* @param array $contact The contact array of the "like" * @param array $contact The contact array of the "like"
* @param int $post_id The post id of the "like" * @param array $item Item array
* *
* @return bool Success * @return array Signed content
*/ */
public static function storeLikeSignature(array $contact, $post_id) public static function createLikeSignature(array $contact, array $item)
{ {
// Is the contact the owner? Then fetch the private key // Is the contact the owner? Then fetch the private key
if (!$contact['self'] || ($contact['uid'] == 0)) { if (!$contact['self'] || ($contact['uid'] == 0)) {
@ -4135,11 +4135,6 @@ class Diaspora
$contact["uprvkey"] = $user['prvkey']; $contact["uprvkey"] = $user['prvkey'];
$item = Item::selectFirst([], ['id' => $post_id]);
if (!DBA::isResult($item)) {
return false;
}
if (!in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) { if (!in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
return false; return false;
} }
@ -4151,14 +4146,7 @@ class Diaspora
$message["author_signature"] = self::signature($contact, $message); $message["author_signature"] = self::signature($contact, $message);
/* return $message;
* Now store the signature more flexible to dynamically support new fields.
* This will break Diaspora compatibility with Friendica versions prior to 3.5.
*/
DBA::insert('sign', ['iid' => $post_id, 'signed_text' => json_encode($message)]);
logger('Stored diaspora like signature');
return true;
} }
/** /**

View file

@ -539,7 +539,7 @@ class Notifier
} }
// Fill the item cache // Fill the item cache
ActivityPub\Transmitter::createCachedActivityFromItem($item_id); ActivityPub\Transmitter::createCachedActivityFromItem($item_id, true);
foreach ($inboxes as $inbox) { foreach ($inboxes as $inbox) {
logger('Deliver ' . $item_id .' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG); logger('Deliver ' . $item_id .' to ' . $inbox .' via ActivityPub', LOGGER_DEBUG);