1
0
Fork 0

Merge pull request #6345 from MrPetovan/bug/6283-clear-message-notifications

Clear private message notifications
This commit is contained in:
Tobias Diekershoff 2018-12-31 08:21:55 +01:00 committed by GitHub
commit e7ee3d7200
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 131 additions and 110 deletions

View file

@ -303,41 +303,58 @@ function message_content(App $a)
$o .= $header;
$r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
WHERE `mail`.`uid` = %d AND `mail`.`id` = %d LIMIT 1",
intval(local_user()),
intval($a->argv[1])
$message = DBA::fetchFirst("
SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
FROM `mail`
LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
WHERE `mail`.`uid` = ? AND `mail`.`id` = ?
LIMIT 1",
local_user(),
$a->argv[1]
);
if (DBA::isResult($r)) {
$contact_id = $r[0]['contact-id'];
$convid = $r[0]['convid'];
if (DBA::isResult($message)) {
$contact_id = $message['contact-id'];
$sql_extra = sprintf(" and `mail`.`parent-uri` = '%s' ", DBA::escape($r[0]['parent-uri']));
if ($convid)
$sql_extra = sprintf(" and ( `mail`.`parent-uri` = '%s' OR `mail`.`convid` = '%d' ) ",
DBA::escape($r[0]['parent-uri']),
intval($convid)
);
$params = [
local_user(),
$message['parent-uri']
];
$messages = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
WHERE `mail`.`uid` = %d $sql_extra ORDER BY `mail`.`created` ASC",
intval(local_user())
if ($message['convid']) {
$sql_extra = "AND (`mail`.`parent-uri` = ? OR `mail`.`convid` = ?)";
$params[] = $message['convid'];
} else {
$sql_extra = "AND `mail`.`parent-uri` = ?";
}
$messages_stmt = DBA::p("
SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
FROM `mail`
LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
WHERE `mail`.`uid` = ?
$sql_extra
ORDER BY `mail`.`created` ASC",
...$params
);
$messages = DBA::toArray($messages_stmt);
DBA::update('mail', ['seen' => 1], ['parent-uri' => $message['parent-uri'], 'uid' => local_user()]);
if ($message['convid']) {
// Clear Diaspora private message notifications
DBA::update('notify', ['seen' => 1], ['type' => NOTIFY_MAIL, 'parent' => $message['convid'], 'uid' => local_user()]);
}
// Clear DFRN private message notifications
DBA::update('notify', ['seen' => 1], ['type' => NOTIFY_MAIL, 'parent' => $message['parent-uri'], 'uid' => local_user()]);
} else {
$messages = false;
}
if (!DBA::isResult($messages)) {
notice(L10n::t('Message not available.') . EOL);
return $o;
}
$r = q("UPDATE `mail` SET `seen` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d",
DBA::escape($r[0]['parent-uri']),
intval(local_user())
);
$tpl = Renderer::getMarkupTemplate('msg-header.tpl');
$a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
'$baseurl' => System::baseUrl(true),
@ -350,8 +367,10 @@ function message_content(App $a)
$unknown = false;
foreach ($messages as $message) {
if ($message['unknown'])
if ($message['unknown']) {
$unknown = true;
}
if ($message['from-url'] == $myprofile) {
$from_url = $myprofile;
$sparkle = '';
@ -499,7 +518,6 @@ function render_messages(array $msg, $t)
$participants = L10n::t("%s and You", $rr['from-name']);
}
$subject_e = (($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>');
$body_e = $rr['body'];
$to_name_e = $rr['name'];
@ -517,7 +535,7 @@ function render_messages(array $msg, $t)
'$from_addr' => defaults($contact, 'addr', ''),
'$sparkle' => ' sparkle',
'$from_photo' => ProxyUtils::proxifyUrl($from_photo, false, ProxyUtils::SIZE_THUMB),
'$subject' => $subject_e,
'$subject' => $rr['title'],
'$delete' => L10n::t('Delete conversation'),
'$body' => $body_e,
'$to_name' => $to_name_e,

View file

@ -64,14 +64,7 @@ function ping_init(App $a)
$format = 'json';
}
$tags = [];
$comments = [];
$likes = [];
$dislikes = [];
$friends = [];
$posts = [];
$regs = [];
$mails = [];
$notifications = [];
$intro_count = 0;
@ -282,22 +275,6 @@ function ping_init(App $a)
}
}
if (DBA::isResult($mails)) {
foreach ($mails as $mail) {
$notif = [
'id' => 0,
'href' => System::baseUrl() . '/message/' . $mail['id'],
'name' => $mail['from-name'],
'url' => $mail['from-url'],
'photo' => $mail['from-photo'],
'date' => $mail['created'],
'seen' => false,
'message' => L10n::t('{0} sent you a message'),
];
$notifs[] = $notif;
}
}
if (DBA::isResult($regs)) {
foreach ($regs as $reg) {
$notif = [
@ -384,7 +361,7 @@ function ping_init(App $a)
if ($format == 'json') {
$data['groups'] = $groups_unseen;
$data['forums'] = $forums_unseen;
$data['notify'] = $sysnotify_count + $intro_count + $mail_count + $register_count;
$data['notify'] = $sysnotify_count + $intro_count + $register_count;
$data['notifications'] = $notifications;
$data['sysmsgs'] = [
'notice' => $sysmsgs,
@ -427,8 +404,6 @@ function ping_get_notifications($uid)
$order = "DESC";
$quit = false;
$a = get_app();
do {
$r = q(
"SELECT `notify`.*, `item`.`visible`, `item`.`deleted`
@ -505,8 +480,8 @@ function ping_get_notifications($uid)
* @param array $notifs Complete list of notification
* @param array $sysmsgs List of system notice messages
* @param array $sysmsgs_info List of system info messages
* @param int $groups_unseen Number of unseen group items
* @param int $forums_unseen Number of unseen forum items
* @param array $groups_unseen List of unseen group messages
* @param array $forums_unseen List of unseen forum messages
*
* @return array XML-transform ready data array
*/