+ Logger::info('Direct Message', $item);
+
+ $msg = [];
+ $msg['uid'] = $item['uid'];
+
+ $msg['contact-id'] = $item['contact-id'];
+
+ $contact = Contact::getById($item['contact-id'], ['name', 'url', 'photo']);
+ $msg['from-name'] = $contact['name'];
+ $msg['from-url'] = $contact['url'];
+ $msg['from-photo'] = $contact['photo'];
+
+ $msg['uri'] = $item['uri'];
+ $msg['created'] = $item['created'];
+
+ $parent = DBA::selectFirst('mail', ['parent-uri', 'title'], ['uri' => $item['thr-parent']]);
+ if (DBA::isResult($parent)) {
+ $msg['parent-uri'] = $parent['parent-uri'];
+ $msg['title'] = $parent['title'];
+ } else {
+ $msg['parent-uri'] = $item['thr-parent'];
+
+ if (!empty($item['title'])) {
+ $msg['title'] = $item['title'];
+ } elseif (!empty($item['content-warning'])) {
+ $msg['title'] = $item['content-warning'];
+ } else {
+ // Trying to generate a title out of the body
+ $title = $item['body'];
+
+ while (preg_match('#^(@\[url=([^\]]+)].*?\[\/url]\s)(.*)#is', $title, $matches)) {
+ $title = $matches[3];
+ }
+
+ $title = trim(HTML::toPlaintext(BBCode::convert($title, false, 2, true), 0));
+
+ if (strlen($title) > 20) {
+ $title = substr($title, 0, 20) . '...';
+ }
+
+ $msg['title'] = $title;
+ }
+ }
+ $msg['body'] = $item['body'];
+
+ return Mail::insert($msg);
+ }
+
+ /**
+ * Fetches missing posts
+ *
+ * @param string $url message URL
+ * @param array $child activity array with the child of this message
+ * @return boolean success
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ */
+ public static function fetchMissingActivity($url, $child = [])
+ {
+ if (!empty($child['receiver'])) {
+ $uid = ActivityPub\Receiver::getFirstUserFromReceivers($child['receiver']);
+ } else {
+ $uid = 0;
+ }