diff --git a/QvitterPlugin.php b/QvitterPlugin.php index b4df80e..b940941 100644 --- a/QvitterPlugin.php +++ b/QvitterPlugin.php @@ -703,13 +703,31 @@ class QvitterPlugin extends Plugin { // reply-to profile url try { $reply = $notice->getParent(); - $twitter_status['in_reply_to_profileurl'] = $reply->getProfile()->getUrl(); - $twitter_status['in_reply_to_ostatus_uri'] = $reply->getProfile()->getUri(); + $reply_profile = $reply->getProfile(); + $twitter_status['in_reply_to_profileurl'] = $reply_profile->getUrl(); + $twitter_status['in_reply_to_ostatus_uri'] = $reply_profile->getUri(); } catch (ServerException $e) { $twitter_status['in_reply_to_profileurl'] = null; $twitter_status['in_reply_to_ostatus_uri'] = null; } + // attentions + try { + $attentions = $notice->getAttentionProfiles(); + $attentions_array = array(); + foreach ($attentions as $attn) { + $attentions_array[] = array( + 'id' => $attn->getID(), + 'screen_name' => $attn->getNickname(), + 'fullname' => $attn->getStreamName(), + 'profileurl' => $attn->getUrl(), + 'ostatus_uri' => $attn->getUri(), + ); + } + $twitter_status['attentions'] = $attentions_array; + } catch (Exception $e) { + // + } // fave number $faves = Fave::byNotice($notice); diff --git a/js/dom-functions.js b/js/dom-functions.js index c20d494..1be4b06 100644 --- a/js/dom-functions.js +++ b/js/dom-functions.js @@ -1338,32 +1338,33 @@ function replyFormHtml(streamItem,qid) { // object with ostatus-uri as key to avoid duplicates var screenNamesToAdd = {}; - // add the screen name to the one we're replying to (if it's not me) + // we don't trust attentions to be in the right order, so always add the + // screen name to the one we're replying to first (if it's not me) if(!thisIsALinkToMyProfile(streamItem.attr('data-user-profile-url'))) { screenNamesToAdd[streamItem.attr('data-user-ostatus-uri')] = streamItem.attr('data-user-screen-name'); } - // add the screen name to the one who the one we're replying to is replying to - // (if it's not me, and not if the author is replying to themselves) - if(q.find('i.addressees > span.reply-to').length > 0 - && !thisIsALinkToMyProfile(streamItem.attr('data-in-reply-to-profile-url')) - && streamItem.attr('data-in-reply-to-profile-ostatus-uri') != streamItem.attr('data-user-ostatus-uri')) { - screenNamesToAdd[streamItem.attr('data-in-reply-to-profile-ostatus-uri')] = streamItem.attr('data-in-reply-to-screen-name'); - } - - // get all other mentions (if it's not me, or reply-to user or reply-to-reply-to user - // because gnusocial in not consistent in which url it supplies in the mentions links - // we have to check both uri and profileurl - $.each(q.find('.queet-text').find('.mention'),function(key,obj){ - if(!thisIsALinkToMyProfile($(obj).attr('href')) - && $(obj).attr('href') != streamItem.attr('data-in-reply-to-profile-ostatus-uri') - && $(obj).attr('href') != streamItem.attr('data-in-reply-to-profile-url') - && $(obj).attr('href') != streamItem.attr('data-user-profile-url') - && $(obj).attr('href') != streamItem.attr('data-user-ostatus-uri')) { - var thisMention = $(obj).html().replace('@',''); - screenNamesToAdd[$(obj).attr('href')] = thisMention; + // add the rest of the attentions (not me) + if(q.children('script.attentions-json').length > 0 + && q.children('script.attentions-json').text() != 'undefined') { + try { + var attentionsParsed = JSON.parse(q.children('script.attentions-json').text()); } - }); + catch(e) { + var attentionsParsed = false; + console.log('could not parse attentions json: ' + e); + console.log("attentions-json: " + q.children('script.attentions-json').text()); + } + + if(attentionsParsed !== false) { + $.each(attentionsParsed, function() { + if(!thisIsALinkToMyProfile(this.profileurl) + && typeof screenNamesToAdd[this.ostatus_uri] == 'undefined') { + screenNamesToAdd[this.ostatus_uri] = this.screen_name; + } + }); + } + } // build reply/rant strings var repliesText = ''; @@ -2039,7 +2040,16 @@ function buildQueetHtml(obj, idInStream, extraClasses, requeeted_by, isConversat if(obj.in_reply_to_screen_name !== null && obj.in_reply_to_profileurl !== null && obj.in_reply_to_profileurl != obj.user.statusnet_profile_url) { - reply_to_html = '@' + obj.in_reply_to_screen_name + ' '; + var replyToProfileurl = obj.in_reply_to_profileurl; + var replyToScreenName = obj.in_reply_to_screen_name; + } + // if we don't have a reply-to, we might have attentions, in that case use the first one as reply + else if(typeof obj.attentions != 'undefined' && typeof obj.attentions[0] != 'undefined') { + var replyToProfileurl = obj.attentions[0].profileurl; + var replyToScreenName = obj.attentions[0].screen_name; + } + if(typeof replyToProfileurl != 'undefined' && typeof replyToScreenName != 'undefined') { + reply_to_html = '@' + replyToScreenName + ' '; } // in-groups html @@ -2120,6 +2130,7 @@ function buildQueetHtml(obj, idInStream, extraClasses, requeeted_by, isConversat ' + requeetedByMe + '>\
\ \ + \ ' + requeetHtml + '\ ' + ostatusHtml + '\
\ diff --git a/js/misc-functions.js b/js/misc-functions.js index 81885fd..91f437d 100644 --- a/js/misc-functions.js +++ b/js/misc-functions.js @@ -1044,6 +1044,16 @@ function searchForUpdatedNoticeData(obj) { streamItemsUpdated = true; } + // attentions might have been added to a notice + if(queetFoundInFeed.children('script.attentions-json').text() != JSON.stringify(obj.attentions)) { + if(queetFoundInFeed.children('script.attentions-json').length == 0) { + queetFoundInFeed.prepend(''); + } + else { + queetFoundInFeed.children('script.attentions-json').text(JSON.stringify(obj.attentions)); + } + } + // set favorite data queetFoundInFeed.find('.action-fav-num').attr('data-fav-num',obj.fave_num); queetFoundInFeed.find('.action-fav-num').html(obj.fave_num);