Browse Source

Merge pull request #141 from erqan/mentions-at-the-beginning

hiding options for the posts those begin with a mention
master
miguelfreitas 11 years ago
parent
commit
3ff3f74070
  1. 22
      js/interface_localization.js
  2. 62
      js/options.js
  3. 55
      js/twister_timeline.js
  4. 30
      options.html

22
js/interface_localization.js

@ -211,7 +211,16 @@ if(preferredLanguage == "en"){ @@ -211,7 +211,16 @@ if(preferredLanguage == "en"){
"Split only new post": "Split only new post",
"Split all": "Split all",
"Don't split": "Don't split",
"Split long posts": "Split long posts"
"Split long posts": "Split long posts",
"Posts that begin with mention": "Posts that begin with mention",
"Show all": "Show all",
"Show only if I am in": "Show only if I am in",
"Show if it's between users I follow": "Show if it's between users I follow",
"Postboard displays": "Postboard displays",
"RTs those are close to original twist": "RTs those are close to original twist",
"Show if the original is older than": "Show if the original is older than",
"hour(s)": "hour(s)",
"only numbers are allowed!": "only numbers are allowed!"
};
}
if(preferredLanguage == "es"){
@ -1822,7 +1831,16 @@ if(preferredLanguage == "tr"){ @@ -1822,7 +1831,16 @@ if(preferredLanguage == "tr"){
"Split only new post": "Sadece yeni postaları böl",
"Split all": "Hepsini böl",
"Don't split": "Bölme",
"Split long posts": "Uzun gönderileri böl"
"Split long posts": "Uzun gönderileri böl",
"Posts that begin with mention": "Bahsettiği kullanıcının adıyla başlayan gönderiler",
"Show all": "Hepsini göster",
"Show only if I am in": "Sadece ben içindeysem göster",
"Show if it's between users I follow": "Takip ettiğim kullanıcılar arasında ise göster",
"Postboard displays": "Zaman çizelgesinde",
"RTs those are close to original twist": "Orjinal twist'e yakın olan RTler",
"Show if the original is older than": "Orjinali yandaki süreden daha eskiyse göster",
"hour(s)": "saat",
"only numbers are allowed!": "sadece rakam girilebilir!"
};
}

62
js/options.js

@ -247,7 +247,7 @@ var TwisterOptions = function() @@ -247,7 +247,7 @@ var TwisterOptions = function()
return $.Options.getOption('splitPosts', 'disable');
}
this.setSplitPostsOpt = function (){
this.setSplitPostsOpt = function () {
$('#splitPosts')[0].value = this.getSplitPostsOpt();
if (this.getSplitPostsOpt() === 'enable')
@ -255,7 +255,7 @@ var TwisterOptions = function() @@ -255,7 +255,7 @@ var TwisterOptions = function()
else
$("#splitPostWarning")[0].style.display = "none";
$('#splitPosts').on('change', function (){
$('#splitPosts').on('change', function () {
$.Options.setOption(this.id, this.value);
if (this.value === 'enable')
@ -265,6 +265,61 @@ var TwisterOptions = function() @@ -265,6 +265,61 @@ var TwisterOptions = function()
});
}
this.getHideRepliesOpt = function () {
return $.Options.getOption('hideReplies', 'following');
}
this.setHideRepliesOpt = function () {
$('#hideReplies')[0].value = this.getHideRepliesOpt();
$('#hideReplies').on('change', function () {
$.Options.setOption(this.id, this.value);
});
}
this.getHideCloseRTsOpt = function () {
return $.Options.getOption('hideCloseRTs', 'disable');
};
this.setHideCloseRTsOpt = function () {
$('#hideCloseRTs')[0].value = this.getHideCloseRTsOpt();
if (this.getHideCloseRTsOpt() === 'disable') {
$('#hideCloseRTsDesc')[0].style.display = 'none';
} else {
$('#hideCloseRTsDesc')[0].style.display = 'inline';
}
$('#hideCloseRTs').on('change', function () {
$.Options.setOption(this.id, this.value);
if (this.value === 'disable') {
$('#hideCloseRTsDesc')[0].style.display = 'none';
} else {
$('#hideCloseRTsDesc')[0].style.display = 'inline';
}
});
};
this.getHideCloseRTsHourOpt = function () {
return parseInt($.Options.getOption('hideCloseRtsHour', '1'));
};
this.setHideCloseRTsHourOpt = function () {
$('#hideCloseRtsHour')[0].value = this.getHideCloseRTsHourOpt().toString();
$('#hideCloseRtsHour').on('keyup', function () {
if (/^\d+$/.test(this.value)) {
this.style.backgroundColor = '';
$.Options.setOption(this.id, this.value);
$(this).next('span').text(polyglot.t('hour(s)'));
} else {
this.style.backgroundColor = '#f00';
$(this).next('span').text(polyglot.t('only numbers are allowed!'));
}
});
};
this.InitOptions = function() {
this.soundNotifOptions();
this.volumeControl();
@ -281,6 +336,9 @@ var TwisterOptions = function() @@ -281,6 +336,9 @@ var TwisterOptions = function()
this.setUseProxyOpt();
this.setUseProxyForImgOnlyOpt();
this.setSplitPostsOpt();
this.setHideRepliesOpt();
this.setHideCloseRTsHourOpt();
this.setHideCloseRTsOpt();
}
}

55
js/twister_timeline.js

@ -140,8 +140,15 @@ function requestGetposts(req) @@ -140,8 +140,15 @@ function requestGetposts(req)
// request if needed
function processReceivedPosts(req, posts)
{
//hiding posts can cause empty postboard, so we have to track the count...
var p2a = posts.length;
for( var i = 0; i < posts.length; i++ ) {
var post = posts[i];
if (willBeHidden(post)) {
p2a--;
continue;
}
var streamPost = postToElem(post, "original");
var timePost = post["userpost"]["time"];
streamPost.attr("data-time",timePost);
@ -192,11 +199,15 @@ function processReceivedPosts(req, posts) @@ -192,11 +199,15 @@ function processReceivedPosts(req, posts)
}
req.doneReportProcessing(posts.length);
if( req.mode == "done" ) {
//if the count of posts less then 5....
if( req.mode == "done" && p2a > 5) {
timelineLoaded = true;
$.MAL.postboardLoaded();
_refreshInProgress = false;
} else {
//we will request more older post...
req.count += postsPerRefresh;
req.mode = 'older';
requestGetposts(req);
}
}
@ -266,7 +277,14 @@ function processLastHave(userHaves) @@ -266,7 +277,14 @@ function processLastHave(userHaves)
// callback for getposts to update the number of new pending posts not shown in timeline
function processNewPostsConfirmation(expected, posts)
{
_newPostsPending += posts.length;
//we don't want to produce alert for the posts that won't be displayed
var p2h = 0;
for( var i = posts.length-1; i >= 0; i-- ) {
if (willBeHidden(posts[i])) {
p2h++;
}
}
_newPostsPending += posts.length - p2h;
if( _newPostsPending ) {
$.MAL.reportNewPosts(_newPostsPending);
}
@ -288,3 +306,36 @@ function timelineChangedUser() @@ -288,3 +306,36 @@ function timelineChangedUser()
_newPostsPending = 0;
timelineLoaded = false;
}
function willBeHidden(post){
var msg = post['userpost']['msg'];
var hidden = false;
if (post['userpost']['n'] === defaultScreenName)
return false;
if ($.Options.getHideRepliesOpt() !== 'disable' &&
/^\@/.test(msg) &&
!(new RegExp('@' + defaultScreenName + '( |,|;|\\.|:|\\/|\\?|\\!|\\\\|\'|"|\\n|$)').test(msg)))
{
if ($.Options.getHideRepliesOpt() === 'only-me' ||
($.Options.getHideRepliesOpt() === 'following' &&
followingUsers.indexOf(msg.substring(1, msg.search(/ |,|;|\.|:|\/|\?|\!|\\|'|"|\n/))) === -1 ))
{
hidden = true;
}
}
if (typeof(post['userpost']['rt']) !== 'undefined' &&
$.Options.getHideCloseRTsOpt() != 'disable' &&
followingUsers.indexOf(post['userpost']['rt']['n']) > -1 &&
parseInt(post['userpost']['time']) - parseInt(post['userpost']['rt']['time']) < $.Options.getHideCloseRTsHourOpt() * 3600)
{
if (hidden)
return false;
else
return true;
}
return hidden;
}

30
options.html

@ -136,6 +136,36 @@ @@ -136,6 +136,36 @@
</div>
</div>
<div class="postboard-display">
<div class="module">
<p class="label"> Postboard displays </p>
<br/>
<div>
<form action="" id="hideRepliesOpt">
<p class="label">Posts that begin with mention</p>
<select name="" id="hideReplies">
<option value="disable">Show all</option>
<option value="only-me">Show only if I am in</option>
<option value="following">Show if it's between users I follow</option>
</select>
</form>
</div>
<br/>
<div>
<form action="" id="hideCloseRTsOpt">
<p class="label">RTs those are close to original twist</p>
<select name="" id="hideCloseRTs">
<option value="disable">Show all</option>
<option value="show-if">Show if the original is older than</option>
</select>
<div id="hideCloseRTsDesc">
<input name="" id="hideCloseRtsHour" maxlength="2" size="3"/> <span class="label">hour(s)</span>
</div>
</form>
</div>
</div>
</div>
<div class="posts-display">
<div class="module">
<p class="label"> Posts display </p>

Loading…
Cancel
Save