12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import { Component } from "@angular/core";
- import {
- IonicPage,
- NavController,
- NavParams,
- LoadingController
- } from "ionic-angular";
- import { FormBuilder, Validators, FormGroup } from "@angular/forms";
- import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";
- 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";
- /**
- * Generated class for the WriteTweetPage page.
- *
- * See https://ionicframework.com/docs/components/#navigation for more info on
- * Ionic pages and navigation.
- */
- @IonicPage()
- @Component({
- selector: "page-write-tweet",
- templateUrl: "write-tweet.html"
- })
- export class WriteTweetPage {
- tweet: FormGroup;
- constructor(
- public navCtrl: NavController,
- public navParams: NavParams,
- private formBuilder: FormBuilder,
- private twitter: TwitterApiProvider,
- private loadingCtrl: LoadingController,
- private storage: Storage,
- private ipfs: P2pStorageIpfsProvider,
- private gun: P2pDatabaseGunProvider
- ) {
- this.tweet = this.formBuilder.group({
- text: ["", Validators.maxLength(140)],
- p2p: [false]
- });
- }
- ionViewDidLoad() {}
- get tweetCharProgress() {
- let progress = 1 - this.tweet.value["text"].length / 140;
- let radius = 8;
- let circumference = Math.PI * radius * 2;
- return progress * circumference;
- }
- async submitTweet() {
- let loading = this.loadingCtrl.create();
- loading.present();
- if (this.tweet.value.p2p) {
- const tweet = await this.buildPrivateTweet();
- const res = await this.ipfs.storeTweet(tweet);
- this.gun.storeLastTweetHashForUser("username", res["Hash"]);
- } else {
- await this.twitter.tweet(this.tweet.value["text"]);
- }
- loading.dismiss();
- this.navCtrl.pop();
- }
- private async buildPrivateTweet() {
- return {
- full_text: this.tweet.value["text"].trim(),
- user_id: await this.storage.get("userId"),
- created_at: Date.now(),
- private_tweet: true,
- entities: {}
- };
- }
- }
|