Merge pull request #13390 from annando/channel
Channels are a new way to see different content
This commit is contained in:
commit
a275f0a719
21
database.sql
21
database.sql
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 2023.09-dev (Giant Rhubarb)
|
||||
-- DB_UPDATE_VERSION 1530
|
||||
-- DB_UPDATE_VERSION 1531
|
||||
-- ------------------------------------------
|
||||
|
||||
|
||||
|
@ -1300,6 +1300,25 @@ CREATE TABLE IF NOT EXISTS `post-delivery-data` (
|
|||
FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
|
||||
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items';
|
||||
|
||||
--
|
||||
-- TABLE post-engagement
|
||||
--
|
||||
CREATE TABLE IF NOT EXISTS `post-engagement` (
|
||||
`uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the item uri',
|
||||
`owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner',
|
||||
`contact-type` tinyint NOT NULL DEFAULT 0 COMMENT 'Person, organisation, news, community, relay',
|
||||
`media-type` tinyint NOT NULL DEFAULT 0 COMMENT 'Type of media in a bit array (1 = image, 2 = video, 4 = audio',
|
||||
`language` varbinary(128) COMMENT 'Language information about this post',
|
||||
`created` datetime COMMENT '',
|
||||
`comments` mediumint unsigned COMMENT 'Number of comments',
|
||||
`activities` mediumint unsigned COMMENT 'Number of activities (like, dislike, ...)',
|
||||
PRIMARY KEY(`uri-id`),
|
||||
INDEX `owner-id` (`owner-id`),
|
||||
INDEX `created` (`created`),
|
||||
FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
|
||||
FOREIGN KEY (`owner-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
|
||||
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Engagement data per post';
|
||||
|
||||
--
|
||||
-- TABLE post-history
|
||||
--
|
||||
|
|
|
@ -16,6 +16,7 @@ General
|
|||
-------
|
||||
* p - Profile
|
||||
* n - Network
|
||||
* l - Channel
|
||||
* c - Community
|
||||
* s - Search
|
||||
* a - Admin
|
||||
|
@ -28,6 +29,17 @@ General
|
|||
* l - Local community
|
||||
* g - Global community
|
||||
|
||||
../channel
|
||||
--------
|
||||
* y - for you
|
||||
* f - followers
|
||||
* h - what's hot
|
||||
* i - Images
|
||||
* v - Videos
|
||||
* d - Audio
|
||||
* g - Posts in your language
|
||||
* o - Hot posts in your language
|
||||
|
||||
../profile
|
||||
--------
|
||||
* m - Status Messages and Posts
|
||||
|
|
|
@ -61,6 +61,7 @@ Database Tables
|
|||
| [post-content](help/database/db_post-content) | Content for all posts |
|
||||
| [post-delivery](help/database/db_post-delivery) | Delivery data for posts for the batch processing |
|
||||
| [post-delivery-data](help/database/db_post-delivery-data) | Delivery data for items |
|
||||
| [post-engagement](help/database/db_post-engagement) | Engagement data per post |
|
||||
| [post-history](help/database/db_post-history) | Post history |
|
||||
| [post-link](help/database/db_post-link) | Post related external links |
|
||||
| [post-media](help/database/db_post-media) | Attached media |
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
Table post-engagement
|
||||
===========
|
||||
|
||||
Engagement data per post
|
||||
|
||||
Fields
|
||||
------
|
||||
|
||||
| Field | Description | Type | Null | Key | Default | Extra |
|
||||
| ------------ | ------------------------------------------------------------- | ------------------ | ---- | --- | ------- | ----- |
|
||||
| uri-id | Id of the item-uri table entry that contains the item uri | int unsigned | NO | PRI | NULL | |
|
||||
| owner-id | Item owner | int unsigned | NO | | 0 | |
|
||||
| contact-type | Person, organisation, news, community, relay | tinyint | NO | | 0 | |
|
||||
| media-type | Type of media in a bit array (1 = image, 2 = video, 4 = audio | tinyint | NO | | 0 | |
|
||||
| language | Language information about this post | varbinary(128) | YES | | NULL | |
|
||||
| created | | datetime | YES | | NULL | |
|
||||
| comments | Number of comments | mediumint unsigned | YES | | NULL | |
|
||||
| activities | Number of activities (like, dislike, ...) | mediumint unsigned | YES | | NULL | |
|
||||
|
||||
Indexes
|
||||
------------
|
||||
|
||||
| Name | Fields |
|
||||
| -------- | -------- |
|
||||
| PRIMARY | uri-id |
|
||||
| owner-id | owner-id |
|
||||
| created | created |
|
||||
|
||||
Foreign Keys
|
||||
------------
|
||||
|
||||
| Field | Target Table | Target Field |
|
||||
|-------|--------------|--------------|
|
||||
| uri-id | [item-uri](help/database/db_item-uri) | id |
|
||||
| owner-id | [contact](help/database/db_contact) | id |
|
||||
|
||||
Return to [database documentation](help/database)
|
|
@ -8,8 +8,8 @@ Fields
|
|||
|
||||
| Field | Description | Type | Null | Key | Default | Extra |
|
||||
| ------- | ---------------------------------------- | ------------------ | ---- | --- | ------- | ----- |
|
||||
| uid | Owner User id | mediumint unsigned | NO | | 0 | |
|
||||
| gsid | Gserver id | int unsigned | NO | | 0 | |
|
||||
| uid | Owner User id | mediumint unsigned | NO | PRI | 0 | |
|
||||
| gsid | Gserver id | int unsigned | NO | PRI | 0 | |
|
||||
| ignored | server accounts are ignored for the user | boolean | NO | | 0 | |
|
||||
|
||||
Indexes
|
||||
|
|
|
@ -57,6 +57,7 @@ use Psr\Log\LoggerInterface;
|
|||
|
||||
class Conversation
|
||||
{
|
||||
const MODE_CHANNEL = 'channel';
|
||||
const MODE_COMMUNITY = 'community';
|
||||
const MODE_CONTACTS = 'contacts';
|
||||
const MODE_CONTACT_POSTS = 'contact-posts';
|
||||
|
@ -530,6 +531,17 @@ class Conversation
|
|||
. "<script> var profile_uid = " . ($this->session->getLocalUserId() ?: 0) . ";"
|
||||
. "</script>";
|
||||
}
|
||||
} elseif ($mode === self::MODE_CHANNEL) {
|
||||
$items = $this->addChildren($items, true, $order, $uid, $mode, $ignoredGsids);
|
||||
|
||||
if (!$update) {
|
||||
$live_update_div = '<div id="live-channel"></div>' . "\r\n"
|
||||
. "<script> var profile_uid = -1; var netargs = '" . substr($this->args->getCommand(), 10)
|
||||
. '?f='
|
||||
. (!empty($_GET['no_sharer']) ? '&no_sharer=' . rawurlencode($_GET['no_sharer']) : '')
|
||||
. (!empty($_GET['accounttype']) ? '&accounttype=' . rawurlencode($_GET['accounttype']) : '')
|
||||
. "'; </script>\r\n";
|
||||
}
|
||||
} elseif ($mode === self::MODE_COMMUNITY) {
|
||||
$items = $this->addChildren($items, true, $order, $uid, $mode, $ignoredGsids);
|
||||
|
||||
|
@ -621,7 +633,7 @@ class Conversation
|
|||
unset($conv_responses['dislike']);
|
||||
}
|
||||
|
||||
if (in_array($mode, [self::MODE_COMMUNITY, self::MODE_CONTACTS, self::MODE_PROFILE])) {
|
||||
if (in_array($mode, [self::MODE_CHANNEL, self::MODE_COMMUNITY, self::MODE_CONTACTS, self::MODE_PROFILE])) {
|
||||
$writable = true;
|
||||
} else {
|
||||
$writable = $items[0]['writable'] || ($items[0]['uid'] == 0) && in_array($items[0]['network'], Protocol::FEDERATED);
|
||||
|
@ -1009,7 +1021,7 @@ class Conversation
|
|||
$items[$key]['user-collapsed-owner'] = !$always_display && in_array($row['owner-id'], $collapses);
|
||||
|
||||
if (
|
||||
in_array($mode, [self::MODE_COMMUNITY, self::MODE_NETWORK]) &&
|
||||
in_array($mode, [self::MODE_CHANNEL, self::MODE_COMMUNITY, self::MODE_NETWORK]) &&
|
||||
(in_array($row['author-id'], $blocks) || in_array($row['owner-id'], $blocks) || in_array($row['author-id'], $ignores) || in_array($row['owner-id'], $ignores))
|
||||
) {
|
||||
unset($items[$key]);
|
||||
|
|
|
@ -42,6 +42,7 @@ class Nav
|
|||
private static $selected = [
|
||||
'global' => null,
|
||||
'community' => null,
|
||||
'channel' => null,
|
||||
'network' => null,
|
||||
'home' => null,
|
||||
'profiles' => null,
|
||||
|
@ -199,6 +200,7 @@ class Nav
|
|||
'moderation' => null,
|
||||
'apps' => null,
|
||||
'community' => null,
|
||||
'channel' => null,
|
||||
'home' => null,
|
||||
'calendar' => null,
|
||||
'login' => null,
|
||||
|
@ -287,6 +289,8 @@ class Nav
|
|||
$nav['community'] = ['community', $this->l10n->t('Community'), '', $this->l10n->t('Conversations on this and other servers')];
|
||||
}
|
||||
|
||||
$nav['channel'] = ['channel', $this->l10n->t('Channels'), '', $this->l10n->t('Current posts, filtered by several rules')];
|
||||
|
||||
if ($this->session->getLocalUserId()) {
|
||||
$nav['calendar'] = ['calendar', $this->l10n->t('Calendar'), '', $this->l10n->t('Calendar')];
|
||||
}
|
||||
|
|
|
@ -533,6 +533,17 @@ class Contact
|
|||
return self::isSharing($cid, $uid, $strict);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the provided public contact id has got followers on this system
|
||||
*
|
||||
* @param integer $cid
|
||||
* @return boolean
|
||||
*/
|
||||
public static function hasFollowers(int $cid): bool
|
||||
{
|
||||
return DBA::exists('account-user-view', ["`pid` = ? AND `uid` != ? AND `rel` IN (?, ?)", $cid, 0, self::SHARING, self::FRIEND]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the basepath for a given contact link
|
||||
*
|
||||
|
|
|
@ -781,7 +781,7 @@ class Relation
|
|||
*/
|
||||
public static function calculateInteractionScore(int $uid)
|
||||
{
|
||||
$days = DI::config()->get('system', 'interaction_score_days');
|
||||
$days = DI::config()->get('channel', 'interaction_score_days');
|
||||
$contact_id = Contact::getPublicIdByUserId($uid);
|
||||
|
||||
Logger::debug('Calculation - start', ['uid' => $uid, 'cid' => $contact_id, 'days' => $days]);
|
||||
|
|
|
@ -1405,6 +1405,8 @@ class Item
|
|||
self::updateDisplayCache($posted_item['uri-id']);
|
||||
}
|
||||
|
||||
Post\Engagement::storeFromItem($posted_item);
|
||||
|
||||
return $post_user_id;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Model\Post;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Model\Verb;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
||||
// Channel
|
||||
|
||||
class Engagement
|
||||
{
|
||||
/**
|
||||
* Store engagement data from an item array
|
||||
*
|
||||
* @param array $item
|
||||
* @return void
|
||||
*/
|
||||
public static function storeFromItem(array $item)
|
||||
{
|
||||
if (!in_array($item['network'], Protocol::FEDERATED)) {
|
||||
Logger::debug('No federated network', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'network' => $item['network']]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (($item['uid'] != 0) && ($item['gravity'] == Item::GRAVITY_COMMENT)) {
|
||||
Logger::debug('Non public comments are not stored', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (in_array($item['verb'], [Activity::FOLLOW, Activity::VIEW, Activity::READ])) {
|
||||
Logger::debug('Technical activities are not stored', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'verb' => $item['verb']]);
|
||||
return;
|
||||
}
|
||||
|
||||
$parent = Post::selectFirst(['created', 'owner-id', 'uid', 'private', 'contact-contact-type', 'language'], ['uri-id' => $item['parent-uri-id']]);
|
||||
if ($parent['private'] != Item::PUBLIC) {
|
||||
Logger::debug('Non public posts are not stored', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'uid' => $parent['uid'], 'private' => $parent['private']]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($parent['created'] < DateTimeFormat::utc('now - ' . DI::config()->get('channel', 'engagement_hours') . ' hour')) {
|
||||
Logger::debug('Post is too old', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'created' => $parent['created']]);
|
||||
return;
|
||||
}
|
||||
|
||||
$store = ($item['gravity'] != Item::GRAVITY_PARENT);
|
||||
|
||||
if (!$store) {
|
||||
$store = Contact::hasFollowers($parent['owner-id']);
|
||||
}
|
||||
|
||||
$mediatype = self::getMediaType($item['parent-uri-id']);
|
||||
|
||||
if (!$store) {
|
||||
$mediatype = !empty($mediatype);
|
||||
}
|
||||
|
||||
$engagement = [
|
||||
'uri-id' => $item['parent-uri-id'],
|
||||
'owner-id' => $parent['owner-id'],
|
||||
'contact-type' => $parent['contact-contact-type'],
|
||||
'media-type' => $mediatype,
|
||||
'language' => $parent['language'],
|
||||
'created' => $parent['created'],
|
||||
'comments' => DBA::count('post', ['parent-uri-id' => $item['parent-uri-id'], 'gravity' => Item::GRAVITY_COMMENT]),
|
||||
'activities' => DBA::count('post', [
|
||||
"`parent-uri-id` = ? AND `gravity` = ? AND NOT `vid` IN (?, ?, ?)",
|
||||
$item['parent-uri-id'], Item::GRAVITY_ACTIVITY,
|
||||
Verb::getID(Activity::FOLLOW), Verb::getID(Activity::VIEW), Verb::getID(Activity::READ)
|
||||
])
|
||||
];
|
||||
if (!$store && ($engagement['comments'] == 0) && ($engagement['activities'] == 0)) {
|
||||
Logger::debug('No media, follower, comments or activities. Engagement not stored', ['fields' => $engagement]);
|
||||
return;
|
||||
}
|
||||
$ret = DBA::insert('post-engagement', $engagement, Database::INSERT_UPDATE);
|
||||
Logger::debug('Engagement stored', ['fields' => $engagement, 'ret' => $ret]);
|
||||
}
|
||||
|
||||
private static function getMediaType(int $uri_id): int
|
||||
{
|
||||
$media = Post\Media::getByURIId($uri_id);
|
||||
$type = 0;
|
||||
foreach ($media as $entry) {
|
||||
if ($entry['type'] == Post\Media::IMAGE) {
|
||||
$type = $type | 1;
|
||||
} elseif ($entry['type'] == Post\Media::VIDEO) {
|
||||
$type = $type | 2;
|
||||
} elseif ($entry['type'] == Post\Media::AUDIO) {
|
||||
$type = $type | 4;
|
||||
}
|
||||
}
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expire old engagement data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function expire()
|
||||
{
|
||||
DBA::delete('post-engagement', ["`created` < ?", DateTimeFormat::utc('now - ' . DI::config()->get('channel', 'engagement_hours') . ' hour')]);
|
||||
Logger::notice('Cleared expired engagements', ['rows' => DBA::affectedRows()]);
|
||||
}
|
||||
}
|
|
@ -183,7 +183,7 @@ class User
|
|||
$system['dob'] = '0000-00-00';
|
||||
|
||||
// Ensure that the user contains data
|
||||
$user = DBA::selectFirst('user', ['prvkey', 'guid'], ['uid' => 0]);
|
||||
$user = DBA::selectFirst('user', ['prvkey', 'guid', 'language'], ['uid' => 0]);
|
||||
if (empty($user['prvkey']) || empty($user['guid'])) {
|
||||
$fields = [
|
||||
'username' => $system['name'],
|
||||
|
@ -204,6 +204,7 @@ class User
|
|||
$system['guid'] = $fields['guid'];
|
||||
} else {
|
||||
$system['guid'] = $user['guid'];
|
||||
$system['language'] = $user['language'];
|
||||
}
|
||||
|
||||
return $system;
|
||||
|
@ -532,6 +533,28 @@ class User
|
|||
return $default_circle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the language code from the given user. If the code is invalid, return the system language
|
||||
*
|
||||
* @param integer $uid User-Id
|
||||
* @param boolean $short If true, return the short form g.g. "en", otherwise the long form e.g. "en-gb"
|
||||
* @return string
|
||||
*/
|
||||
public static function getLanguageCode(int $uid, bool $short): string
|
||||
{
|
||||
$owner = self::getOwnerDataById($uid);
|
||||
$languages = DI::l10n()->getAvailableLanguages();
|
||||
if (in_array($owner['language'], array_keys($languages))) {
|
||||
$language = $owner['language'];
|
||||
} else {
|
||||
$language = DI::config()->get('system', 'language');
|
||||
}
|
||||
if ($short) {
|
||||
return substr($language, 0, 2);
|
||||
}
|
||||
return $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate a user with a clear text password
|
||||
*
|
||||
|
|
|
@ -0,0 +1,474 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Conversation;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\App\Mode;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Content\BoundariesPager;
|
||||
use Friendica\Content\Conversation;
|
||||
use Friendica\Content\Feature;
|
||||
use Friendica\Content\Nav;
|
||||
use Friendica\Content\Text\HTML;
|
||||
use Friendica\Content\Widget;
|
||||
use Friendica\Content\Widget\TrendingTags;
|
||||
use Friendica\Core\Cache\Capability\ICanCache;
|
||||
use Friendica\Core\Cache\Enum\Duration;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Security\Login;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Core\Session\Model\UserSession;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Navigation\SystemMessages;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Channel extends BaseModule
|
||||
{
|
||||
const WHATSHOT = 'whatshot';
|
||||
const FORYOU = 'foryou';
|
||||
const FOLLOWERS = 'followers';
|
||||
const IMAGE = 'image';
|
||||
const VIDEO = 'video';
|
||||
const AUDIO = 'audio';
|
||||
const LANGUAGE = 'language';
|
||||
|
||||
protected static $content;
|
||||
protected static $accountTypeString;
|
||||
protected static $accountType;
|
||||
protected static $itemsPerPage;
|
||||
protected static $min_id;
|
||||
protected static $max_id;
|
||||
protected static $item_id;
|
||||
|
||||
/** @var UserSession */
|
||||
protected $session;
|
||||
/** @var ICanCache */
|
||||
protected $cache;
|
||||
/** @var IManageConfigValues The config */
|
||||
protected $config;
|
||||
/** @var SystemMessages */
|
||||
protected $systemMessages;
|
||||
/** @var App\Page */
|
||||
protected $page;
|
||||
/** @var Conversation */
|
||||
protected $conversation;
|
||||
/** @var App\Mode $mode */
|
||||
protected $mode;
|
||||
/** @var IManagePersonalConfigValues */
|
||||
protected $pConfig;
|
||||
/** @var Database */
|
||||
protected $database;
|
||||
|
||||
|
||||
public function __construct(SystemMessages $systemMessages, Database $database, IManagePersonalConfigValues $pConfig, Mode $mode, Conversation $conversation, App\Page $page, IManageConfigValues $config, ICanCache $cache, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->systemMessages = $systemMessages;
|
||||
$this->database = $database;
|
||||
$this->pConfig = $pConfig;
|
||||
$this->mode = $mode;
|
||||
$this->conversation = $conversation;
|
||||
$this->page = $page;
|
||||
$this->config = $config;
|
||||
$this->cache = $cache;
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
if (!$this->session->getLocalUserId()) {
|
||||
return Login::form();
|
||||
}
|
||||
|
||||
$this->parseRequest($request);
|
||||
|
||||
$t = Renderer::getMarkupTemplate("community.tpl");
|
||||
$o = Renderer::replaceMacros($t, [
|
||||
'$content' => '',
|
||||
'$header' => '',
|
||||
]);
|
||||
|
||||
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
|
||||
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
|
||||
$o .= Renderer::replaceMacros($tpl, ['$reload_uri' => $this->args->getQueryString()]);
|
||||
}
|
||||
|
||||
if (empty($request['mode']) || ($request['mode'] != 'raw')) {
|
||||
$tabs = [];
|
||||
|
||||
$tabs[] = [
|
||||
'label' => $this->l10n->t('For you'),
|
||||
'url' => 'channel/' . self::FORYOU,
|
||||
'sel' => self::$content == self::FORYOU ? 'active' : '',
|
||||
'title' => $this->l10n->t('Posts from contacts you interact with and who interact with you'),
|
||||
'id' => 'channel-foryou-tab',
|
||||
'accesskey' => 'y'
|
||||
];
|
||||
|
||||
$tabs[] = [
|
||||
'label' => $this->l10n->t('What\'s Hot'),
|
||||
'url' => 'channel/' . self::WHATSHOT,
|
||||
'sel' => self::$content == self::WHATSHOT ? 'active' : '',
|
||||
'title' => $this->l10n->t('Posts with a lot of interactions'),
|
||||
'id' => 'channel-whatshot-tab',
|
||||
'accesskey' => 'h'
|
||||
];
|
||||
|
||||
$language = User::getLanguageCode($this->session->getLocalUserId(), false);
|
||||
$languages = $this->l10n->getAvailableLanguages();
|
||||
|
||||
$tabs[] = [
|
||||
'label' => $languages[$language],
|
||||
'url' => 'channel/' . self::LANGUAGE,
|
||||
'sel' => self::$content == self::LANGUAGE ? 'active' : '',
|
||||
'title' => $this->l10n->t('Posts in %s', $languages[$language]),
|
||||
'id' => 'channel-language-tab',
|
||||
'accesskey' => 'g'
|
||||
];
|
||||
|
||||
$tabs[] = [
|
||||
'label' => $this->l10n->t('Followers'),
|
||||
'url' => 'channel/' . self::FOLLOWERS,
|
||||
'sel' => self::$content == self::FOLLOWERS ? 'active' : '',
|
||||
'title' => $this->l10n->t('Posts from your followers that you don\'t follow'),
|
||||
'id' => 'channel-followers-tab',
|
||||
'accesskey' => 'f'
|
||||
];
|
||||
|
||||
$tabs[] = [
|
||||
'label' => $this->l10n->t('Images'),
|
||||
'url' => 'channel/' . self::IMAGE,
|
||||
'sel' => self::$content == self::IMAGE ? 'active' : '',
|
||||
'title' => $this->l10n->t('Posts with images'),
|
||||
'id' => 'channel-image-tab',
|
||||
'accesskey' => 'i'
|
||||
];
|
||||
|
||||
$tabs[] = [
|
||||
'label' => $this->l10n->t('Audio'),
|
||||
'url' => 'channel/' . self::AUDIO,
|
||||
'sel' => self::$content == self::AUDIO ? 'active' : '',
|
||||
'title' => $this->l10n->t('Posts with audio'),
|
||||
'id' => 'channel-audio-tab',
|
||||
'accesskey' => 'd'
|
||||
];
|
||||
|
||||
$tabs[] = [
|
||||
'label' => $this->l10n->t('Videos'),
|
||||
'url' => 'channel/' . self::VIDEO,
|
||||
'sel' => self::$content == self::VIDEO ? 'active' : '',
|
||||
'title' => $this->l10n->t('Posts with videos'),
|
||||
'id' => 'channel-video-tab',
|
||||
'accesskey' => 'v'
|
||||
];
|
||||
|
||||
$tab_tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
|
||||
$o .= Renderer::replaceMacros($tab_tpl, ['$tabs' => $tabs]);
|
||||
|
||||
Nav::setSelected('channel');
|
||||
|
||||
$this->page['aside'] .= Widget::accountTypes('channel/' . self::$content, self::$accountTypeString);
|
||||
|
||||
if (!in_array(self::$content, [self::FOLLOWERS, self::FORYOU]) && $this->config->get('system', 'community_no_sharer')) {
|
||||
$path = self::$content;
|
||||
if (!empty($this->parameters['accounttype'])) {
|
||||
$path .= '/' . $this->parameters['accounttype'];
|
||||
}
|
||||
$query_parameters = [];
|
||||
|
||||
if (!empty($request['min_id'])) {
|
||||
$query_parameters['min_id'] = $request['min_id'];
|
||||
}
|
||||
if (!empty($request['max_id'])) {
|
||||
$query_parameters['max_id'] = $request['max_id'];
|
||||
}
|
||||
if (!empty($request['last_created'])) {
|
||||
$query_parameters['max_id'] = $request['last_created'];
|
||||
}
|
||||
|
||||
$path_all = $path . (!empty($query_parameters) ? '?' . http_build_query($query_parameters) : '');
|
||||
$path_no_sharer = $path . '?' . http_build_query(array_merge($query_parameters, ['no_sharer' => true]));
|
||||
$this->page['aside'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('widget/community_sharer.tpl'), [
|
||||
'$title' => $this->l10n->t('Own Contacts'),
|
||||
'$path_all' => $path_all,
|
||||
'$path_no_sharer' => $path_no_sharer,
|
||||
'$no_sharer' => !empty($request['no_sharer']),
|
||||
'$all' => $this->l10n->t('Include'),
|
||||
'$no_sharer_label' => $this->l10n->t('Hide'),
|
||||
'$base' => 'channel',
|
||||
]);
|
||||
}
|
||||
|
||||
if (Feature::isEnabled($this->session->getLocalUserId(), 'trending_tags')) {
|
||||
$this->page['aside'] .= TrendingTags::getHTML(self::$content);
|
||||
}
|
||||
|
||||
// We need the editor here to be able to reshare an item.
|
||||
$o .= $this->conversation->statusEditor([], 0, true);
|
||||
}
|
||||
|
||||
$items = $this->getItems($request);
|
||||
|
||||
if (!$this->database->isResult($items)) {
|
||||
$this->systemMessages->addNotice($this->l10n->t('No results.'));
|
||||
return $o;
|
||||
}
|
||||
|
||||
$o .= $this->conversation->render($items, Conversation::MODE_CHANNEL, false, false, 'created', $this->session->getLocalUserId());
|
||||
|
||||
$pager = new BoundariesPager(
|
||||
$this->l10n,
|
||||
$this->args->getQueryString(),
|
||||
$items[0]['created'],
|
||||
$items[count($items) - 1]['created'],
|
||||
self::$itemsPerPage
|
||||
);
|
||||
|
||||
if ($this->pConfig->get($this->session->getLocalUserId(), 'system', 'infinite_scroll')) {
|
||||
$o .= HTML::scrollLoader();
|
||||
} else {
|
||||
$o .= $pager->renderMinimal(count($items));
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes module parameters from the request and local configuration
|
||||
*
|
||||
* @throws HTTPException\BadRequestException
|
||||
* @throws HTTPException\ForbiddenException
|
||||
*/
|
||||
protected function parseRequest(array $request)
|
||||
{
|
||||
self::$accountTypeString = $request['accounttype'] ?? $this->parameters['accounttype'] ?? '';
|
||||
self::$accountType = User::getAccountTypeByString(self::$accountTypeString);
|
||||
|
||||
self::$content = $this->parameters['content'] ?? '';
|
||||
if (!self::$content) {
|
||||
self::$content = self::FORYOU;
|
||||
}
|
||||
|
||||
if (!in_array(self::$content, [self::WHATSHOT, self::FORYOU, self::FOLLOWERS, self::IMAGE, self::VIDEO, self::AUDIO, self::LANGUAGE])) {
|
||||
throw new HTTPException\BadRequestException($this->l10n->t('Channel not available.'));
|
||||
}
|
||||
|
||||
if ($this->mode->isMobile()) {
|
||||
self::$itemsPerPage = $this->pConfig->get(
|
||||
$this->session->getLocalUserId(),
|
||||
'system',
|
||||
'itemspage_mobile_network',
|
||||
$this->config->get('system', 'itemspage_network_mobile')
|
||||
);
|
||||
} else {
|
||||
self::$itemsPerPage = $this->pConfig->get(
|
||||
$this->session->getLocalUserId(),
|
||||
'system',
|
||||
'itemspage_network',
|
||||
$this->config->get('system', 'itemspage_network')
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($request['item'])) {
|
||||
$item = Post::selectFirst(['parent-uri-id'], ['id' => $request['item']]);
|
||||
self::$item_id = $item['parent-uri-id'] ?? 0;
|
||||
} else {
|
||||
self::$item_id = 0;
|
||||
}
|
||||
|
||||
self::$min_id = $request['min_id'] ?? null;
|
||||
self::$max_id = $request['last_created'] ?? $request['max_id'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the displayed items.
|
||||
*
|
||||
* Community pages have a restriction on how many successive posts by the same author can show on any given page,
|
||||
* so we may have to retrieve more content beyond the first query
|
||||
*
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function getItems(array $request)
|
||||
{
|
||||
if (self::$content == self::WHATSHOT) {
|
||||
if (!is_null(self::$accountType)) {
|
||||
$condition = ["(`comments` >= ? OR `activities` >= ?) AND `contact-type` = ?", $this->getMedianComments(4), $this->getMedianActivities(4), self::$accountType];
|
||||
} else {
|
||||
$condition = ["(`comments` >= ? OR `activities` >= ?) AND `contact-type` != ?", $this->getMedianComments(4), $this->getMedianActivities(4), Contact::TYPE_COMMUNITY];
|
||||
}
|
||||
} elseif (self::$content == self::FORYOU) {
|
||||
$cid = Contact::getPublicIdByUserId($this->session->getLocalUserId());
|
||||
|
||||
$condition = ["(`owner-id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `thread-score` > ?) OR
|
||||
((`comments` >= ? OR `activities` >= ?) AND `owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?))) OR
|
||||
( `owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` IN (?, ?) AND `notify_new_posts`)))",
|
||||
$cid, $this->getMedianThreadScore($cid, 4), $this->getMedianComments(4), $this->getMedianActivities(4), $this->session->getLocalUserId(), Contact::FRIEND, Contact::SHARING,
|
||||
$this->session->getLocalUserId(), Contact::FRIEND, Contact::SHARING];
|
||||
} elseif (self::$content == self::FOLLOWERS) {
|
||||
$condition = ["`owner-id` IN (SELECT `pid` FROM `account-user-view` WHERE `uid` = ? AND `rel` = ?)", $this->session->getLocalUserId(), Contact::FOLLOWER];
|
||||
} elseif (self::$content == self::IMAGE) {
|
||||
$condition = ["`media-type` & ?", 1];
|
||||
} elseif (self::$content == self::VIDEO) {
|
||||
$condition = ["`media-type` & ?", 2];
|
||||
} elseif (self::$content == self::AUDIO) {
|
||||
$condition = ["`media-type` & ?", 4];
|
||||
} elseif (self::$content == self::LANGUAGE) {
|
||||
$condition = ["JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?", User::getLanguageCode($this->session->getLocalUserId(), true)];
|
||||
}
|
||||
|
||||
if (self::$content != self::LANGUAGE) {
|
||||
$condition = $this->addLanguageCondition($condition);
|
||||
}
|
||||
|
||||
$condition[0] .= " AND NOT EXISTS(SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `cid` = `post-engagement`.`owner-id` AND (`ignored` OR `blocked` OR `collapsed`))";
|
||||
$condition[] = $this->session->getLocalUserId();
|
||||
|
||||
if ((self::$content != self::WHATSHOT) && !is_null(self::$accountType)) {
|
||||
$condition[0] .= " AND `contact-type` = ?";
|
||||
$condition[] = self::$accountType;
|
||||
}
|
||||
|
||||
$params = ['order' => ['created' => true], 'limit' => self::$itemsPerPage];
|
||||
|
||||
if (!empty(self::$item_id)) {
|
||||
$condition[0] .= " AND `uri-id` = ?";
|
||||
$condition[] = self::$item_id;
|
||||
} else {
|
||||
if (!empty($request['no_sharer'])) {
|
||||
$condition[0] .= " AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `post-user`.`uid` = ? AND `post-user`.`uri-id` = `post-engagement`.`uri-id`)";
|
||||
$condition[] = $this->session->getLocalUserId();
|
||||
}
|
||||
|
||||
if (isset(self::$max_id)) {
|
||||
$condition[0] .= " AND `created` < ?";
|
||||
$condition[] = self::$max_id;
|
||||
}
|
||||
|
||||
if (isset(self::$min_id)) {
|
||||
$condition[0] .= " AND `created` > ?";
|
||||
$condition[] = self::$min_id;
|
||||
|
||||
// Previous page case: we want the items closest to min_id but for that we need to reverse the query order
|
||||
if (!isset(self::$max_id)) {
|
||||
$params['order']['created'] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$items = $this->database->selectToArray('post-engagement', ['uri-id', 'created'], $condition, $params);
|
||||
if (empty($items)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Previous page case: once we get the relevant items closest to min_id, we need to restore the expected display order
|
||||
if (empty(self::$item_id) && isset(self::$min_id) && !isset(self::$max_id)) {
|
||||
$items = array_reverse($items);
|
||||
}
|
||||
|
||||
Item::update(['unseen' => false], ['unseen' => true, 'uid' => $this->session->getLocalUserId(), 'uri-id' => array_column($items, 'uri-id')]);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function addLanguageCondition(array $condition): array
|
||||
{
|
||||
$conditions = [];
|
||||
$languages = $this->pConfig->get($this->session->getLocalUserId(), 'channel', 'languages', [User::getLanguageCode($this->session->getLocalUserId(), false)]);
|
||||
foreach ($languages as $language) {
|
||||
$conditions[] = "JSON_EXTRACT(JSON_KEYS(language), '$[0]') = ?";
|
||||
$condition[] = substr($language, 0, 2);
|
||||
}
|
||||
if (!empty($conditions)) {
|
||||
$condition[0] .= " AND (`language` IS NULL OR " . implode(' OR ', $conditions) . ")";
|
||||
}
|
||||
return $condition;
|
||||
}
|
||||
|
||||
private function getMedianComments(int $divider): int
|
||||
{
|
||||
$cache_key = 'Channel:getMedianComments:' . $divider;
|
||||
$comments = $this->cache->get($cache_key);
|
||||
if (!empty($comments)) {
|
||||
return $comments;
|
||||
}
|
||||
|
||||
$limit = $this->database->count('post-engagement', ["`contact-type` != ? AND `comments` > ?", Contact::TYPE_COMMUNITY, 0]) / $divider;
|
||||
$post = $this->database->selectToArray('post-engagement', ['comments'], ["`contact-type` != ?", Contact::TYPE_COMMUNITY], ['order' => ['comments' => true], 'limit' => [$limit, 1]]);
|
||||
$comments = $post[0]['comments'] ?? 0;
|
||||
if (empty($comments)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->cache->set($cache_key, $comments, Duration::HOUR);
|
||||
return $comments;
|
||||
}
|
||||
|
||||
private function getMedianActivities(int $divider): int
|
||||
{
|
||||
$cache_key = 'Channel:getMedianActivities:' . $divider;
|
||||
$activities = $this->cache->get($cache_key);
|
||||
if (!empty($activities)) {
|
||||
return $activities;
|
||||
}
|
||||
|
||||
$limit = $this->database->count('post-engagement', ["`contact-type` != ? AND `activities` > ?", Contact::TYPE_COMMUNITY, 0]) / $divider;
|
||||
$post = $this->database->selectToArray('post-engagement', ['activities'], ["`contact-type` != ?", Contact::TYPE_COMMUNITY], ['order' => ['activities' => true], 'limit' => [$limit, 1]]);
|
||||
$activities = $post[0]['activities'] ?? 0;
|
||||
if (empty($activities)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->cache->set($cache_key, $activities, Duration::HOUR);
|
||||
return $activities;
|
||||
}
|
||||
|
||||
private function getMedianThreadScore(int $cid, int $divider): int
|
||||
{
|
||||
$cache_key = 'Channel:getThreadScore:' . $cid . ':' . $divider;
|
||||
$score = $this->cache->get($cache_key);
|
||||
if (!empty($score)) {
|
||||
return $score;
|
||||
}
|
||||
|
||||
$limit = $this->database->count('contact-relation', ["`cid` = ? AND `thread-score` > ?", $cid, 0]) / $divider;
|
||||
$relation = $this->database->selectToArray('contact-relation', ['thread-score'], ['cid' => $cid], ['order' => ['thread-score' => true], 'limit' => [$limit, 1]]);
|
||||
$score = $relation[0]['thread-score'] ?? 0;
|
||||
if (empty($score)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->cache->set($cache_key, $score, Duration::HOUR);
|
||||
return $score;
|
||||
}
|
||||
}
|
|
@ -137,6 +137,7 @@ class Community extends BaseModule
|
|||
'$no_sharer' => !empty($_REQUEST['no_sharer']),
|
||||
'$all' => DI::l10n()->t('Include'),
|
||||
'$no_sharer_label' => DI::l10n()->t('Hide'),
|
||||
'$base' => 'community',
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -245,8 +246,7 @@ class Community extends BaseModule
|
|||
}
|
||||
|
||||
self::$min_id = $_GET['min_id'] ?? null;
|
||||
self::$max_id = $_GET['max_id'] ?? null;
|
||||
self::$max_id = $_GET['last_commented'] ?? self::$max_id;
|
||||
self::$max_id = $_GET['last_commented'] ?? $_GET['max_id'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -76,6 +76,7 @@ class Display extends BaseSettings
|
|||
$theme = !empty($request['theme']) ? trim($request['theme']) : $user['theme'];
|
||||
$mobile_theme = !empty($request['mobile_theme']) ? trim($request['mobile_theme']) : '';
|
||||
$enable_smile = !empty($request['enable_smile']) ? intval($request['enable_smile']) : 0;
|
||||
$channel_languages = !empty($request['channel_languages']) ? $request['channel_languages'] : [];
|
||||
$first_day_of_week = !empty($request['first_day_of_week']) ? intval($request['first_day_of_week']) : 0;
|
||||
$calendar_default_view = !empty($request['calendar_default_view']) ? trim($request['calendar_default_view']) : 'month';
|
||||
$infinite_scroll = !empty($request['infinite_scroll']) ? intval($request['infinite_scroll']) : 0;
|
||||
|
@ -120,6 +121,8 @@ class Display extends BaseSettings
|
|||
$this->pConfig->set($uid, 'system', 'stay_local' , $stay_local);
|
||||
$this->pConfig->set($uid, 'system', 'preview_mode' , $preview_mode);
|
||||
|
||||
$this->pConfig->set($uid, 'channel', 'languages' , $channel_languages);
|
||||
|
||||
$this->pConfig->set($uid, 'calendar', 'first_day_of_week' , $first_day_of_week);
|
||||
$this->pConfig->set($uid, 'calendar', 'default_view' , $calendar_default_view);
|
||||
|
||||
|
@ -215,6 +218,8 @@ class Display extends BaseSettings
|
|||
BBCode::PREVIEW_LARGE => $this->t('Large Image'),
|
||||
];
|
||||
|
||||
$channel_languages = $this->pConfig->get($uid, 'channel', 'languages', [User::getLanguageCode($uid, false)]);
|
||||
$languages = $this->l10n->getAvailableLanguages();
|
||||
|
||||
$first_day_of_week = $this->pConfig->get($uid, 'calendar', 'first_day_of_week', 0);
|
||||
$weekdays = [
|
||||
|
@ -249,6 +254,7 @@ class Display extends BaseSettings
|
|||
'$d_ctset' => $this->t('Custom Theme Settings'),
|
||||
'$d_cset' => $this->t('Content Settings'),
|
||||
'$stitle' => $this->t('Theme settings'),
|
||||
'$channel_title' => $this->t('Channels'),
|
||||
'$calendar_title' => $this->t('Calendar'),
|
||||
|
||||
'$form_security_token' => self::getFormSecurityToken('settings_display'),
|
||||
|
@ -269,6 +275,8 @@ class Display extends BaseSettings
|
|||
'$stay_local' => ['stay_local' , $this->t('Stay local'), $stay_local, $this->t("Don't go to a remote system when following a contact link.")],
|
||||
'$preview_mode' => ['preview_mode' , $this->t('Link preview mode'), $preview_mode, $this->t('Appearance of the link preview that is added to each post with a link.'), $preview_modes, false],
|
||||
|
||||
'$channel_languages' => ['channel_languages[]', $this->t('Channel languages:'), $channel_languages, $this->t('Select all languages that you want to see in your channels.'), $languages, 'multiple'],
|
||||
|
||||
'$first_day_of_week' => ['first_day_of_week' , $this->t('Beginning of week:') , $first_day_of_week , '', $weekdays , false],
|
||||
'$calendar_default_view' => ['calendar_default_view', $this->t('Default calendar view:'), $calendar_default_view, '', $calendarViews, false],
|
||||
]);
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Update;
|
||||
|
||||
use Friendica\Content\Conversation;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Module\Conversation\Channel as ChannelModule;
|
||||
|
||||
/**
|
||||
* Asynchronous update module for the Channel page
|
||||
*
|
||||
* @package Friendica\Module\Update
|
||||
*/
|
||||
class Channel extends ChannelModule
|
||||
{
|
||||
protected function rawContent(array $request = [])
|
||||
{
|
||||
$this->parseRequest($request);
|
||||
|
||||
$o = '';
|
||||
if (!empty($request['force'])) {
|
||||
$o = $this->conversation->render($this->getItems($request), Conversation::MODE_CHANNEL, true, false, 'created', $this->session->getLocalUserId());
|
||||
}
|
||||
|
||||
System::htmlUpdateExit($o);
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
namespace Friendica\Object;
|
||||
|
||||
use Friendica\Content\Conversation;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\DI;
|
||||
|
@ -73,24 +74,19 @@ class Thread
|
|||
$a = DI::app();
|
||||
|
||||
switch ($mode) {
|
||||
case 'network':
|
||||
case 'notes':
|
||||
case Conversation::MODE_NETWORK:
|
||||
case Conversation::MODE_NOTES:
|
||||
$this->profile_owner = DI::userSession()->getLocalUserId();
|
||||
$this->writable = true;
|
||||
break;
|
||||
case 'profile':
|
||||
case Conversation::MODE_PROFILE:
|
||||
case Conversation::MODE_DISPLAY:
|
||||
$this->profile_owner = $a->getProfileOwner();
|
||||
$this->writable = Security::canWriteToUserWall($this->profile_owner) || $writable;
|
||||
break;
|
||||
case 'display':
|
||||
$this->profile_owner = $a->getProfileOwner();
|
||||
$this->writable = Security::canWriteToUserWall($this->profile_owner) || $writable;
|
||||
break;
|
||||
case 'community':
|
||||
$this->profile_owner = 0;
|
||||
$this->writable = $writable;
|
||||
break;
|
||||
case 'contacts':
|
||||
case Conversation::MODE_CHANNEL:
|
||||
case Conversation::MODE_COMMUNITY:
|
||||
case Conversation::MODE_CONTACTS:
|
||||
$this->profile_owner = 0;
|
||||
$this->writable = $writable;
|
||||
break;
|
||||
|
|
|
@ -45,6 +45,7 @@ class OptimizeTables
|
|||
DBA::optimizeTable('oembed');
|
||||
DBA::optimizeTable('parsed_url');
|
||||
DBA::optimizeTable('session');
|
||||
DBA::optimizeTable('post-engagement');
|
||||
|
||||
if (DI::config()->get('system', 'optimize_all_tables')) {
|
||||
DBA::optimizeTable('apcontact');
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace Friendica\Worker;
|
|||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Contact\Relation;
|
||||
use Friendica\Model\Post;
|
||||
|
||||
/**
|
||||
* Update the interaction scores
|
||||
|
@ -41,6 +42,9 @@ class UpdateScores
|
|||
DBA::close($users);
|
||||
|
||||
Logger::notice('Score update done');
|
||||
|
||||
Post\Engagement::expire();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ use Friendica\Database\DBA;
|
|||
|
||||
// This file is required several times during the test in DbaDefinition which justifies this condition
|
||||
if (!defined('DB_UPDATE_VERSION')) {
|
||||
define('DB_UPDATE_VERSION', 1530);
|
||||
define('DB_UPDATE_VERSION', 1531);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -162,8 +162,8 @@ return [
|
|||
"user-gserver" => [
|
||||
"comment" => "User settings about remote servers",
|
||||
"fields" => [
|
||||
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "Owner User id"],
|
||||
"gsid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["gserver" => "id"], "comment" => "Gserver id"],
|
||||
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "primary" => "1", "comment" => "Owner User id"],
|
||||
"gsid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["gserver" => "id"], "primary" => "1", "comment" => "Gserver id"],
|
||||
"ignored" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "server accounts are ignored for the user"],
|
||||
],
|
||||
"indexes" => [
|
||||
|
@ -1323,6 +1323,24 @@ return [
|
|||
"PRIMARY" => ["uri-id"],
|
||||
]
|
||||
],
|
||||
"post-engagement" => [
|
||||
"comment" => "Engagement data per post",
|
||||
"fields" => [
|
||||
"uri-id" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"],
|
||||
"owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Item owner"],
|
||||
"contact-type" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Person, organisation, news, community, relay"],
|
||||
"media-type" => ["type" => "tinyint", "not null" => "1", "default" => "0", "comment" => "Type of media in a bit array (1 = image, 2 = video, 4 = audio"],
|
||||
"language" => ["type" => "varbinary(128)", "comment" => "Language information about this post"],
|
||||
"created" => ["type" => "datetime", "comment" => ""],
|
||||
"comments" => ["type" => "mediumint unsigned", "comment" => "Number of comments"],
|
||||
"activities" => ["type" => "mediumint unsigned", "comment" => "Number of activities (like, dislike, ...)"],
|
||||
],
|
||||
"indexes" => [
|
||||
"PRIMARY" => ["uri-id"],
|
||||
"owner-id" => ["owner-id"],
|
||||
"created" => ["created"],
|
||||
]
|
||||
],
|
||||
"post-history" => [
|
||||
"comment" => "Post history",
|
||||
"fields" => [
|
||||
|
|
|
@ -349,10 +349,6 @@ return [
|
|||
// This has to be quite large to deal with embedded private photos. False to use the system value.
|
||||
'ini_pcre_backtrack_limit' => 500000,
|
||||
|
||||
// interaction_score_days (Integer)
|
||||
// Number of days that are used to calculate the interaction score.
|
||||
'interaction_score_days' => 30,
|
||||
|
||||
// invitation_only (Boolean)
|
||||
// If set true registration is only possible after a current member of the node has sent an invitation.
|
||||
'invitation_only' => false,
|
||||
|
@ -800,4 +796,13 @@ return [
|
|||
// Wether the blocklist is publicly listed under /about (or in any later API)
|
||||
'public' => true,
|
||||
],
|
||||
'channel' => [
|
||||
// engagement_hours (Integer)
|
||||
// Number of hours posts are held in the engagement table
|
||||
'engagement_hours' => 24,
|
||||
|
||||
// interaction_score_days (Integer)
|
||||
// Number of days that are used to calculate the interaction score.
|
||||
'interaction_score_days' => 30,
|
||||
],
|
||||
];
|
||||
|
|
|
@ -391,6 +391,7 @@ return [
|
|||
'/event/{mode:edit|copy}/{id:\d+}' => [Module\Calendar\Event\Form::class, [R::GET ]],
|
||||
],
|
||||
|
||||
'/channel[/{content}]' => [Module\Conversation\Channel::class, [R::GET]],
|
||||
'/community[/{content}]' => [Module\Conversation\Community::class, [R::GET]],
|
||||
|
||||
'/compose[/{type}]' => [Module\Item\Compose::class, [R::GET, R::POST]],
|
||||
|
@ -686,6 +687,7 @@ return [
|
|||
'/toggle_mobile' => [Module\ToggleMobile::class, [R::GET]],
|
||||
'/tos' => [Module\Tos::class, [R::GET]],
|
||||
|
||||
'/update_channel[/{content}]' => [Module\Update\Channel::class, [R::GET]],
|
||||
'/update_community[/{content}]' => [Module\Update\Community::class, [R::GET]],
|
||||
|
||||
'/update_display' => [Module\Update\Display::class, [R::GET]],
|
||||
|
|
13
update.php
13
update.php
|
@ -62,6 +62,7 @@ use Friendica\Model\User;
|
|||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Protocol\Delivery;
|
||||
use Friendica\Security\PermissionSet\Repository\PermissionSet;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
||||
// Post-update script of PR 5751
|
||||
function update_1298()
|
||||
|
@ -1377,3 +1378,15 @@ function update_1525(): int
|
|||
|
||||
return Update::SUCCESS;
|
||||
}
|
||||
|
||||
function update_1531()
|
||||
{
|
||||
$threads = Post::selectThread(Item::DELIVER_FIELDLIST, ["`uid` = ? AND `created` > ?", 0, DateTimeFormat::utc('now - ' . DI::config()->get('channel', 'engagement_hours') . ' hour')]);
|
||||
while ($post = Post::fetch($threads)) {
|
||||
$post['gravity'] = Item::GRAVITY_COMMENT;
|
||||
Post\Engagement::storeFromItem($post);
|
||||
}
|
||||
DBA::close($threads);
|
||||
|
||||
return Update::SUCCESS;
|
||||
}
|
|
@ -506,7 +506,7 @@ function NavUpdate() {
|
|||
$('nav').trigger('nav-update', data.result);
|
||||
|
||||
// start live update
|
||||
['network', 'profile', 'community', 'notes', 'display', 'contact'].forEach(function (src) {
|
||||
['network', 'profile', 'channel', 'community', 'notes', 'display', 'contact'].forEach(function (src) {
|
||||
if ($('#live-' + src).length) {
|
||||
liveUpdate(src);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,7 +3,11 @@
|
|||
<label for="id_{{$field.0}}">{{$field.1}}</label>
|
||||
<select name="{{$field.0}}" id="id_{{$field.0}}" aria-describedby="{{$field.0}}_tip" {{$field.5 nofilter}}>
|
||||
{{foreach $field.4 as $opt=>$val}}
|
||||
{{if $field.5=='multiple'}}
|
||||
<option value="{{$opt}}" dir="auto"{{if $opt|in_array:$field.2}} selected="selected"{{/if}}>{{$val}}</option>
|
||||
{{else}}
|
||||
<option value="{{$opt}}" dir="auto"{{if $opt==$field.2}} selected="selected"{{/if}}>{{$val}}</option>
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
</select>
|
||||
{{if $field.3}}
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
<a accesskey="p" id="nav-home-link" class="nav-commlink {{$nav.home.2}} {{$sel.home}}" href="{{$nav.home.0}}" title="{{$nav.home.3}}">{{$nav.home.1}}</a>
|
||||
<span id="home-update" class="nav-ajax-left"></span>
|
||||
{{/if}}
|
||||
{{if $nav.channel}}
|
||||
<a accesskey="l" id="nav-channel-link" class="nav-commlink {{$nav.channel.2}} {{$sel.channel}}" href="{{$nav.channel.0}}" title="{{$nav.channel.3}}">{{$nav.channel.1}}</a>
|
||||
{{/if}}
|
||||
{{if $nav.community}}
|
||||
<a accesskey="c" id="nav-community-link" class="nav-commlink {{$nav.community.2}} {{$sel.community}}" href="{{$nav.community.0}}" title="{{$nav.community.3}}">{{$nav.community.1}}</a>
|
||||
{{/if}}
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
{{include file="field_checkbox.tpl" field=$stay_local}}
|
||||
{{include file="field_select.tpl" field=$preview_mode}}
|
||||
|
||||
<h2>{{$channel_title}}</h2>
|
||||
{{include file="field_select.tpl" field=$channel_languages}}
|
||||
|
||||
<h2>{{$calendar_title}}</h2>
|
||||
{{include file="field_select.tpl" field=$first_day_of_week}}
|
||||
{{include file="field_select.tpl" field=$calendar_default_view}}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<h3>{{$title}}</h3>
|
||||
</span>
|
||||
<ul class="sidebar-community-no-sharer-ul">
|
||||
<li role="menuitem" class="sidebar-community-no-sharer-li{{if !$no_sharer}} selected{{/if}}"><a href="community/{{$path_all}}">{{$all}}</a></li>
|
||||
<li role="menuitem" class="sidebar-community-no-sharer-li{{if $no_sharer}} selected{{/if}}"><a href="community/{{$path_no_sharer}}">{{$no_sharer_label}}</a></li>
|
||||
<li role="menuitem" class="sidebar-community-no-sharer-li{{if !$no_sharer}} selected{{/if}}"><a href="{{$base}}/{{$path_all}}">{{$all}}</a></li>
|
||||
<li role="menuitem" class="sidebar-community-no-sharer-li{{if $no_sharer}} selected{{/if}}"><a href="{{$base}}/{{$path_no_sharer}}">{{$no_sharer_label}}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<script>
|
||||
|
|
|
@ -3,7 +3,11 @@
|
|||
<label for="id_{{$field.0}}">{{$field.1}}</label>
|
||||
<select name="{{$field.0}}" id="id_{{$field.0}}" class="form-control" aria-describedby="{{$field.0}}_tip" {{$field.5 nofilter}}>
|
||||
{{foreach $field.4 as $opt=>$val}}
|
||||
{{if $field.5=='multiple'}}
|
||||
<option value="{{$opt}}" {{if $opt|in_array:$field.2}}selected="selected"{{/if}}>{{$val}}</option>
|
||||
{{else}}
|
||||
<option value="{{$opt}}" {{if $opt==$field.2}}selected="selected"{{/if}}>{{$val}}</option>
|
||||
{{/if}}
|
||||
{{/foreach}}
|
||||
</select>
|
||||
{{if $field.3}}
|
||||
|
|
|
@ -54,6 +54,15 @@
|
|||
class="nav-network-badge badge nav-notification"></span></a>
|
||||
</li>
|
||||
{{/if}}
|
||||
|
||||
{{if $nav.channel}}
|
||||
<li class="nav-segment">
|
||||
<a accesskey="l" class="nav-menu {{$sel.channel}}" href="{{$nav.channel.0}}"
|
||||
data-toggle="tooltip" aria-label="{{$nav.channel.3}}" title="{{$nav.channel.3}}"><i
|
||||
class="fa fa-lg fa-newspaper-o fa-fw" aria-hidden="true"></i></a>
|
||||
</li>
|
||||
{{/if}}
|
||||
|
||||
{{if $nav.home}}
|
||||
<li class="nav-segment">
|
||||
<a accesskey="p" class="nav-menu {{$sel.home}}" href="{{$nav.home.0}}" data-toggle="tooltip"
|
||||
|
|
|
@ -74,6 +74,24 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<div class="section-subtitle-wrapper panel-heading" role="tab" id="channel-settings-title">
|
||||
<h2>
|
||||
<button class="btn-link accordion-toggle collapsed" data-toggle="collapse" data-parent="#settings" href="#channel-settings-content" aria-expanded="false" aria-controls="channel-settings-content">
|
||||
{{$channel_title}}
|
||||
</button>
|
||||
</h2>
|
||||
</div>
|
||||
<div id="channel-settings-content" class="panel-collapse collapse{{if !$theme && !$mobile_theme && !$theme_config}} in{{/if}}" role="tabpanel" aria-labelledby="channel-settings">
|
||||
<div class="panel-body">
|
||||
{{include file="field_select.tpl" field=$channel_languages}}
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
<button type="submit" name="submit" class="btn btn-primary" value="{{$submit}}">{{$submit}}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<div class="section-subtitle-wrapper panel-heading" role="tab" id="calendar-settings-title">
|
||||
<h2>
|
||||
|
|
|
@ -36,6 +36,12 @@
|
|||
<a class="{{$nav.events.2}} mobile-view" href="{{$nav.events.0}}" title="{{$nav.events.3}}"><i class="icon s22 icon-calendar"></i></a>
|
||||
</li>
|
||||
{{/if}}
|
||||
{{if $nav.channel}}
|
||||
<li role="menuitem" id="nav-channel-link" class="nav-menu {{$sel.channel}}">
|
||||
<a accesskey="l" class="{{$nav.channel.2}} desktop-view" href="{{$nav.channel.0}}" title="{{$nav.channel.3}}">{{$nav.channel.1}}</a>
|
||||
<a class="{{$nav.channel.2}} mobile-view" href="{{$nav.channel.0}}" title="{{$nav.channel.3}}"><i class="icon s22 icon-bullseye"></i></a>
|
||||
</li>
|
||||
{{/if}}
|
||||
{{if $nav.community}}
|
||||
<li role="menuitem" id="nav-community-link" class="nav-menu {{$sel.community}}">
|
||||
<a accesskey="c" class="{{$nav.community.2}} desktop-view" href="{{$nav.community.0}}" title="{{$nav.community.3}}">{{$nav.community.1}}</a>
|
||||
|
|
Loading…
Reference in New Issue
Block a user