2018-11-13 00:34:38 +00:00
|
|
|
import { Component } from '@angular/core';
|
|
|
|
import { NavController, NavParams } from 'ionic-angular';
|
2018-11-19 00:39:53 +00:00
|
|
|
import { UserListPage } from '../user-list/user-list';
|
2018-11-13 00:34:38 +00:00
|
|
|
|
2018-11-18 06:34:32 +00:00
|
|
|
import * as pnut from 'pnut-butter';
|
|
|
|
|
2018-11-13 00:34:38 +00:00
|
|
|
/**
|
|
|
|
* Generated class for the ProfilePage page.
|
|
|
|
*
|
|
|
|
* See https://ionicframework.com/docs/components/#navigation for more info on
|
|
|
|
* Ionic pages and navigation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'page-profile',
|
|
|
|
templateUrl: 'profile.html',
|
|
|
|
})
|
|
|
|
export class ProfilePage {
|
|
|
|
|
|
|
|
private user: any;
|
2018-11-18 06:34:32 +00:00
|
|
|
private posts: Array<Object> = [];
|
|
|
|
private bookmarks: Array<Object> = [];
|
|
|
|
private before_id_post: string;
|
|
|
|
private before_id_stars: string;
|
|
|
|
private myUsername: string;
|
2018-11-19 00:39:53 +00:00
|
|
|
public activeTab: string = 'posts';
|
2018-11-13 00:34:38 +00:00
|
|
|
|
|
|
|
constructor(public navCtrl: NavController, public navParams: NavParams) {
|
|
|
|
this.user = this.navParams.data.user;
|
2018-11-18 06:34:32 +00:00
|
|
|
this.myUsername = this.navParams.data.me;
|
2018-11-13 00:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ionViewDidLoad() {
|
|
|
|
console.log('ionViewDidLoad ProfilePage');
|
2018-11-19 00:39:53 +00:00
|
|
|
// console.log(JSON.stringify(this.user));
|
|
|
|
// console.log('-----');
|
2018-11-18 06:34:32 +00:00
|
|
|
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 = "";
|
2018-11-19 00:39:53 +00:00
|
|
|
let rplen = 0;
|
|
|
|
if (typeof data[i]['reposted_by'] !== "undefined") {
|
|
|
|
rplen = data[i]['reposted_by'].length;
|
|
|
|
}
|
|
|
|
for (var j = 0; j < rplen; j++) {
|
2018-11-18 06:34:32 +00:00
|
|
|
reposted_by_string = reposted_by_string + data[i]['reposted_by'][j]['username'] + ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
2018-11-13 00:34:38 +00:00
|
|
|
}
|
|
|
|
|
2018-11-19 00:39:53 +00:00
|
|
|
showUserList(list) {
|
|
|
|
this.navCtrl.push(UserListPage, {
|
|
|
|
userid: this.user.id,
|
|
|
|
username: this.myUsername,
|
|
|
|
list: list});
|
|
|
|
}
|
|
|
|
|
2018-11-13 00:34:38 +00:00
|
|
|
}
|