|
@@ -1,10 +1,10 @@
|
|
import { Injectable } from "@angular/core";
|
|
import { Injectable } from "@angular/core";
|
|
import { Storage } from "@ionic/storage";
|
|
import { Storage } from "@ionic/storage";
|
|
-import { Platform } from 'ionic-angular';
|
|
|
|
|
|
+import { Platform } from 'ionic-angular';
|
|
import { File } from '@ionic-native/file';
|
|
import { File } from '@ionic-native/file';
|
|
import { HttpClient } from "@angular/common/http";
|
|
import { HttpClient } from "@angular/common/http";
|
|
import * as tweets from './tweet.json';
|
|
import * as tweets from './tweet.json';
|
|
-declare var cordova:any;
|
|
|
|
|
|
+declare var cordova: any;
|
|
|
|
|
|
@Injectable()
|
|
@Injectable()
|
|
export class MockProvider {
|
|
export class MockProvider {
|
|
@@ -12,17 +12,17 @@ export class MockProvider {
|
|
userId: string;
|
|
userId: string;
|
|
mockTweets;
|
|
mockTweets;
|
|
result;
|
|
result;
|
|
- fileRead:Boolean;
|
|
|
|
|
|
+ fileRead: Boolean;
|
|
|
|
|
|
-constructor(
|
|
|
|
|
|
+ constructor(
|
|
private storage: Storage,
|
|
private storage: Storage,
|
|
private file: File,
|
|
private file: File,
|
|
public http: HttpClient,
|
|
public http: HttpClient,
|
|
private platform: Platform
|
|
private platform: Platform
|
|
) {
|
|
) {
|
|
- console.log('tweets are:',tweets);
|
|
|
|
|
|
+ console.log('tweets are:', tweets);
|
|
this.fileRead = false;
|
|
this.fileRead = false;
|
|
- this.mockTweets = [...tweets];
|
|
|
|
|
|
+ this.mockTweets = [...tweets];
|
|
console.log(' this.mockTweets are:', this.mockTweets);
|
|
console.log(' this.mockTweets are:', this.mockTweets);
|
|
|
|
|
|
this.storage.get("userId").then(userId => (this.userId = userId));
|
|
this.storage.get("userId").then(userId => (this.userId = userId));
|
|
@@ -37,10 +37,9 @@ constructor(
|
|
*/
|
|
*/
|
|
public async loadUserTimeline(
|
|
public async loadUserTimeline(
|
|
userId,
|
|
userId,
|
|
- oldestPublicTweet?,
|
|
|
|
- oldestPrivateTweet?
|
|
|
|
- )
|
|
|
|
- {
|
|
|
|
|
|
+ oldestPublicTweet ? ,
|
|
|
|
+ oldestPrivateTweet ?
|
|
|
|
+ ) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -50,63 +49,68 @@ constructor(
|
|
* @param oldestPublicTweet oldest public tweet
|
|
* @param oldestPublicTweet oldest public tweet
|
|
* @param oldestPrivateTweet oldest private tweet
|
|
* @param oldestPrivateTweet oldest private tweet
|
|
*/
|
|
*/
|
|
- public async loadHomeTimeline(oldestPublicTweet?, oldestPrivateTweet?) {
|
|
|
|
|
|
+ public async loadHomeTimeline(oldestPublicTweet ? , oldestPrivateTweet ? ) {
|
|
console.log('hometime line called in mockprovider');
|
|
console.log('hometime line called in mockprovider');
|
|
this.readFile().then(tweets => {
|
|
this.readFile().then(tweets => {
|
|
- console.log('new mocktweets after replace',this.mockTweets);
|
|
|
|
|
|
+ console.log('new mocktweets after replace', this.mockTweets);
|
|
})
|
|
})
|
|
- .catch(err => console.error('error in readfile',err));
|
|
|
|
|
|
+ .catch(err => console.error('error in readfile', err));
|
|
return this.mockTweets;
|
|
return this.mockTweets;
|
|
}
|
|
}
|
|
|
|
|
|
- public async replyTweet(){}
|
|
|
|
|
|
+ public async replyTweet() {}
|
|
|
|
+ public async countfav() {}
|
|
|
|
+
|
|
|
|
|
|
- public writeTweet(twt:string){
|
|
|
|
|
|
+ public writeTweet(twt: string , isPrivate: boolean) {
|
|
// console.log('inside writetweet',this.mockTweets[0]);
|
|
// console.log('inside writetweet',this.mockTweets[0]);
|
|
// console.log('inside writetweet obj is:',this.mockTweets[0].full_text);
|
|
// console.log('inside writetweet obj is:',this.mockTweets[0].full_text);
|
|
let newTweet = Object.assign({}, this.mockTweets[0]);
|
|
let newTweet = Object.assign({}, this.mockTweets[0]);
|
|
newTweet.full_text = twt;
|
|
newTweet.full_text = twt;
|
|
- console.log('new tweet ',newTweet);
|
|
|
|
|
|
+ if(isPrivate){
|
|
|
|
+ newTweet.private_tweet = true;
|
|
|
|
+ }
|
|
|
|
+ console.log('new tweet ', newTweet);
|
|
this.mockTweets.push(newTweet);
|
|
this.mockTweets.push(newTweet);
|
|
this.writefile(this.mockTweets);
|
|
this.writefile(this.mockTweets);
|
|
}
|
|
}
|
|
|
|
|
|
- public async writefile(mocktweet){
|
|
|
|
- await this.platform.ready()
|
|
|
|
- .then(_ => console.log('Device ready.'));
|
|
|
|
- //check if file exists
|
|
|
|
- this.result = this.file.writeFile(this.file.dataDirectory, 'twets.json', JSON.stringify(mocktweet), {replace: true, append:false});
|
|
|
|
- console.log("writing the file:",this.result);
|
|
|
|
- console.log('Reading the file:',this.readFile());
|
|
|
|
|
|
+ public async writefile(mocktweet) {
|
|
|
|
+ await this.platform.ready()
|
|
|
|
+ .then(_ => console.log('Device ready.'));
|
|
|
|
+ //check if file exists
|
|
|
|
+ this.result = this.file.writeFile(this.file.dataDirectory, 'twets.json', JSON.stringify(mocktweet), { replace: true, append: false });
|
|
|
|
+ console.log("writing the file:", this.result);
|
|
|
|
+ console.log('Reading the file:', this.readFile());
|
|
}
|
|
}
|
|
|
|
|
|
public async readFile() {
|
|
public async readFile() {
|
|
- var readTweets:[];
|
|
|
|
- console.log('in readfile',this.mockTweets);
|
|
|
|
|
|
+ var readTweets: [];
|
|
|
|
+ console.log('in readfile', this.mockTweets);
|
|
this.file.checkFile(this.file.dataDirectory, 'twets.json')
|
|
this.file.checkFile(this.file.dataDirectory, 'twets.json')
|
|
- .then(() => {
|
|
|
|
- console.log('file exists');
|
|
|
|
- this.file.readAsText(this.file.dataDirectory, 'twets.json')
|
|
|
|
- .then(data=>{
|
|
|
|
- readTweets = JSON.parse(data);
|
|
|
|
- if(!this.fileRead){
|
|
|
|
- // readTweets.forEach(el=>this.mockTweets.push(el));
|
|
|
|
- this.mockTweets = [...readTweets];
|
|
|
|
- this.fileRead = true;
|
|
|
|
- }
|
|
|
|
- console.log('file is: ',this.mockTweets);
|
|
|
|
- })
|
|
|
|
- .catch(err => console.error('error in reading file',err));
|
|
|
|
- })
|
|
|
|
- .catch(err => {
|
|
|
|
- console.error('File doesnt exist',err);
|
|
|
|
- this.file.writeFile(this.file.dataDirectory, 'twets.json', JSON.stringify(this.mockTweets), {replace: true});
|
|
|
|
- });
|
|
|
|
|
|
+ .then(() => {
|
|
|
|
+ console.log('file exists');
|
|
|
|
+ this.file.readAsText(this.file.dataDirectory, 'twets.json')
|
|
|
|
+ .then(data => {
|
|
|
|
+ readTweets = JSON.parse(data);
|
|
|
|
+ if (!this.fileRead) {
|
|
|
|
+ // readTweets.forEach(el=>this.mockTweets.push(el));
|
|
|
|
+ this.mockTweets = [...readTweets];
|
|
|
|
+ this.fileRead = true;
|
|
|
|
+ }
|
|
|
|
+ console.log('file is: ', this.mockTweets);
|
|
|
|
+ })
|
|
|
|
+ .catch(err => console.error('error in reading file', err));
|
|
|
|
+ })
|
|
|
|
+ .catch(err => {
|
|
|
|
+ console.error('File doesnt exist', err);
|
|
|
|
+ this.file.writeFile(this.file.dataDirectory, 'twets.json', JSON.stringify(this.mockTweets), { replace: true });
|
|
|
|
+ });
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
private async fetchPrivateTweets(privateTweetsData: object[]) {
|
|
private async fetchPrivateTweets(privateTweetsData: object[]) {
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|