mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 04:15:12 +00:00
start on network/home notification refactor
This commit is contained in:
parent
4d97432214
commit
96c8e74438
3 changed files with 94 additions and 8 deletions
|
@ -21,8 +21,7 @@ $arr = array(
|
||||||
'commtag' => t('Community Tagging'),
|
'commtag' => t('Community Tagging'),
|
||||||
'categories' => t('Post Categories'),
|
'categories' => t('Post Categories'),
|
||||||
'filing' => t('Saved Folders'),
|
'filing' => t('Saved Folders'),
|
||||||
'archives' => t('Archives'),
|
'archives' => t('Search by Date'),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
60
include/notify.php
Normal file
60
include/notify.php
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
function format_notification($item) {
|
||||||
|
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
// convert this logic into a json array just like the system notifications
|
||||||
|
|
||||||
|
switch($item['verb']){
|
||||||
|
case ACTIVITY_LIKE:
|
||||||
|
|
||||||
|
|
||||||
|
$notif_content .= replace_macros($tpl_item_likes,array(
|
||||||
|
'$itemem_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$item['parent'],
|
||||||
|
'$itemem_image' => $item['author-avatar'],
|
||||||
|
'$itemem_text' => sprintf( t("%s liked %s's post"), $item['author-name'], $item['pname']),
|
||||||
|
'$itemem_when' => relative_date($item['created'])
|
||||||
|
));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ACTIVITY_DISLIKE:
|
||||||
|
$notif_content .= replace_macros($tpl_item_dislikes,array(
|
||||||
|
'$itemem_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$item['parent'],
|
||||||
|
'$itemem_image' => $item['author-avatar'],
|
||||||
|
'$itemem_text' => sprintf( t("%s disliked %s's post"), $item['author-name'], $item['pname']),
|
||||||
|
'$itemem_when' => relative_date($item['created'])
|
||||||
|
));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ACTIVITY_FRIEND:
|
||||||
|
|
||||||
|
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
|
||||||
|
$obj = parse_xml_string($xmlhead.$item['object']);
|
||||||
|
$item['fname'] = $obj->title;
|
||||||
|
|
||||||
|
$notif_content .= replace_macros($tpl_item_friends,array(
|
||||||
|
'$itemem_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$item['parent'],
|
||||||
|
'$itemem_image' => $item['author-avatar'],
|
||||||
|
'$itemem_text' => sprintf( t("%s is now friends with %s"), $item['author-name'], $item['fname']),
|
||||||
|
'$itemem_when' => relative_date($item['created'])
|
||||||
|
));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
$itemem_text = (($item['id'] == $item['parent'])
|
||||||
|
? sprintf( t("%s created a new post"), $item['author-name'])
|
||||||
|
: sprintf( t("%s commented on %s's post"), $item['author-name'], $item['pname']));
|
||||||
|
$tpl = (($item['id'] == $item['parent']) ? $tpl_item_posts : $tpl_item_comments);
|
||||||
|
|
||||||
|
$notif_content .= replace_macros($tpl,array(
|
||||||
|
'$itemem_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$item['parent'],
|
||||||
|
'$itemem_image' => $item['author-avatar'],
|
||||||
|
'$itemem_text' => $itemem_text,
|
||||||
|
'$itemem_when' => relative_date($it['created'])
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
27
mod/ping.php
27
mod/ping.php
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
|
|
||||||
require_once('include/bbcode.php');
|
require_once('include/bbcode.php');
|
||||||
|
require_once('include/notify.php');
|
||||||
|
|
||||||
function ping_init(&$a) {
|
function ping_init(&$a) {
|
||||||
|
|
||||||
|
@ -89,6 +90,32 @@ function ping_init(&$a) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(argc() > 1 && (argv(1) === 'network' || argv(1) === 'home')) {
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
|
||||||
|
$r = q("SELECT id, item_restrict, item_flags FROM item
|
||||||
|
WHERE item_restrict = %d and item_flags & %d and `item`.`uid` = %d",
|
||||||
|
intval(ITEM_VISIBLE),
|
||||||
|
intval(ITEM_UNSEEN),
|
||||||
|
intval(local_user())
|
||||||
|
);
|
||||||
|
|
||||||
|
if($r) {
|
||||||
|
foreach($r as $item) {
|
||||||
|
if((argv(1) === 'home') && (! ($item['item_flags'] & ITEM_HOME)))
|
||||||
|
continue;
|
||||||
|
$result[] = format_notification($item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode(array( argv(1) => $result));
|
||||||
|
killme();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Normal ping - just the counts
|
||||||
|
|
||||||
$t = q("select count(*) as total from notify where uid = %d and seen = 0",
|
$t = q("select count(*) as total from notify where uid = %d and seen = 0",
|
||||||
intval(local_user())
|
intval(local_user())
|
||||||
|
|
Loading…
Reference in a new issue