-- ------------------------------------------
-- Friendica 2020.12-dev (Red Hot Poker)
--- DB_UPDATE_VERSION 1379
+-- DB_UPDATE_VERSION 1380
-- ------------------------------------------
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\ItemContent;
use Friendica\Model\Notify;
* Creates a notification entry and possibly sends a mail
*
* @param array $params Array with the elements:
- * uid, item, parent, type, otype, verb, event,
- * link, subject, body, to_name, to_email, source_name,
- * source_link, activity, preamble, notify_flags,
- * language, show_in_notification_page
+ * type, event, otype, activity, verb, uid, cid, origin_cid, item, link,
+ * source_name, source_mail, source_nick, source_link, source_photo,
+ * show_in_notification_page
+ *
* @return bool
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
}
// Ensure that the important fields are set at any time
- $fields = ['notify-flags', 'language', 'username', 'email'];
+ $fields = ['nickname', 'page-flags', 'notify-flags', 'language', 'username', 'email'];
$user = DBA::selectFirst('user', $fields, ['uid' => $params['uid']]);
if (!DBA::isResult($user)) {
return false;
}
- $params['notify_flags'] = ($params['notify_flags'] ?? '') ?: $user['notify-flags'];
- $params['language'] = ($params['language'] ?? '') ?: $user['language'];
- $params['to_name'] = ($params['to_name'] ?? '') ?: $user['username'];
- $params['to_email'] = ($params['to_email'] ?? '') ?: $user['email'];
+ // There is no need to create notifications for forum accounts
+ if (in_array($user['page-flags'], [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP])) {
+ return false;
+ }
+
+ $nickname = $user['nickname'];
+
+ $params['notify_flags'] = $user['notify-flags'];
+ $params['language'] = $user['language'];
+ $params['to_name'] = $user['username'];
+ $params['to_email'] = $user['email'];
// from here on everything is in the recipients language
$l10n = DI::l10n()->withLang($params['language']);
+ if (!empty($params['cid'])) {
+ $contact = Contact::getById($params['cid'], ['url', 'name', 'photo']);
+ if (DBA::isResult($contact)) {
+ $params['source_link'] = $contact['url'];
+ $params['source_name'] = $contact['name'];
+ $params['source_photo'] = $contact['photo'];
+ }
+ }
+
+ if (!empty($params['origin_cid'])) {
+ $contact = Contact::getById($params['origin_cid'], ['url', 'name', 'photo']);
+ if (DBA::isResult($contact)) {
+ $params['origin_link'] = $contact['url'];
+ $params['origin_name'] = $contact['name'];
+ $params['origin_photo'] = $contact['photo'];
+ }
+ }
+
$siteurl = DI::baseUrl()->get(true);
$sitename = DI::config()->get('config', 'sitename');
$hostname = substr($hostname, 0, strpos($hostname, ':'));
}
- $user = User::getById($params['uid'], ['nickname', 'page-flags']);
-
- // There is no need to create notifications for forum accounts
- if (!DBA::isResult($user) || in_array($user["page-flags"], [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP])) {
- return false;
- }
- $nickname = $user["nickname"];
-
// Creates a new email builder for the notification email
$emailBuilder = DI::emailer()->newNotifyMail();
$emailBuilder->setHeader('X-Friendica-Account', '<' . $nickname . '@' . $hostname . '>');
- if (array_key_exists('item', $params)) {
- $title = $params['item']['title'];
- $body = $params['item']['body'];
- } else {
- $title = $body = '';
- }
-
- if (isset($params['item']['id'])) {
- $item_id = $params['item']['id'];
- } else {
- $item_id = 0;
- }
-
- if (isset($params['item']['uri-id'])) {
- $uri_id = $params['item']['uri-id'];
- } else {
- $uri_id = 0;
- }
-
- if (isset($params['parent'])) {
- $parent_id = $params['parent'];
- } else {
- $parent_id = 0;
- }
+ $title = $params['item']['title'] ?? '';
+ $body = $params['item']['body'] ?? '';
- if (isset($params['item']['parent-uri-id'])) {
- $parent_uri_id = $params['item']['parent-uri-id'];
- } else {
- $parent_uri_id = 0;
- }
+ $item_id = $params['item']['id'] ?? 0;
+ $uri_id = $params['item']['uri-id'] ?? 0;
+ $parent_id = $params['item']['parent'] ?? 0;
+ $parent_uri_id = $params['item']['parent-uri-id'] ?? 0;
$epreamble = '';
$preamble = '';
$itemlink = '';
if ($params['type'] == Notify\Type::MAIL) {
- $itemlink = $siteurl.'/message/'.$params['item']['id'];
- $params["link"] = $itemlink;
+ $itemlink = $params['link'];
$subject = $l10n->t('%s New mail received at %s', $subjectPrefix, $sitename);
$epreamble = $l10n->t('%1$s sent you %2$s.', '[url='.$params['source_link'].']'.$params['source_name'].'[/url]', '[url=' . $itemlink . ']' . $l10n->t('a private message').'[/url]');
$sitelink = $l10n->t('Please visit %s to view and/or reply to your private messages.');
- $tsitelink = sprintf($sitelink, $siteurl.'/message/'.$params['item']['id']);
- $hsitelink = sprintf($sitelink, '<a href="'.$siteurl.'/message/'.$params['item']['id'].'">'.$sitename.'</a>');
+ $tsitelink = sprintf($sitelink, $itemlink);
+ $hsitelink = sprintf($sitelink, '<a href="' . $itemlink . '">' . $sitename . '</a>');
+
+ // Mail notifications aren't using the "notify" table entry
+ $show_in_notification_page = false;
}
if ($params['type'] == Notify\Type::COMMENT || $params['type'] == Notify\Type::TAG_SELF) {
if (!empty($uri_id)) {
$fields['uri-id'] = $uri_id;
}
- if (!empty($item_id)) {
+ if (!empty($parent_id)) {
$fields['parent'] = $parent_id;
}
- if (!empty($item_id)) {
+ if (!empty($parent_uri_id)) {
$fields['parent-uri-id'] = $parent_uri_id;
}
$notification = DI::notify()->insert($fields);
// Generate the notification array
$params = [];
+ $params['otype'] = Notify\ObjectType::ITEM;
$params['uid'] = $uid;
+ $params['origin_cid'] = $params['cid'] = $item['author-id'];
$params['item'] = $item;
- $params['parent'] = $item['parent'];
$params['link'] = DI::baseUrl() . '/display/' . urlencode($item['guid']);
- $params['otype'] = 'item';
- $params['origin_name'] = $params['source_name'] = $item['author-name'];
- $params['origin_link'] = $params['source_link'] = $item['author-link'];
- $params['origin_photo'] = $params['source_photo'] = $item['author-avatar'];
// Set the activity flags
$params['activity']['explicit_tagged'] = ($notification_type & UserItem::NOTIF_EXPLICIT_TAGGED);
return false;
}
- $params['origin_name'] = $parent_item['author-name'];
- $params['origin_link'] = $parent_item['author-link'];
- $params['origin_photo'] = $parent_item['author-avatar'];
+ $params['origin_cid'] = $parent_item['author-id'];
$params['item'] = $parent_item;
}
}
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Group;
+use Friendica\Model\Notify;
use Friendica\Model\Notify\Type;
use Friendica\Model\User;
use Friendica\Protocol\Activity;
if ($combined['notify-flags'] & Type::CONFIRM) {
$mutual = ($new_relation == Contact::FRIEND);
notification([
- 'type' => Type::CONFIRM,
- 'notify_flags' => $combined['notify-flags'],
- 'language' => $combined['language'],
- 'to_name' => $combined['username'],
- 'to_email' => $combined['email'],
- 'uid' => $combined['uid'],
- 'link' => DI::baseUrl() . '/contact/' . $dfrn_record,
- 'source_name' => ((strlen(stripslashes($combined['name']))) ? stripslashes($combined['name']) : DI::l10n()->t('[Name Withheld]')),
- 'source_link' => $combined['url'],
- 'source_photo' => $combined['photo'],
- 'verb' => ($mutual ? Activity::FRIEND : Activity::FOLLOW),
- 'otype' => 'intro'
+ 'type' => Type::CONFIRM,
+ 'otype' => Notify\ObjectType::INTRO,
+ 'verb' => ($mutual ? Activity::FRIEND : Activity::FOLLOW),
+ 'uid' => $combined['uid'],
+ 'cid' => $combined['id'],
+ 'link' => DI::baseUrl() . '/contact/' . $dfrn_record,
]);
}
}
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Group;
+use Friendica\Model\Notify;
use Friendica\Model\Notify\Type;
use Friendica\Model\Profile;
use Friendica\Model\User;
if (!$auto_confirm) {
notification([
- 'type' => Type::INTRO,
- 'notify_flags' => $r[0]['notify-flags'],
- 'language' => $r[0]['language'],
- 'to_name' => $r[0]['username'],
- 'to_email' => $r[0]['email'],
- 'uid' => $r[0]['uid'],
- 'link' => DI::baseUrl() . '/notifications/intros',
- 'source_name' => ((strlen(stripslashes($r[0]['name']))) ? stripslashes($r[0]['name']) : DI::l10n()->t('[Name Withheld]')),
- 'source_link' => $r[0]['url'],
- 'source_photo' => $r[0]['photo'],
- 'verb' => Activity::REQ_FRIEND,
- 'otype' => 'intro'
+ 'type' => Type::INTRO,
+ 'otype' => Notify\ObjectType::INTRO,
+ 'verb' => Activity::REQ_FRIEND,
+ 'uid' => $r[0]['uid'],
+ 'cid' => $r[0]['id'],
+ 'link' => DI::baseUrl() . '/notifications/intros',
]);
}
if ($update) {
$item_id = $_REQUEST['item_id'];
- $item = Item::selectFirst(['uid', 'parent', 'parent-uri'], ['id' => $item_id]);
+ $item = Item::selectFirst(['uid', 'parent', 'parent-uri', 'parent-uri-id'], ['id' => $item_id]);
if ($item['uid'] != 0) {
$a->profile = ['uid' => intval($item['uid'])];
} else {
if ($a->argc == 2) {
$item_parent = 0;
- $fields = ['id', 'parent', 'parent-uri', 'uid'];
+ $fields = ['id', 'parent', 'parent-uri', 'parent-uri-id', 'uid'];
if (local_user()) {
$condition = ['guid' => $a->argv[1], 'uid' => local_user()];
}
if (!DI::pConfig()->get(local_user(), 'system', 'detailed_notif')) {
- DBA::update('notify', ['seen' => true], ['parent' => $item['parent'], 'uid' => local_user()]);
+ DBA::update('notify', ['seen' => true], ['parent-uri-id' => $item['parent-uri-id'], 'uid' => local_user()]);
}
// We are displaying an "alternate" link if that post was public. See issue 2864
use Friendica\Model\Conversation;
use Friendica\Model\FileTag;
use Friendica\Model\Item;
+use Friendica\Model\Notify;
use Friendica\Model\Notify\Type;
use Friendica\Model\Photo;
use Friendica\Model\Post;
if ($contact_record != $author) {
if ($toplevel_item_id) {
notification([
- 'type' => Type::COMMENT,
- 'notify_flags' => $user['notify-flags'],
- 'language' => $user['language'],
- 'to_name' => $user['username'],
- 'to_email' => $user['email'],
- 'uid' => $user['uid'],
- 'item' => $datarray,
- 'link' => DI::baseUrl().'/display/'.urlencode($datarray['guid']),
- 'source_name' => $datarray['author-name'],
- 'source_link' => $datarray['author-link'],
- 'source_photo' => $datarray['author-avatar'],
- 'verb' => Activity::POST,
- 'otype' => 'item',
- 'parent' => $toplevel_item_id,
- 'parent_uri' => $toplevel_item['uri']
+ 'type' => Type::COMMENT,
+ 'otype' => Notify\ObjectType::ITEM,
+ 'verb' => Activity::POST,
+ 'uid' => $user['uid'],
+ 'cid' => $datarray['author-id'],
+ 'item' => $datarray,
+ 'link' => DI::baseUrl() . '/display/' . urlencode($datarray['guid']),
]);
} elseif (empty($forum_contact)) {
notification([
- 'type' => Type::WALL,
- 'notify_flags' => $user['notify-flags'],
- 'language' => $user['language'],
- 'to_name' => $user['username'],
- 'to_email' => $user['email'],
- 'uid' => $user['uid'],
- 'item' => $datarray,
- 'link' => DI::baseUrl().'/display/'.urlencode($datarray['guid']),
- 'source_name' => $datarray['author-name'],
- 'source_link' => $datarray['author-link'],
- 'source_photo' => $datarray['author-avatar'],
- 'verb' => Activity::POST,
- 'otype' => 'item'
+ 'type' => Type::WALL,
+ 'otype' => Notify\ObjectType::ITEM,
+ 'verb' => Activity::POST,
+ 'uid' => $user['uid'],
+ 'cid' => $datarray['author-id'],
+ 'item' => $datarray,
+ 'link' => DI::baseUrl() . '/display/' . urlencode($datarray['guid']),
]);
}
}
$messages = DBA::toArray($messages_stmt);
DBA::update('mail', ['seen' => 1], ['parent-uri' => $message['parent-uri'], 'uid' => local_user()]);
- DBA::update('notify', ['seen' => 1], ['type' => Type::MAIL, 'parent' => $message['id'], 'uid' => local_user()]);
} else {
$messages = false;
}
// Don't fork from frontend tasks by default
$dont_fork = DI::config()->get("system", "worker_dont_fork", false) || !DI::mode()->isBackend();
$created = DateTimeFormat::utcNow();
+ $delayed = DBA::NULL_DATETIME;
$force_priority = false;
$run_parameter = array_shift($args);
if (is_int($run_parameter)) {
$priority = $run_parameter;
} elseif (is_array($run_parameter)) {
+ if (isset($run_parameter['delayed'])) {
+ $delayed = $run_parameter['execute'];
+ }
if (isset($run_parameter['priority'])) {
$priority = $run_parameter['priority'];
}
}
if (!$found) {
- $added = DBA::insert('workerqueue', ['parameter' => $parameters, 'created' => $created, 'priority' => $priority]);
+ $added = DBA::insert('workerqueue', ['parameter' => $parameters, 'created' => $created,
+ 'priority' => $priority, 'next_try' => $delayed]);
if (!$added) {
return false;
}
in_array($user['page-flags'], [User::PAGE_FLAGS_NORMAL])) {
notification([
- 'type' => Type::INTRO,
- 'notify_flags' => $user['notify-flags'],
- 'language' => $user['language'],
- 'to_name' => $user['username'],
- 'to_email' => $user['email'],
- 'uid' => $user['uid'],
- 'link' => DI::baseUrl() . '/notifications/intros',
- 'source_name' => ((strlen(stripslashes($contact_record['name']))) ? stripslashes($contact_record['name']) : DI::l10n()->t('[Name Withheld]')),
- 'source_link' => $contact_record['url'],
- 'source_photo' => $contact_record['photo'],
- 'verb' => ($sharing ? Activity::FRIEND : Activity::FOLLOW),
- 'otype' => 'intro'
+ 'type' => Type::INTRO,
+ 'otype' => Notify\ObjectType::INTRO,
+ 'verb' => ($sharing ? Activity::FRIEND : Activity::FOLLOW),
+ 'uid' => $user['uid'],
+ 'cid' => $contact_record['id'],
+ 'link' => DI::baseUrl() . '/notifications/intros',
]);
}
} elseif (DBA::isResult($user) && in_array($user['page-flags'], [User::PAGE_FLAGS_SOAPBOX, User::PAGE_FLAGS_FREELOVE, User::PAGE_FLAGS_COMMUNITY])) {
DBA::insert('intro', $fields);
notification([
- 'type' => Type::SUGGEST,
- 'notify_flags' => $owner['notify-flags'],
- 'language' => $owner['language'],
- 'to_name' => $owner['name'],
- 'to_email' => $owner['email'],
- 'uid' => $owner['uid'],
- 'item' => $suggest,
- 'link' => DI::baseUrl().'/notifications/intros',
- 'source_name' => $from_contact['name'],
- 'source_link' => $from_contact['url'],
- 'source_photo' => $from_contact['photo'],
- 'verb' => Activity::REQ_FRIEND,
- 'otype' => 'intro'
+ 'type' => Type::SUGGEST,
+ 'otype' => Notify\ObjectType::INTRO,
+ 'verb' => Activity::REQ_FRIEND,
+ 'uid' => $owner['uid'],
+ 'cid' => $from_contact['uid'],
+ 'item' => $suggest,
+ 'link' => DI::baseUrl().'/notifications/intros',
]);
return true;
// "Deleting" global items just means hiding them
if ($item['uid'] == 0) {
DBA::update('user-item', ['hidden' => true], ['iid' => $item['id'], 'uid' => $uid], true);
-
- // Delete notifications
- DBA::delete('notify', ['iid' => $item['id'], 'uid' => $uid]);
} elseif ($item['uid'] == $uid) {
self::markForDeletionById($item['id'], PRIORITY_HIGH);
} else {
}
}
- // Delete notifications
- DBA::delete('notify', ['iid' => $item['id'], 'uid' => $item['uid']]);
-
// Set the item to "deleted"
$item_fields = ['deleted' => true, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
DBA::update('item', $item_fields, ['id' => $item['id']]);
Post\DeliveryData::delete($item['uri-id']);
- if (!empty($item['icid']) && !self::exists(['icid' => $item['icid'], 'deleted' => false])) {
- DBA::delete('item-content', ['id' => $item['icid']], ['cascade' => false]);
- }
// When the permission set will be used in photo and events as well,
// this query here needs to be extended.
// @todo Currently deactivated. We need the permission set in the deletion process.
// send notifications.
$notif_params = [
- 'type' => Type::MAIL,
- 'notify_flags' => $user['notify-flags'],
- 'language' => $user['language'],
- 'to_name' => $user['username'],
- 'to_email' => $user['email'],
- 'uid' => $user['uid'],
- 'item' => $msg,
- 'parent' => $msg['id'],
- 'source_name' => $msg['from-name'],
- 'source_link' => $msg['from-url'],
- 'source_photo' => $msg['from-photo'],
- 'verb' => Activity::POST,
- 'otype' => 'mail'
+ 'type' => Type::MAIL,
+ 'otype' => Notify\ObjectType::MAIL,
+ 'verb' => Activity::POST,
+ 'uid' => $user['uid'],
+ 'cid' => $msg['contact-id'],
+ 'link' => DI::baseUrl() . '/message/' . $msg['id'],
];
notification($notif_params);
\notification([
'type' => Model\Notify\Type::SYSTEM,
'event' => 'SYSTEM_REGISTER_REQUEST',
+ 'uid' => $admin['uid'],
+ 'link' => $base_url . '/admin/users/',
'source_name' => $user['username'],
'source_mail' => $user['email'],
'source_nick' => $user['nickname'],
'source_link' => $base_url . '/admin/users/',
- 'link' => $base_url . '/admin/users/',
'source_photo' => $base_url . '/photo/avatar/' . $user['uid'] . '.jpg',
- 'to_email' => $admin['email'],
- 'uid' => $admin['uid'],
- 'language' => ($admin['language'] ?? '') ?: 'en',
'show_in_notification_page' => false
]);
}
use Friendica\Model\Item;
use Friendica\Model\ItemURI;
use Friendica\Model\Mail;
+use Friendica\Model\Notify;
use Friendica\Model\Notify\Type;
use Friendica\Model\PermissionSet;
use Friendica\Model\Post;
}
if ($Blink && Strings::compareLink($Blink, DI::baseUrl() . "/profile/" . $importer["nickname"])) {
- $author = DBA::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item['author-id']]);
+ $author = DBA::selectFirst('contact', ['id', 'name', 'thumb', 'url'], ['id' => $item['author-id']]);
$parent = Item::selectFirst(['id'], ['uri' => $item['thr-parent'], 'uid' => $importer["importer_uid"]]);
$item['parent'] = $parent['id'];
// send a notification
notification(
[
- "type" => Type::POKE,
- "notify_flags" => $importer["notify-flags"],
- "language" => $importer["language"],
- "to_name" => $importer["username"],
- "to_email" => $importer["email"],
- "uid" => $importer["importer_uid"],
- "item" => $item,
- "link" => DI::baseUrl()."/display/".urlencode($item['guid']),
- "source_name" => $author["name"],
- "source_link" => $author["url"],
- "source_photo" => $author["thumb"],
- "verb" => $item["verb"],
- "otype" => "person",
- "activity" => $verb,
- "parent" => $item['parent']]
+ "type" => Type::POKE,
+ "otype" => Notify\ObjectType::PERSON,
+ "activity" => $verb,
+ "verb" => $item["verb"],
+ "uid" => $importer["importer_uid"],
+ "cid" => $author["id"],
+ "item" => $item,
+ "link" => DI::baseUrl() . "/display/" . urlencode($item['guid']),
+ ]
);
}
}
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1379);
+ define('DB_UPDATE_VERSION', 1380);
}
return [
*
*/
+use Friendica\Model\Notify;
+
return [
// Empty these tables
'cache',
'iid' => 4,
'seen' => 0,
'verb' => '',
- 'otype' => 'item',
+ 'otype' => Notify\ObjectType::ITEM,
'name_cache' => 'Reply to',
'msg_cache' => 'A test reply from an item',
],
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
+use Friendica\Model\Notify;
use Friendica\Model\Photo;
use Friendica\Model\User;
use Friendica\Model\Storage;
return Update::SUCCESS;
}
+
+function update_1380()
+{
+ if (!DBA::e("UPDATE `notify` INNER JOIN `item` ON `item`.`id` = `notify`.`iid` SET `notify`.`uri-id` = `item`.`uri-id` WHERE `notify`.`uri-id` IS NULL AND `notify`.`otype` IN (?, ?)",
+ Notify\ObjectType::ITEM, Notify\ObjectType::PERSON)) {
+ return Update::FAILED;
+ }
+
+ if (!DBA::e("UPDATE `notify` INNER JOIN `item` ON `item`.`id` = `notify`.`parent` SET `notify`.`parent-uri-id` = `item`.`uri-id` WHERE `notify`.`parent-uri-id` IS NULL AND `notify`.`otype` IN (?, ?)",
+ Notify\ObjectType::ITEM, Notify\ObjectType::PERSON)) {
+ return Update::FAILED;
+ }
+
+ return Update::SUCCESS;
+}