+ /**
+ * Creates an announce object entry
+ *
+ * @param array $item
+ * @param array $data activity data
+ *
+ * @return array with activity data
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ private static function createAnnounce($item, $data)
+ {
+ $announce = api_share_as_retweet($item);
+ if (empty($announce['plink'])) {
+ $data['type'] = 'Create';
+ $data['object'] = self::createNote($item);
+ return $data;
+ }
+
+ // Fetch the original id of the object
+ $activity = ActivityPub::fetchContent($announce['plink'], $item['uid']);
+ if (!empty($activity)) {
+ $ldactivity = JsonLD::compact($activity);
+ $id = JsonLD::fetchElement($ldactivity, '@id');
+ if (!empty($id)) {
+ $data['object'] = $id;
+ return $data;
+ }
+ }
+
+ $data['type'] = 'Create';
+ $data['object'] = self::createNote($item);
+ return $data;
+ }
+
+ /**
+ * Creates an activity id for a given contact id
+ *
+ * @param integer $cid Contact ID of target
+ *
+ * @return bool|string activity id
+ */
+ public static function activityIDFromContact($cid)
+ {
+ $contact = DBA::selectFirst('contact', ['uid', 'id', 'created'], ['id' => $cid]);
+ if (!DBA::isResult($contact)) {
+ return false;
+ }
+
+ $hash = hash('ripemd128', $contact['uid'].'-'.$contact['id'].'-'.$contact['created']);
+ $uuid = substr($hash, 0, 8). '-' . substr($hash, 8, 4) . '-' . substr($hash, 12, 4) . '-' . substr($hash, 16, 4) . '-' . substr($hash, 20, 12);
+ return System::baseUrl() . '/activity/' . $uuid;
+ }
+
+ /**
+ * Transmits a contact suggestion to a given inbox
+ *
+ * @param integer $uid User ID
+ * @param string $inbox Target inbox
+ * @param integer $suggestion_id Suggestion ID
+ *
+ * @return boolean was the transmission successful?
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ public static function sendContactSuggestion($uid, $inbox, $suggestion_id)
+ {
+ $owner = User::getOwnerDataById($uid);
+
+ $suggestion = DBA::selectFirst('fsuggest', ['url', 'note', 'created'], ['id' => $suggestion_id]);
+
+ $data = ['@context' => ActivityPub::CONTEXT,
+ 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
+ 'type' => 'Announce',
+ 'actor' => $owner['url'],
+ 'object' => $suggestion['url'],
+ 'content' => $suggestion['note'],
+ 'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
+ 'to' => [ActivityPub::PUBLIC_COLLECTION],
+ 'cc' => []];
+
+ $signed = LDSignature::sign($data, $owner);
+
+ Logger::log('Deliver profile deletion for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', Logger::DEBUG);
+ return HTTPSignature::transmit($signed, $inbox, $uid);
+ }
+
+ /**
+ * Transmits a profile relocation to a given inbox
+ *
+ * @param integer $uid User ID
+ * @param string $inbox Target inbox
+ *
+ * @return boolean was the transmission successful?
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ public static function sendProfileRelocation($uid, $inbox)
+ {
+ $owner = User::getOwnerDataById($uid);
+
+ $data = ['@context' => ActivityPub::CONTEXT,
+ 'id' => System::baseUrl() . '/activity/' . System::createGUID(),
+ 'type' => 'dfrn:relocate',
+ 'actor' => $owner['url'],
+ 'object' => $owner['url'],
+ 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
+ 'instrument' => ['type' => 'Service', 'name' => BaseObject::getApp()->getUserAgent()],
+ 'to' => [ActivityPub::PUBLIC_COLLECTION],
+ 'cc' => []];
+
+ $signed = LDSignature::sign($data, $owner);
+
+ Logger::log('Deliver profile relocation for user ' . $uid . ' to ' . $inbox . ' via ActivityPub', Logger::DEBUG);
+ return HTTPSignature::transmit($signed, $inbox, $uid);
+ }
+