+ /**
+ * Returns threads from a given contact id
+ *
+ * @param int $cid Contact ID
+ * @param int $update Update mode
+ * @param int $parent Item parent ID for the update mode
+ * @return string posts in HTML
+ * @throws \Exception
+ */
+ public static function getThreadsFromId(int $cid, int $uid, int $update = 0, int $parent = 0, string $last_received = ''): string
+ {
+ $contact = DBA::selectFirst('contact', ['contact-type', 'network'], ['id' => $cid]);
+ if (!DBA::isResult($contact)) {
+ return '';
+ }
+
+ if (empty($contact["network"]) || in_array($contact["network"], Protocol::FEDERATED)) {
+ $condition = ["(`uid` = 0 OR (`uid` = ? AND NOT `global`))", $uid];
+ } else {
+ $condition = ["`uid` = ?", $uid];
+ }
+
+ if (!empty($parent)) {
+ $condition = DBA::mergeConditions($condition, ['parent' => $parent]);
+ } elseif (!empty($last_received)) {
+ $condition = DBA::mergeConditions($condition, ["`received` < ?", $last_received]);
+ }
+
+ $contact_field = ((($contact["contact-type"] == self::TYPE_COMMUNITY) || ($contact['network'] == Protocol::MAIL)) ? 'owner-id' : 'author-id');
+
+ if (DI::mode()->isMobile()) {
+ $itemsPerPage = DI::pConfig()->get($uid, 'system', 'itemspage_mobile_network', DI::config()->get('system', 'itemspage_network_mobile'));
+ } else {
+ $itemsPerPage = DI::pConfig()->get($uid, 'system', 'itemspage_network', DI::config()->get('system', 'itemspage_network'));
+ }
+
+ $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage);
+
+ if (DI::pConfig()->get($uid, 'system', 'infinite_scroll')) {
+ $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
+ $o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
+ } else {
+ $o = '';