| |
@@ -11,24 +11,27 @@
|
| |
See http://ionicframework.com/docs/v2/components/#navigation for more info on
|
| |
Ionic pages and navigation.
|
| |
*/
|
| |
+ export interface Post {
|
| |
+ link:string
|
| |
+ content:string,
|
| |
+ origin:string,
|
| |
+ date: Date
|
| |
+ }
|
| |
@Component({
|
| |
templateUrl: 'social.html',
|
| |
providers: [FB, Tw],
|
| |
})
|
| |
export class SocialPage {
|
| |
|
| |
- // TODO: Refactor, we are not supposed to use `any`, rather, ww should define an
|
| |
+ // TODO: Refactor, we are not supposed to use `any`, rather, we should define an
|
| |
// interface Post { content:string, date:Date }
|
| |
- private posts:Array<any>;
|
| |
- private tweets:Array<any>;
|
| |
- private updates:Array<any>;
|
| |
+ private posts:Post[];
|
| |
+
|
| |
private USER:any;
|
| |
|
| |
- constructor(private browser:Browser, private fb:FB, private tw:Tw,
|
| |
+ constructor(private browser:Browser, private fb:FB, private twitter:Tw,
|
| |
private socialSharing:SocialSharing) {
|
| |
this.posts = [];
|
| |
- this.tweets = [];
|
| |
- this.updates = [];
|
| |
|
| |
this.USER = {
|
| |
FB: 'fedoraqa',
|
| |
@@ -40,25 +43,13 @@
|
| |
this.updateUpdates();
|
| |
}
|
| |
|
| |
- updateUpdates() {
|
| |
- this.fb
|
| |
- .getPagePosts(this.USER.FB)
|
| |
- .then((posts:Array<any>) => {
|
| |
- this.posts = posts;
|
| |
- this.mergeUpdates();
|
| |
- }).catch((err) => console.log(err + "kanika"));
|
| |
-
|
| |
- this.tw
|
| |
- .getTimelineTweets(this.USER.TW)
|
| |
- .then((tweets:Array<any>) => {
|
| |
- this.tweets = tweets;
|
| |
- this.mergeUpdates();
|
| |
- }).catch((err) => console.log(err));
|
| |
- }
|
| |
+ async updateUpdates() {
|
| |
+ const posts = await Promise.all<Post[],Post[]>([
|
| |
+ this.fb.getPagePosts(this.USER.FB),
|
| |
+ this.twitter.getTimelineTweets(this.USER.TW)
|
| |
+ ]);
|
| |
|
| |
- mergeUpdates() {
|
| |
- // TODO: Merge as per ascending order of timestamps?
|
| |
- this.updates = [ ...this.posts, ...this.tweets ];
|
| |
+ this.posts = [...posts[0], ...posts[1]].sort((a:Post,b:Post) => b.date.getTime() - a.date.getTime() );
|
| |
}
|
| |
|
| |
openUpdate(event) {
|
| |
When clubbing the posts from different sources, we lose the chronological order of the posts. We now sort the
post
array after fetching posts from all the sources to restore the sorted orderCloses #40
Blocked by #55 , #57