hide&delete remote notices from qvitter-instances

This commit is contained in:
Hannes Mannerheim 2015-06-18 20:55:46 +02:00
parent eee1084be4
commit 1c8d539237
4 changed files with 92 additions and 43 deletions

View File

@ -500,13 +500,17 @@ class QvitterPlugin extends Plugin {
}
}
if($notice->object_type == 'activity') {
if($notice->object_type == 'activity' || $notice->object_type == 'http://activitystrea.ms/schema/1.0/activity') {
$twitter_status['is_activity'] = true;
}
else {
$twitter_status['is_activity'] = false;
}
if($notice->verb == 'qvitter-delete-notice') {
$twitter_status['qvitter_delete_notice'] = true;
}
return true;
}
@ -704,9 +708,73 @@ class QvitterPlugin extends Plugin {
}
$notif->delete();
// outputs an activity notice that this notice was deleted
$profile = $notice->getProfile();
$rendered = sprintf(_m('<a href="%1$s">%2$s</a> deleted notice <a href="%3$s">{{%4$s}}</a>.'),
$profile->getUrl(),
$profile->getBestName(),
$notice->getUrl(),
$notice->uri);
$uri = TagURI::mint('delete-notice:%d:%d:%s',
$notice->profile_id,
$notice->id,
common_date_iso8601(common_sql_now()));
$notice = Notice::saveNew($notice->profile_id,
$notice->uri,
ActivityPlugin::SOURCE,
array('rendered' => $rendered,
'urls' => array(),
'uri' => $uri,
'verb' => 'qvitter-delete-notice',
'object_type' => ActivityObject::ACTIVITY));
return true;
}
/**
* Checks for deleted remote notices and deleted the locally
* A local qvitter-delete-notice is outputted in the onNoticeDeleteRelated event above
*
* @return boolean hook flag
*/
public function onEndHandleFeedEntry($activity) {
if($activity->verb == 'qvitter-delete-notice') {
$deleter_profile_uri = $activity->actor->id;
$deleted_notice_uri = $activity->objects[0]->objects[0]->content;
$deleted_notice_uri = substr($deleted_notice_uri,strpos($deleted_notice_uri,'{{')+2);
$deleted_notice_uri = substr($deleted_notice_uri,0,strpos($deleted_notice_uri,'}}'));
$deleter_ostatus_profile = Ostatus_profile::getKV('uri', $deleter_profile_uri);
if(!$deleter_ostatus_profile instanceof Ostatus_profile) {
return true;
}
$deleter_profile = Profile::getKV('id', $deleter_ostatus_profile->profile_id);
$deleted_notice = Notice::getKV('uri', $deleted_notice_uri);
if(!($deleter_profile instanceof Profile) || !($deleted_notice instanceof Notice)) {
return true;
}
if($deleter_profile->id != $deleted_notice->profile_id) {
return true;
}
$deleted_notice->delete();
}
return true;
}
/**
* Add notification on subscription, remove on unsubscribe
*

View File

@ -2298,7 +2298,7 @@ ul.queet-actions li .icon.is-mine:before {
.modal-container .queet.rtl .account-group > .avatar {
right:0;
}
.modal-container .modal-body .stream-item .queet.rtl .account-group > .avatar {
.modal-container .modal-body .queet.rtl .account-group > .avatar {
right:12px;
}
.queet.rtl .stream-item-header {

View File

@ -1333,36 +1333,6 @@ function centerPopUp(thisPopUp) {
/* ·
·
· Gnu social don't use url as uri anymore, we need to handle both cases
·
· · · · · · · · · · · · · */
function convertNewGNUSocialURItoURL(obj) {
if(typeof obj.uri == 'undefined') {
obj.uri = '';
}
if(obj.uri.substring(0,4) != 'http') {
// guess the url if we only have the non-url uri
if(typeof obj.url == 'undefined') {
var httpOrHttps = obj.user.statusnet_profile_url.substring(0,obj.user.statusnet_profile_url.indexOf('://'));
obj.uri = httpOrHttps + '://' + obj.uri.substring(4,obj.uri.indexOf(',')) + '/notice/' + obj.uri.substring(obj.uri.indexOf('noticeId=')+9,obj.uri.indexOf(':objectType'));
}
// if an url record is present, use that
else {
obj.uri = obj.url;
}
}
return obj;
}
/* ·
·
· Get and show conversation
@ -1579,6 +1549,7 @@ function addToFeed(feed, after, extraClasses, isReply) {
}
}
// if this is the notifications feed, but not if it is a reply
if(window.currentStream.substring(0,35) == 'qvitter/statuses/notifications.json'
&& !isReply) {
@ -1607,13 +1578,11 @@ function addToFeed(feed, after, extraClasses, isReply) {
if(obj.ntype == 'like') {
var noticeTime = parseTwitterDate(obj.notice.created_at);
obj.notice = convertNewGNUSocialURItoURL(obj.notice);
var notificationHtml = '<div data-quitter-id-in-stream="' + obj.id + '" id="stream-item-n-' + obj.id + '" class="stream-item ' + extraClassesThisRun + ' notification like"><div class="queet"><div class="dogear"></div>' + ostatusHtml + '<div class="queet-content"><div class="stream-item-header"><a class="account-group" href="' + obj.from_profile.statusnet_profile_url + '"></span><img class="avatar" src="' + obj.from_profile.profile_image_url + '" /><strong class="name" data-user-id="' + obj.from_profile.id + '" title="@' + obj.from_profile.screen_name + '">' + obj.from_profile.name + '</strong></a> ' + window.sL.xFavedYourQueet + '<small class="created-at" data-created-at="' + obj.created_at + '" title="' + obj.created_at + '">' + notificationTime + '</small></div><div class="small-grey-notice"><a href="' + obj.notice.uri + '">' + noticeTime + '</a>: ' + $.trim(obj.notice.statusnet_html) + '</div></div></div></div>';
var notificationHtml = '<div data-quitter-id-in-stream="' + obj.id + '" id="stream-item-n-' + obj.id + '" class="stream-item ' + extraClassesThisRun + ' notification like"><div class="queet"><div class="dogear"></div>' + ostatusHtml + '<div class="queet-content"><div class="stream-item-header"><a class="account-group" href="' + obj.from_profile.statusnet_profile_url + '"></span><img class="avatar" src="' + obj.from_profile.profile_image_url + '" /><strong class="name" data-user-id="' + obj.from_profile.id + '" title="@' + obj.from_profile.screen_name + '">' + obj.from_profile.name + '</strong></a> ' + window.sL.xFavedYourQueet + '<small class="created-at" data-created-at="' + obj.created_at + '" title="' + obj.created_at + '">' + notificationTime + '</small></div><div class="small-grey-notice"><a href="' + window.siteInstanceURL + 'notice/' + obj.notice.id + '">' + noticeTime + '</a>: ' + $.trim(obj.notice.statusnet_html) + '</div></div></div></div>';
}
else if(obj.ntype == 'repeat') {
obj.notice = convertNewGNUSocialURItoURL(obj.notice);
var noticeTime = parseTwitterDate(obj.notice.created_at);
var notificationHtml = '<div data-quitter-id-in-stream="' + obj.id + '" id="stream-item-n-' + obj.id + '" class="stream-item ' + extraClassesThisRun + ' notification repeat"><div class="queet"><div class="queet-content"><div class="dogear"></div>' + ostatusHtml + '<div class="stream-item-header"><a class="account-group" href="' + obj.from_profile.statusnet_profile_url + '"><img class="avatar" src="' + obj.from_profile.profile_image_url + '" /><strong class="name" data-user-id="' + obj.from_profile.id + '" title="@' + obj.from_profile.screen_name + '">' + obj.from_profile.name + '</strong></a> ' + window.sL.xRepeatedYourQueet + '<small class="created-at" data-created-at="' + obj.created_at + '" title="' + obj.created_at + '">' + notificationTime + '</small></div><div class="small-grey-notice"><a href="' + obj.notice.uri + '">' + noticeTime + '</a>: ' + $.trim(obj.notice.statusnet_html) + '</div></div></div></div>';
var notificationHtml = '<div data-quitter-id-in-stream="' + obj.id + '" id="stream-item-n-' + obj.id + '" class="stream-item ' + extraClassesThisRun + ' notification repeat"><div class="queet"><div class="queet-content"><div class="dogear"></div>' + ostatusHtml + '<div class="stream-item-header"><a class="account-group" href="' + obj.from_profile.statusnet_profile_url + '"><img class="avatar" src="' + obj.from_profile.profile_image_url + '" /><strong class="name" data-user-id="' + obj.from_profile.id + '" title="@' + obj.from_profile.screen_name + '">' + obj.from_profile.name + '</strong></a> ' + window.sL.xRepeatedYourQueet + '<small class="created-at" data-created-at="' + obj.created_at + '" title="' + obj.created_at + '">' + notificationTime + '</small></div><div class="small-grey-notice"><a href="' + window.siteInstanceURL + 'notice/' + obj.notice.id + '">' + noticeTime + '</a>: ' + $.trim(obj.notice.statusnet_html) + '</div></div></div></div>';
}
else if(obj.ntype == 'mention') {
var notificationHtml = buildQueetHtml(obj.notice, obj.id, extraClassesThisRun + ' notification mention');
@ -1779,6 +1748,18 @@ function addToFeed(feed, after, extraClasses, isReply) {
// ordinary tweet
else {
// if this is a special qvitter-delete-notice activity notice it means we try to hide
// the deleted notice from our stream
if(typeof obj.qvitter_delete_notice != 'undefined' && obj.qvitter_delete_notice == true) {
var streamItemToHide = $('.stream-item[data-uri="' + obj.text + '"]');
streamItemToHide.animate({opacity:'0.2'},1000,'linear',function(){
$(this).css('height',$(this).height() + 'px');
$(this).animate({height:'0px'},500,'linear',function(){
$(this).remove();
});
});
}
// don't show any notices with object_type "activity"
if(typeof obj.is_activity != 'undefined' && obj.is_activity === true) {
return true;
@ -1790,7 +1771,7 @@ function addToFeed(feed, after, extraClasses, isReply) {
// activity get special design
if(obj.source == 'activity') {
var queetTime = parseTwitterDate(obj.created_at);
var queetHtml = '<div id="stream-item-' + obj.id + '" class="stream-item activity ' + extraClassesThisRun + '" data-quitter-id="' + obj.id + '" data-conversation-id="' + obj.statusnet_conversation_id + '" data-quitter-id-in-stream="' + obj.id + '"><div class="queet" id="q-' + obj.id + '"><div class="queet-content"><div class="stream-item-header"><small class="created-at" data-created-at="' + obj.created_at + '"><a href="' + obj.uri + '">' + queetTime + '</a></small></div><div class="queet-text">' + $.trim(obj.statusnet_html) + '</div></div></div></div>';
var queetHtml = '<div id="stream-item-' + obj.id + '" class="stream-item activity ' + extraClassesThisRun + '" data-quitter-id="' + obj.id + '" data-conversation-id="' + obj.statusnet_conversation_id + '" data-quitter-id-in-stream="' + obj.id + '"><div class="queet" id="q-' + obj.id + '"><div class="queet-content"><div class="stream-item-header"><small class="created-at" data-created-at="' + obj.created_at + '"><a href="' + window.siteInstanceURL + 'notice/' + obj.id + '">' + queetTime + '</a></small></div><div class="queet-text">' + $.trim(obj.statusnet_html) + '</div></div></div></div>';
// detect rtl
queetHtml = detectRTL(queetHtml);
@ -2015,7 +1996,6 @@ function buildQueetHtml(obj, idInStream, extraClassesThisRun, requeeted_by, isCo
requeetHtml = '<div class="context" id="requeet-' + requeeted_by.id + '"><span class="with-icn"><i class="badge-requeeted"></i><span class="requeet-text"> ' + window.sL.requeetedBy.replace('{requeeted-by}',requeetedByHtml) + '</span></span></div>';
}
obj = convertNewGNUSocialURItoURL(obj);
// external
var ostatusHtml = '';
@ -2026,6 +2006,7 @@ function buildQueetHtml(obj, idInStream, extraClassesThisRun, requeeted_by, isCo
var queetTime = parseTwitterDate(obj.created_at);
var queetHtml = '<div \
id="' + idPrepend + 'stream-item-' + obj.id + '" \
data-uri="' + obj.uri + '" \
class="stream-item ' + extraClassesThisRun + ' ' + requeetedClass + ' ' + favoritedClass + '" \
data-attachments=\'' + JSON.stringify(obj.attachments) + '\'\
data-source="' + escape(obj.source) + '" \

View File

@ -120,5 +120,5 @@
"ellipsisMore": "Mer",
"blockUser": "Blockera {username}",
"goToOriginalNotice": "Gå till den ursprungliga queeten",
"clickToDrag":"Klicka för att dra"
"clickToDrag":"Klicka och dra för att flytta"
}