|
@@ -10,6 +10,7 @@ import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";
|
|
|
import { HttpClient } from "@angular/common/http";
|
|
|
import { Storage } from "@ionic/storage";
|
|
|
import Gun from "gun";
|
|
|
+import { P2pStorageIpfsProvider } from "../../providers/p2p-storage-ipfs/p2p-storage-ipfs";
|
|
|
|
|
|
/**
|
|
|
* Generated class for the WriteTweetPage page.
|
|
@@ -34,7 +35,8 @@ export class WriteTweetPage {
|
|
|
private twitter: TwitterApiProvider,
|
|
|
private loadingCtrl: LoadingController,
|
|
|
private http: HttpClient,
|
|
|
- private storage: Storage
|
|
|
+ private storage: Storage,
|
|
|
+ private ipfs: P2pStorageIpfsProvider
|
|
|
) {
|
|
|
this.gun = Gun();
|
|
|
this.tweet = this.formBuilder.group({
|
|
@@ -57,8 +59,9 @@ export class WriteTweetPage {
|
|
|
loading.present();
|
|
|
|
|
|
if (this.tweet.value.p2p) {
|
|
|
- let hash = await this.postToIpfs(this.tweet.value["text"]);
|
|
|
- this.gun.get("username").put({ lastTweet: hash });
|
|
|
+ const tweet = await this.buildPrivateTweet();
|
|
|
+ const res = await this.ipfs.storeTweet(tweet);
|
|
|
+ this.gun.get("username").put({ lastTweet: res["Hash"] });
|
|
|
} else {
|
|
|
await this.twitter.tweet(this.tweet.value["text"]);
|
|
|
}
|
|
@@ -67,20 +70,11 @@ export class WriteTweetPage {
|
|
|
this.navCtrl.pop();
|
|
|
}
|
|
|
|
|
|
- private async postToIpfs(text) {
|
|
|
- let url = "https://ipfs.infura.io:5001/api/v0/add";
|
|
|
-
|
|
|
- let data = {
|
|
|
+ private async buildPrivateTweet() {
|
|
|
+ return {
|
|
|
text: this.tweet.value["text"].trim(),
|
|
|
userId: await this.storage.get("userId"),
|
|
|
timestamp: Date.now()
|
|
|
};
|
|
|
-
|
|
|
- let formData = new FormData();
|
|
|
- formData.append("data", JSON.stringify(data));
|
|
|
-
|
|
|
- let res = await this.http.post(url, formData).toPromise();
|
|
|
- console.log(res["Hash"]);
|
|
|
- return res["Hash"];
|
|
|
}
|
|
|
}
|