mirror of
https://github.com/friendica/friendica
synced 2024-11-09 16:22:56 +00:00
New "UserItem" class, new notification type field
This commit is contained in:
parent
7420d07699
commit
4bfd0abec7
3 changed files with 91 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 2019.12-rc (Dalmatian Bellflower)
|
||||
-- DB_UPDATE_VERSION 1328
|
||||
-- Friendica 2020.03-dev (Dalmatian Bellflower)
|
||||
-- DB_UPDATE_VERSION 1329
|
||||
-- ------------------------------------------
|
||||
|
||||
|
||||
|
@ -1285,6 +1285,7 @@ CREATE TABLE IF NOT EXISTS `user-item` (
|
|||
`hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide an item from the user',
|
||||
`ignored` boolean COMMENT 'Ignore this thread if set',
|
||||
`pinned` boolean COMMENT 'The item is pinned on the profile page',
|
||||
`notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
|
||||
PRIMARY KEY(`uid`,`iid`),
|
||||
INDEX `uid_pinned` (`uid`,`pinned`)
|
||||
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific item data';
|
||||
|
|
85
src/Model/UserItem.php
Normal file
85
src/Model/UserItem.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file src/Model/UserItem.php
|
||||
*/
|
||||
|
||||
namespace Friendica\Model;
|
||||
|
||||
use Friendica\Database\DBA;
|
||||
|
||||
class UserItem
|
||||
{
|
||||
/**
|
||||
* Checks an item for notifications and sets the "notification-type" field
|
||||
*
|
||||
* @param array $item The message array that is checked for notifications
|
||||
* @param int $uid User ID
|
||||
*/
|
||||
public static function setNotification($item, $uid)
|
||||
{
|
||||
}
|
||||
|
||||
private static function checkShared($item, $uid)
|
||||
{
|
||||
if ($item['gravity'] != GRAVITY_PARENT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send a notification for every new post?
|
||||
// Either the contact had posted something directly
|
||||
if (DBA::exists('contact', ['id' => $item['contact-id'], 'notify_new_posts' => true])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Or the contact is a mentioned forum
|
||||
$tags = DBA::select('term', ['url'], ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => TERM_MENTION, 'uid' => $uid]);
|
||||
while ($tag = DBA::fetch($tags)) {
|
||||
$condition = ['nurl' => Strings::normaliseLink($tag["url"]), 'uid' => $uid, 'notify_new_posts' => true, 'contact-type' => Contact::TYPE_COMMUNITY];
|
||||
if (DBA::exists('contact', $condition)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is the user mentioned in this post?
|
||||
private static function checkTagged($item, $uid)
|
||||
{
|
||||
if ($item["mention"]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($profiles AS $profile) {
|
||||
if (strpos($item["tag"], "=".$profile."]") || strpos($item["body"], "=".$profile."]"))
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($defaulttype == NOTIFY_TAGSELF) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function checkCommented($item, $uid)
|
||||
{
|
||||
// Is it a post that the user had started?
|
||||
$fields = ['ignored', 'mention'];
|
||||
$thread = Item::selectFirstThreadForUser($uid, $fields, ['iid' => $item["parent"], 'deleted' => false]);
|
||||
|
||||
if ($thread['mention'] && !$thread['ignored']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// And now we check for participation of one of our contacts in the thread
|
||||
$condition = ['parent' => $item["parent"], 'author-id' => $contacts, 'deleted' => false];
|
||||
|
||||
if (!$thread['ignored'] && Item::exists($condition)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -34,7 +34,7 @@
|
|||
use Friendica\Database\DBA;
|
||||
|
||||
if (!defined('DB_UPDATE_VERSION')) {
|
||||
define('DB_UPDATE_VERSION', 1328);
|
||||
define('DB_UPDATE_VERSION', 1329);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -1388,7 +1388,8 @@ return [
|
|||
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["user" => "uid"], "comment" => "User id"],
|
||||
"hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Marker to hide an item from the user"],
|
||||
"ignored" => ["type" => "boolean", "comment" => "Ignore this thread if set"],
|
||||
"pinned" => ["type" => "boolean", "comment" => "The item is pinned on the profile page"]
|
||||
"pinned" => ["type" => "boolean", "comment" => "The item is pinned on the profile page"],
|
||||
"notification-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
|
||||
],
|
||||
"indexes" => [
|
||||
"PRIMARY" => ["uid", "iid"],
|
||||
|
|
Loading…
Reference in a new issue