|
@@ -3,7 +3,8 @@ import {
|
|
|
IonicPage,
|
|
|
NavController,
|
|
|
NavParams,
|
|
|
- LoadingController
|
|
|
+ LoadingController,
|
|
|
+ AlertController
|
|
|
} from "ionic-angular";
|
|
|
import { FormBuilder, Validators, FormGroup } from "@angular/forms";
|
|
|
import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";
|
|
@@ -11,6 +12,7 @@ import { Storage } from "@ionic/storage";
|
|
|
import { P2pStorageIpfsProvider } from "../../providers/p2p-storage-ipfs/p2p-storage-ipfs";
|
|
|
import { P2pDatabaseGunProvider } from "../../providers/p2p-database-gun/p2p-database-gun";
|
|
|
import twittertext from "twitter-text";
|
|
|
+import { CryptoProvider } from "../../providers/crypto/crypto";
|
|
|
|
|
|
@IonicPage()
|
|
|
@Component({
|
|
@@ -32,7 +34,9 @@ export class WriteTweetPage {
|
|
|
private loadingCtrl: LoadingController,
|
|
|
private storage: Storage,
|
|
|
private ipfs: P2pStorageIpfsProvider,
|
|
|
- private gun: P2pDatabaseGunProvider
|
|
|
+ private gun: P2pDatabaseGunProvider,
|
|
|
+ private cryptoUtils: CryptoProvider,
|
|
|
+ private alertCtrl: AlertController
|
|
|
) {
|
|
|
this.retweetId = this.navParams.get("tweetId");
|
|
|
this.replyToStatusId = this.navParams.get("replyToStatus");
|
|
@@ -64,16 +68,21 @@ export class WriteTweetPage {
|
|
|
loading.present();
|
|
|
|
|
|
if (this.tweet.value.p2p) {
|
|
|
- const tweet = await this.buildPrivateTweet();
|
|
|
- const res = await this.ipfs.storeTweet(tweet);
|
|
|
-
|
|
|
- this.gun.storeLastTweetHashForUser(
|
|
|
- tweet.user_id,
|
|
|
- res["Hash"],
|
|
|
- tweet.created_at
|
|
|
- );
|
|
|
-
|
|
|
- this.gun.publishHashtags(tweet.entities.hashtags);
|
|
|
+ if (
|
|
|
+ (await this.cryptoUtils.isPrivateKeySet()) &&
|
|
|
+ (await this.cryptoUtils.isPublicKeyPublished())
|
|
|
+ ) {
|
|
|
+ await this.tweetPrivate();
|
|
|
+ } else {
|
|
|
+ const alert = this.alertCtrl.create({
|
|
|
+ title: "Oooops...",
|
|
|
+ message:
|
|
|
+ "Please verify that you have set a private and public key in the settings and that your latest public key was published."
|
|
|
+ });
|
|
|
+ loading.dismiss();
|
|
|
+ alert.present();
|
|
|
+ return;
|
|
|
+ }
|
|
|
} else {
|
|
|
await this.twitter.tweet(
|
|
|
this.tweet.value["text"],
|
|
@@ -86,6 +95,19 @@ export class WriteTweetPage {
|
|
|
this.navCtrl.pop();
|
|
|
}
|
|
|
|
|
|
+ private async tweetPrivate() {
|
|
|
+ const tweet = await this.buildPrivateTweet();
|
|
|
+ const res = await this.ipfs.storeTweet(tweet);
|
|
|
+
|
|
|
+ this.gun.storeLastTweetHashForUser(
|
|
|
+ tweet.user_id,
|
|
|
+ res["Hash"],
|
|
|
+ tweet.created_at
|
|
|
+ );
|
|
|
+
|
|
|
+ this.gun.publishHashtags(tweet.entities.hashtags);
|
|
|
+ }
|
|
|
+
|
|
|
private async buildPrivateTweet() {
|
|
|
const status = this.tweet.value["text"].trim();
|
|
|
const entities = await this.getEntities(status);
|