Notifications cleared for a whole thread in case of one mark seen
This commit is contained in:
parent
4ab893a561
commit
7909d9c417
|
@ -5957,11 +5957,11 @@ function api_friendica_notification_seen($type)
|
||||||
$id = (!empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0);
|
$id = (!empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$notification = DI::notify()->getByID($id);
|
$notify = DI::notify()->getByID($id);
|
||||||
$notification->setSeen();
|
DI::notify()->setSeen(true, $notify);
|
||||||
|
|
||||||
if ($notification->otype === Notify::OTYPE_ITEM) {
|
if ($notify->otype === Notify::OTYPE_ITEM) {
|
||||||
$item = Item::selectFirstForUser(api_user(), [], ['id' => $notification->iid, 'uid' => api_user()]);
|
$item = Item::selectFirstForUser(api_user(), [], ['id' => $notify->iid, 'uid' => api_user()]);
|
||||||
if (DBA::isResult($item)) {
|
if (DBA::isResult($item)) {
|
||||||
// we found the item, return it to the user
|
// we found the item, return it to the user
|
||||||
$ret = api_format_items([$item], $user_info, false, $type);
|
$ret = api_format_items([$item], $user_info, false, $type);
|
||||||
|
@ -5973,6 +5973,8 @@ function api_friendica_notification_seen($type)
|
||||||
return api_format_data('result', $type, ['result' => "success"]);
|
return api_format_data('result', $type, ['result' => "success"]);
|
||||||
} catch (NotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
throw new BadRequestException('Invalid argument');
|
throw new BadRequestException('Invalid argument');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
throw new InternalServerErrorException('Internal Server exception');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Friendica\Model;
|
namespace Friendica\Model;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use Friendica\BaseModel;
|
use Friendica\BaseModel;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
|
@ -50,24 +49,6 @@ class Notify extends BaseModel
|
||||||
$this->setMsgCache();
|
$this->setMsgCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the notification as seen
|
|
||||||
*
|
|
||||||
* @param bool $seen true, if seen
|
|
||||||
*
|
|
||||||
* @return bool True, if the seen state could be saved
|
|
||||||
*/
|
|
||||||
public function setSeen(bool $seen = true)
|
|
||||||
{
|
|
||||||
$this->seen = $seen;
|
|
||||||
try {
|
|
||||||
return $this->repo->update($this);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$this->logger->warning('Update failed.', ['$this' => $this, 'exception' => $e]);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the pre-formatted name (caching)
|
* Sets the pre-formatted name (caching)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -44,8 +44,8 @@ class Notification extends BaseModule
|
||||||
// @TODO: Replace with parameter from router
|
// @TODO: Replace with parameter from router
|
||||||
if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
|
if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
|
||||||
try {
|
try {
|
||||||
$success = DI::notify()->setAllSeen();
|
$success = DI::notify()->setSeen();
|
||||||
}catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
DI::logger()->warning('set all seen failed.', ['exception' => $e]);
|
DI::logger()->warning('set all seen failed.', ['exception' => $e]);
|
||||||
$success = false;
|
$success = false;
|
||||||
}
|
}
|
||||||
|
@ -66,11 +66,11 @@ class Notification extends BaseModule
|
||||||
|
|
||||||
if ($request_id) {
|
if ($request_id) {
|
||||||
try {
|
try {
|
||||||
$notification = DI::notify()->getByID($request_id);
|
$notify = DI::notify()->getByID($request_id);
|
||||||
$notification->setSeen();
|
DI::notify()->setSeen(true, $notify);
|
||||||
|
|
||||||
if (!empty($notification->link)) {
|
if (!empty($notify->link)) {
|
||||||
System::externalRedirect($notification->link);
|
System::externalRedirect($notify->link);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (HTTPException\NotFoundException $e) {
|
} catch (HTTPException\NotFoundException $e) {
|
||||||
|
@ -83,4 +83,3 @@ class Notification extends BaseModule
|
||||||
DI::baseUrl()->redirect('notifications/system');
|
DI::baseUrl()->redirect('notifications/system');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ use Friendica\BaseRepository;
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
use Friendica\Model;
|
use Friendica\Model;
|
||||||
use Friendica\Collection;
|
use Friendica\Collection;
|
||||||
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
use Friendica\Network\HTTPException\NotFoundException;
|
use Friendica\Network\HTTPException\NotFoundException;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
|
|
||||||
|
@ -52,14 +53,28 @@ class Notify extends BaseRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* Set seen state of notifications of the local_user()
|
||||||
|
*
|
||||||
|
* @param bool $seen optional true or false. default true
|
||||||
|
* @param Model\Notify $notify optional a notify, which should be set seen (including his parents)
|
||||||
*
|
*
|
||||||
* @return bool true on success, false on error
|
* @return bool true on success, false on error
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function setAllSeen(bool $seen = true)
|
public function setSeen(bool $seen = true, Model\Notify $notify = null)
|
||||||
{
|
{
|
||||||
return $this->dba->update('notify', ['seen' => $seen], ['uid' => local_user()]);
|
if (empty($notify)) {
|
||||||
|
$conditions = ['uid' => local_user()];
|
||||||
|
} else {
|
||||||
|
$conditions = ['(`link` = ? OR (`parent` != 0 AND `parent` = ? AND `otype` = ?)) AND `uid` = ?',
|
||||||
|
$notify->link,
|
||||||
|
$notify->parent,
|
||||||
|
$notify->otype,
|
||||||
|
local_user()];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->dba->update('notify', ['seen' => $seen], $conditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,12 +82,12 @@ class Notify extends BaseRepository
|
||||||
*
|
*
|
||||||
* @return Model\Notify|false
|
* @return Model\Notify|false
|
||||||
*
|
*
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws InternalServerErrorException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function insert(array $fields)
|
public function insert(array $fields)
|
||||||
{
|
{
|
||||||
$fields['date'] = DateTimeFormat::utcNow();
|
$fields['date'] = DateTimeFormat::utcNow();
|
||||||
|
|
||||||
Hook::callAll('enotify_store', $fields);
|
Hook::callAll('enotify_store', $fields);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue