From 7e58365dacaa20644f9b6a3d70ce106f7e5d7c07 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Sat, 22 Jul 2017 08:17:35 -0700 Subject: [PATCH] properly exclude deleted posts from the stream #35 --- src/pages/stream/stream.ts | 75 ++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 44 deletions(-) diff --git a/src/pages/stream/stream.ts b/src/pages/stream/stream.ts index 5ecec86..7d6be7a 100644 --- a/src/pages/stream/stream.ts +++ b/src/pages/stream/stream.ts @@ -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});