properly exclude deleted posts from the stream #35

This commit is contained in:
Morgan McMillian 2017-07-22 08:17:35 -07:00
parent e1a81b4185
commit 7e58365dac

View file

@ -56,7 +56,8 @@ export class StreamPage {
pnut.user('me').then(res => {
this.myUsername = res.data.username;
}).catch(err => {
console.log(err);
// console.log('-*-');
// console.log(JSON.stringify(err));
});
}
@ -81,18 +82,7 @@ export class StreamPage {
}
this.fcaller.then(res => {
if (res.data.length > 0) {
for (var i = 0; i < res.data.length; i++) {
if (res.data[i]['repost_of']) {
res.data[i] = res.data[i]['repost_of']
}
for (var j = 0; j < res.data[i]['content']['entities']['mentions'].length; j++) {
var men = res.data[i]['content']['entities']['mentions'][j]['text'];
if (this.myUsername === men) {
res.data[i]['you_are_mentioned'] = true;
}
}
}
this.posts.push.apply(this.posts, res.data);
this.posts.push.apply(this.posts, this.parseData(res.data));
this.before_id = res.meta.min_id;
}
console.log('since_id: ' + this.since_id);
@ -112,18 +102,7 @@ export class StreamPage {
}
this.fcaller.then(res => {
if (res.data.length > 0) {
for (var i = 0; i < res.data.length; i++) {
if (res.data[i]['repost_of']) {
res.data[i] = res.data[i]['repost_of']
}
for (var j = 0; j < res.data[i]['content']['entities']['mentions'].length; j++) {
var men = res.data[i]['content']['entities']['mentions'][j]['text'];
if (this.myUsername === men) {
res.data[i]['you_are_mentioned'] = true;
}
}
}
Array.prototype.unshift.apply(this.posts, res.data);
Array.prototype.unshift.apply(this.posts, this.parseData(res.data));
this.since_id = res.meta.max_id;
}
console.log('since_id: ' + this.since_id);
@ -136,25 +115,7 @@ export class StreamPage {
fetchPosts() {
this.fetcher({include_raw: 1, include_reposted_by: 1, count: 40}).then(res => {
for (var i = 0; i < res.data.length; i++) {
if (res.data[i]['repost_of']) {
res.data[i] = res.data[i]['repost_of']
var reposted_by_string = "";
for (var j = 0; j < res.data[i]['reposted_by'].length; j++) {
reposted_by_string = reposted_by_string + res.data[i]['reposted_by'][j]['username'] + ", ";
}
// res.data[i]['reposted_by_string'] = "Reposted by: " + reposted_by_string;
}
if (res.data[i].content) {
for (var j = 0; j < res.data[i]['content']['entities']['mentions'].length; j++) {
var men = res.data[i]['content']['entities']['mentions'][j]['text'];
if (this.myUsername === men) {
res.data[i]['you_are_mentioned'] = true;
}
}
}
}
this.posts = res.data;
this.posts = this.parseData(res.data);
this.since_id = res.meta.max_id;
this.before_id = res.meta.min_id;
console.log('since_id: ' + this.since_id);
@ -164,6 +125,32 @@ export class StreamPage {
});
}
parseData(data) {
var pdata = [];
for (var i = 0; i < data.length; i++) {
if (!data[i].is_deleted) {
if (data[i]['repost_of']) {
data[i] = data[i]['repost_of']
var reposted_by_string = "";
for (var j = 0; j < data[i]['reposted_by'].length; j++) {
reposted_by_string = reposted_by_string + data[i]['reposted_by'][j]['username'] + ", ";
}
// data[i]['reposted_by_string'] = "Reposted by: " + reposted_by_string;
}
if (data[i].content) {
for (var j = 0; j < data[i]['content']['entities']['mentions'].length; j++) {
var men = data[i]['content']['entities']['mentions'][j]['text'];
if (this.myUsername === men) {
data[i]['you_are_mentioned'] = true;
}
}
}
pdata.push(data[i]);
}
}
return pdata;
}
fetchThread(threadid) {
pnut.thread(threadid, {include_raw: 1, count: 140}).then(res => {
this.navCtrl.push(ThreadPage, {posts: res.data});