]> git.mxchange.org Git - friendica.git/commitdiff
New "UserItem" class, new notification type field
authorMichael <heluecht@pirati.ca>
Sat, 4 Jan 2020 12:21:42 +0000 (12:21 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 4 Jan 2020 12:21:42 +0000 (12:21 +0000)
database.sql
src/Model/UserItem.php [new file with mode: 0644]
static/dbstructure.config.php

index 6a55db52699a41d5a4c925ad2e9b77a003ccacb0..02d1ac895c5d517d4e3362e1124a2bdbce2d6a21 100644 (file)
@@ -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';
diff --git a/src/Model/UserItem.php b/src/Model/UserItem.php
new file mode 100644 (file)
index 0000000..26c42f1
--- /dev/null
@@ -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;
+       }
+}
index ada837fb265b427771f6a16643106b92bb609c82..a7d851943d00cb227e51499f180645528f57edb7 100755 (executable)
@@ -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"],