quoted notices

This commit is contained in:
Hannes Mannerheim 2016-01-07 03:03:18 +01:00
parent 62817126a4
commit 7554706792
4 changed files with 205 additions and 7 deletions

View File

@ -567,6 +567,66 @@ class QvitterPlugin extends Plugin {
}
}
// quoted notices
if (!empty($twitter_status['attachments'])) {
foreach ($twitter_status['attachments'] as &$attachment) {
$quoted_notice = false;
// if this attachment has an url this might be a notice url
if (isset($attachment['url'])) {
$noticeurl = common_path('notice/', StatusNet::isHTTPS());
$instanceurl = common_path('', StatusNet::isHTTPS());
// local notice urls
if(stristr($attachment['url'], $noticeurl)) {
$possible_notice_id = str_replace($noticeurl,'',$attachment['url']);
if(ctype_digit($possible_notice_id)) {
$quoted_notice = Notice::getKV('id',$possible_notice_id);;
}
}
// remote. but we don't want to lookup every url in the db,
// so only do this if we have reason to believe this might
// be a remote notice url
elseif(!stristr($attachment['url'], $instanceurl) && stristr($attachment['url'],'/notice/')) {
$quoted_notice = Notice::getKV('url',$attachment['url']);
}
// include the quoted notice in the attachment
if($quoted_notice instanceof Notice) {
$quoted_notice_author = Profile::getKV('id',$quoted_notice->profile_id);
if($quoted_notice_author instanceof Profile) {
$attachment['quoted_notice']['id'] = $quoted_notice->id;
$attachment['quoted_notice']['content'] = $quoted_notice->content;
$attachment['quoted_notice']['nickname'] = $quoted_notice_author->nickname;
$attachment['quoted_notice']['fullname'] = $quoted_notice_author->fullname;
$quoted_notice_attachments = $quoted_notice->attachments();
foreach($quoted_notice_attachments as $q_attach) {
if(is_object($q_attach)) {
try {
$qthumb = $q_attach->getThumbnail();
$thumb_url = File_thumbnail::url($qthumb->filename);
$attachment['quoted_notice']['attachments'][] = array('thumb_url'=>$thumb_url,
'attachment_id'=>$q_attach->id);
} catch (Exception $e) {
common_debug('Qvitter: exception: '.$e.' could not get thumbnail for attachment id='.$q_attach->id.' in quoted notice id='.$quoted_notice->id);
}
}
}
}
}
}
}
}
try {
$twitter_status['external_url'] = $notice->getUrl(true);
} catch (InvalidUrlException $e) {
common_debug('Qvitter: No URL available for external notice: id='.$notice->id);
}
// reply-to profile url
try {
$reply = $notice->getParent();

View File

@ -652,7 +652,9 @@ class QvitterAction extends ApiAction
span.inline-reply-caret,
.stream-item.expanded .stream-item.first-visible-after-parent,
#popup-faq #faq-container p.indent,
.post-to-group {
.post-to-group,
.quoted-notice:hover,
.stream-item:hover:not(.expanded) .quoted-notice:hover {
border-color:/*LIGHTERBORDERCOLORSTART*/rgb(155,206,224)/*LIGHTERBORDERCOLOREND*/;
}
span.inline-reply-caret .caret-inner {

View File

@ -2005,6 +2005,83 @@ body.rtl .queet.rtl .expanded-content {
display:block;
}
.quoted-notices {
width:100%;
position:relative;
}
.quoted-notice {
width:100%;
border: 1px solid #eee;
border-radius: 4px;
cursor: pointer;
display: table;
table-layout: fixed;
padding: 12px;
box-sizing: border-box;
margin-top:12px;
color:#292f33 !important;
overflow: hidden;
}
.stream-item:hover:not(.expanded) .quoted-notice {
border: 1px solid #ddd;
}
.quoted-notice-attachments {
width:100%;
position: relative;
overflow:hidden;
}
.quoted-notice-attachments-num-1 {
height: 102px;
width: 102px;
margin-right: 12px;
float: left;
}
.quoted-notice-img-container {
height: 102px;
width: 102px;
display: inline-block;
margin-right: 7px;
margin-top:7px;
background-size:cover;
background-repeat:no-repeat;
background-position: center;
}
.quoted-notice-attachments-num-1 .quoted-notice-img-container {
height: 100%;
width: 100%;
margin:0;
}
.quoted-notice-img {
height: 100%;
opacity: 0;
width: 100%;
}
.quoted-notice-header {
line-height:20px;
margin-bottom:5px;
}
.quoted-notice-author-fullname {
font-weight: bold;
}
.quoted-notice-author-nickname {
font-size:13px;
color:#999;
}
.quoted-notice-author-nickname::before {
content:"@";
}
.quoted-notice-body {
white-space: pre-wrap;
word-wrap: break-word;
}
.queet .queet-thumbs {
-webkit-transition: max-height 0s linear;
-moz-transition: max-height 0s linear;
@ -2537,7 +2614,7 @@ ul.queet-actions li .icon {
position: relative;
}
ul.queet-actions li:not(:first-child) .icon {
margin-left:26px;
margin-left:52px;
}
.queet.rtl ul.queet-actions .icon {
margin-left:26px;

View File

@ -1955,6 +1955,17 @@ function buildQueetHtml(obj, idInStream, extraClasses, requeeted_by, isConversat
URItoUse += '-activity-notice';
}
// attachment html and attachment url's to hide
var attachmentBuild = buildAttachmentHTML(obj.attachments);
var statusnetHTML = $('<div/>').html(obj.statusnet_html);
$.each(statusnetHTML.find('a'),function(){
if(attachmentBuild.urlsToHide.indexOf($(this).text()) > -1) {
$(this).css('display','none');
}
});
statusnetHTML = statusnetHTML.html();
// external
var ostatusHtml = '';
if(obj.is_local === false) {
@ -1988,8 +1999,8 @@ function buildQueetHtml(obj, idInStream, extraClasses, requeeted_by, isConversat
<a data-tooltip="' + parseTwitterLongDate(obj.created_at) + '" href="' + window.siteInstanceURL + 'notice/' + obj.id + '">' + queetTime + '</a>\
</small>\
</div>\
<div class="queet-text">' + $.trim(obj.statusnet_html) + '</div>\
' + buildAttachmentHTML(obj.attachments) + '\
<div class="queet-text">' + $.trim(statusnetHTML) + '</div>\
' + attachmentBuild.html + '\
<div class="stream-item-footer">\
' + queetActions + '\
</div>\
@ -2016,12 +2027,57 @@ function buildQueetHtml(obj, idInStream, extraClasses, requeeted_by, isConversat
function buildAttachmentHTML(attachments){
var attachment_html = '';
var quotedNoticeHTML = '';
var attachmentNum = 0;
var urlsToHide = [];
if(typeof attachments != "undefined") {
$.each(attachments, function(){
if(typeof this.thumb_url != 'undefined'
// quoted notices
if(typeof this.quoted_notice != 'undefined') {
var quotedContent = this.quoted_notice.content;
// quoted notice's attachments' thumb urls
var quotedAttachmentsHTML = '';
var quotedAttachmentsHTMLbefore = '';
var quotedAttachmentsHTMLafter = '';
if(typeof this.quoted_notice.attachments != 'undefined' && this.quoted_notice.attachments.length > 0) {
quotedAttachmentsHTML += '<div class="quoted-notice-attachments quoted-notice-attachments-num-' + this.quoted_notice.attachments.length + '">'
$.each(this.quoted_notice.attachments,function(k,qAttach){
quotedAttachmentsHTML += '<div class="quoted-notice-img-container" style="background-image:url(\'' + qAttach.thumb_url + '\')"><img class="quoted-notice-img" src="' + qAttach.thumb_url + '" /></div>';
// remove attachment string from content
quotedContent = quotedContent.split(window.siteInstanceURL + 'attachment/' + qAttach.attachment_id).join('');
});
quotedAttachmentsHTML += '</div>';
// if there is only one attachment, it goes before, otherwise after
if(this.quoted_notice.attachments.length == 1) {
quotedAttachmentsHTMLbefore = quotedAttachmentsHTML;
}
else {
quotedAttachmentsHTMLafter = quotedAttachmentsHTML;
}
}
// hide the notice url in the queet text
urlsToHide.push(this.url);
quotedNoticeHTML += '<a href="' + window.siteInstanceURL + 'notice/' + this.quoted_notice.id + '" class="quoted-notice" data-notice-url=' + this.url + '>\
' + quotedAttachmentsHTMLbefore + '\
<div class="quoted-notice-header">\
<span class="quoted-notice-author-fullname">' + this.quoted_notice.fullname + '</span>\
<span class="quoted-notice-author-nickname">' + this.quoted_notice.nickname + '</span>\
</div>\
<div class="quoted-notice-body">' + $.trim(quotedContent) + '</div>\
' + quotedAttachmentsHTMLafter + '\
</a>';
}
// if there's a local thumb_url we assume this is a image or video
else if(typeof this.thumb_url != 'undefined'
&& this.thumb_url !== null
&& isLocalURL(this.thumb_url)) { // if there's a local thumb_url we assume this is a image or video
&& isLocalURL(this.thumb_url)) {
var bigThumbW = 1000;
var bigThumbH = 3000;
if(bigThumbW > window.siteMaxThumbnailSize) {
@ -2069,13 +2125,16 @@ function buildAttachmentHTML(attachments){
}
attachment_html = attachment_html + '<a style="background-image:url(\'' + img_url + '\')" class="thumb-container' + noCoverClass + playButtonClass + youTubeClass + '" href="' + this.url + '"><img class="attachment-thumb" data-mime-type="' + this.mimetype + '" src="' + img_url + '"/ data-width="' + this.width + '" data-height="' + this.height + '" data-full-image-url="' + this.url + '" data-thumb-url="' + img_url + '"></a>';
urlsToHide.push(window.siteInstanceURL + 'attachment/' + this.id); // hide this attachment url from the queet text
attachmentNum++;
}
else if (this.mimetype == 'image/svg+xml') {
attachment_html = attachment_html + '<a style="background-image:url(\'' + this.url + '\')" class="thumb-container" href="' + this.url + '"><img class="attachment-thumb" data-mime-type="' + this.mimetype + '" src="' + this.url + '"/></a>';
urlsToHide.push(window.siteInstanceURL + 'attachment/' + this.id); // hide this attachment url from the queet text
attachmentNum++;
}
});
}
return '<div class="queet-thumbs thumb-num-' + attachmentNum + '">' + attachment_html + '</div>';
return {html: '<div class="quoted-notices">' + quotedNoticeHTML + '</div><div class="queet-thumbs thumb-num-' + attachmentNum + '">' + attachment_html + '</div>',
urlsToHide: urlsToHide };
}