diff --git a/src/components/post/post.ts b/src/components/post/post.ts index 1206cf5..38fe00c 100644 --- a/src/components/post/post.ts +++ b/src/components/post/post.ts @@ -45,7 +45,7 @@ export class PostComponent { } showProfile(user) { - this.navCtrl.push(ProfilePage, {user: user}); + this.navCtrl.push(ProfilePage, {user: user, me: this.myUsername}); } showReplyPost(postData, repType) { diff --git a/src/pages/profile/profile.html b/src/pages/profile/profile.html index b53d110..3e23216 100644 --- a/src/pages/profile/profile.html +++ b/src/pages/profile/profile.html @@ -13,7 +13,7 @@ - + @@ -26,25 +26,53 @@ -

-


- +
+ - + - + - + - + + + Posts + Stars + + +
+ +
+ + + + + +
+ +
+ + + + + +
+ + + + + +
+
diff --git a/src/pages/profile/profile.ts b/src/pages/profile/profile.ts index af51b5a..e1d7e1c 100644 --- a/src/pages/profile/profile.ts +++ b/src/pages/profile/profile.ts @@ -1,6 +1,8 @@ import { Component } from '@angular/core'; import { NavController, NavParams } from 'ionic-angular'; +import * as pnut from 'pnut-butter'; + /** * Generated class for the ProfilePage page. * @@ -15,13 +17,87 @@ import { NavController, NavParams } from 'ionic-angular'; export class ProfilePage { private user: any; + private posts: Array = []; + private bookmarks: Array = []; + private before_id_post: string; + private before_id_stars: string; + private myUsername: string; constructor(public navCtrl: NavController, public navParams: NavParams) { this.user = this.navParams.data.user; + this.myUsername = this.navParams.data.me; } ionViewDidLoad() { console.log('ionViewDidLoad ProfilePage'); + let params = { + include_deleted: 0, + include_raw: 1, + count: 40 + }; + pnut.postsFrom(this.user.id, params).then(res => { + this.posts = this.parseData(res.data); + this.before_id_post = res.meta.min_id; + }); + pnut.bookmarks(this.user.id, params).then(res => { + this.bookmarks = this.parseData(res.data); + this.before_id_stars = res.meta.min_id; + }); + } + + fetchOlderPosts(infiniteScroll, stream) { + let before_id = this.before_id_post; + let fetcher = pnut.postsFrom; + if (stream === 'bookmarks') { + before_id = this.before_id_stars; + fetcher = pnut.bookmarks; + } + let params = { + include_deleted: 0, + include_raw: 1, + before_id: before_id, + count: 40 + }; + fetcher(this.user.id, params).then(res => { + if (res.data.length > 0) { + if (stream === 'posts') { + this.posts.push.apply(this.posts, this.parseData(res.data)); + this.before_id_post = res.meta.min_id; + } else if (stream === 'bookmarks') { + this.bookmarks.push.apply(this.bookmarks, this.parseData(res.data)); + this.before_id_stars = res.meta.min_id; + } + } + infiniteScroll.complete(); + }).catch(err => { + console.log(err); + }); + } + + 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 k = 0; k < data[i]['content']['entities']['mentions'].length; k++) { + var men = data[i]['content']['entities']['mentions'][k]['text']; + if (this.myUsername === men) { + data[i]['you_are_mentioned'] = true; + } + } + } + pdata.push(data[i]); + } + } + return pdata; } } diff --git a/src/pages/stream/stream.html b/src/pages/stream/stream.html index 22d5c2a..67796d0 100644 --- a/src/pages/stream/stream.html +++ b/src/pages/stream/stream.html @@ -25,89 +25,6 @@ -