2 Commits 3fce74fc00 ... ae23cdc966

Author SHA1 Message Date
  rohit.gowda ae23cdc966 New apk with proper working of Twitter and Firebase API, Public Tweets loading properly 4 years ago
  rohit.gowda 1c67e30baa Work around to fix rate limit exceeded error 4 years ago

BIN
app/apk/hybrid-osn-encryption.apk


+ 3 - 7
app/src/app/app.html

@@ -4,12 +4,10 @@
       <ion-title>Menu</ion-title>
     </ion-toolbar>
   </ion-header>
-
   <ion-content>
-    <div class="user-info" *ngIf="user" (click)="showProfile(user.id)" menuClose>
+    <div class="user-info" *ngIf="user" (click)="showProfile(user.id_str)" menuClose>
       <div class="user-banner" [style.background]="'url('+ banner +')'">
-        <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px"
-          viewBox="0 0 300 100" xml:space="preserve" width="100%" class="svg-triangle">
+        <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 300 100" xml:space="preserve" width="100%" class="svg-triangle">
           <polygon points="0,75  0,100 300,100 300,99" fill="#FFFFFF" />
         </svg>
         <img src="{{ user.profile_image_url_https | highResolution }}" alt="User" class="user-avatar">
@@ -27,8 +25,6 @@
       </button>
     </ion-list>
   </ion-content>
-
 </ion-menu>
-
 <!-- Disable swipe-to-go-back because it's poor UX to combine STGB with side menus -->
-<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
+<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>

+ 5 - 5
app/src/pages/home/home.ts

@@ -19,6 +19,7 @@ import { FeedProvider } from "../../providers/feed/feed";
 export class HomePage {
   menuController: MenuController;
   tweets;
+  cachedTweets=[];
   privateTweet:boolean = false;
   public color = 'primary';
 
@@ -56,6 +57,7 @@ export class HomePage {
         this.alertCtrl.create(alertText).present()
       })
       .then(() => loading.dismiss());
+     
   }
 
   doRefresh(refresher: Refresher) {
@@ -83,6 +85,7 @@ export class HomePage {
   }
 
   get privateTweets() {
+    Object.assign(this.cachedTweets ,this.tweets);
     return this.tweets.filter(tweet => tweet.private_tweet);
   }
 
@@ -119,11 +122,8 @@ export class HomePage {
 
     else{
       this.color = 'white';
-      this.feed
-      .loadHomeTimeline()
-      .then(tweets => (this.tweets = tweets))
-      .catch(err => console.error(err))
-      .then(() => loading.dismiss());
+      this.tweets =this.cachedTweets;
+      loading.dismiss();
     }
     
   }

+ 2 - 5
app/src/pages/settings/settings.html

@@ -6,7 +6,6 @@
     <ion-title>Settings</ion-title>
   </ion-navbar>
 </ion-header>
-
 <ion-content padding>
   <ion-card>
     <ion-card-header>Keywords for Private Mode</ion-card-header>
@@ -16,14 +15,13 @@
       <ion-textarea [(ngModel)]="keywords"></ion-textarea>
     </ion-card-content>
   </ion-card>
-
   <ion-card>
     <ion-card-header>Encryption</ion-card-header>
     <ion-card-content>
       <p>To protect your privacy, all data send to the P2P network will be encrypted. Therefore you need to enter or
         generate
         a pair of keys. If you run the app on multiple devices, please enter everywhere the same pair of keys.</p>
-      <ion-label color="primary" stacked>Enter your email address:</ion-label>
+      <ion-label color="danger" stacked>Enter your email address:</ion-label>
       <ion-input [(ngModel)]="email" type="email" required></ion-input>
       <button ion-button block (click)="generateKeys()">Generate keys</button>
       <ion-label color="primary" stacked>Private Key:</ion-label>
@@ -35,6 +33,5 @@
       <button ion-button block (click)="exportPrivateKey()">Export private key</button>
     </ion-card-content>
   </ion-card>
-
   <button ion-button block (click)="save()">Save settings</button>
-</ion-content>
+</ion-content>

+ 31 - 7
app/src/pages/settings/settings.ts

@@ -48,6 +48,7 @@ export class SettingsPage {
 
   generateKeys() {
     if (!this.email) {
+      this.createAlert("Blank email address", "Please enter a valid email address to generate key pair");
       return;
     } else {
       this.storage.set("email", this.email);
@@ -86,13 +87,18 @@ export class SettingsPage {
 
 
   save() {
-    this.storage.set("publicKey", this.publicKey);
-    this.storage.set("privateKey", this.privateKey);
-    this.storage.set("keyid", this.keyid);
-    this.storage.set("revocationCert", this.revocationCertificate);
-    this.storage.set("keywords", this.keywords ? this.keywords.trim() : "");
-    this.showToast("Successfully saved!");
-    this.publishPrivateKey();
+    if (this.publicKey || this.privateKey) {
+      this.storage.set("publicKey", this.publicKey);
+      this.storage.set("privateKey", this.privateKey);
+      this.storage.set("keyid", this.keyid);
+      this.storage.set("revocationCert", this.revocationCertificate);
+      this.storage.set("keywords", this.keywords ? this.keywords.trim() : "");
+      this.showToast("Successfully saved!");
+      this.publishPrivateKey();
+    }
+    else{
+      this.createAlert("No Keys","No keys to save!");
+    }
   }
 
   async publishPublicKey() {
@@ -134,4 +140,22 @@ export class SettingsPage {
     });
     toast.present();
   }
+
+  private createAlert(title,subtitle){
+            const newAlert = this.alertCtrl.create({
+          title: title,
+          subTitle: subtitle,
+          buttons: [{
+              text: "No",
+              role: "cancel"
+            },
+            {
+              text: "ok",
+            }
+          ]
+        });
+
+        newAlert.present();
+        return newAlert;
+  }
 }

+ 1 - 14
app/src/pages/write-tweet/write-tweet.ts

@@ -65,19 +65,6 @@ export class WriteTweetPage {
     this.addValidators();
    }
 
-   private async testPvtKeySaveFlow(){
-    console.log("saving pvt keys");
-    let a = await this.storage.get("privateKey");
-    const privKeyObj = (await openpgp.key.readArmored(a)).keys[0];
-
-    //retireve private key from Gun
-    let user = await  this.storage.get("userId");
-    let pvtKey = await this.gun.getPvtKeyHistory(user);
-    //fetch data from ipfs link
-    let keyHistory = await this.ipfs.fetchJson(pvtKey.key);
-
-   }
-
   private async addValidators() {
     const triggerWords = await this.storage.get("keywords");
     const validators = [
@@ -154,7 +141,7 @@ export class WriteTweetPage {
         (await this.cryptoUtils.isPublicKeyPublished())
       ) {
         loading.setContent("Publish private tweet...");
-        let result = await this.tweetPrivate();
+        await this.tweetPrivate();
 
       } else {
         loading.dismiss();

+ 14 - 0
app/src/providers/auth/auth.ts

@@ -40,12 +40,24 @@ export class AuthProvider {
       .then(() => firebase.auth().getRedirectResult())
       .then(this.setKeys)
       .then(() => this.twitter.initApi());
+
+  }
+
+  getCurrentUser(){
+    return firebase.auth().currentUser;
   }
 
   /**
    * Logs the user out by deleting session data
    */
   logout() {
+    firebase.auth().signOut().then(function() {
+  // Sign-out successful.
+    console.log("user signed out successful");
+    }, function(error) {
+      // An error happened.
+        console.log("UNABLE TO sign user out:",error);
+    });
     this.storage.clear();
   }
 
@@ -55,6 +67,7 @@ export class AuthProvider {
   async isLoggedIn() {
     let accessToken = await this.storage.get("accessTokenKey");
     let accessTokenKey = await this.storage.get("accessTokenSecret");
+    console.log("userid is:",this.storage.get( "userId"));
     return accessToken && accessTokenKey;
   }
 
@@ -62,6 +75,7 @@ export class AuthProvider {
    * Saves acces token and user id to locale storage
    */
   setKeys = async result => {
+    console.log("SETTING KEYS HERE NOW",result);
     await this.storage.set(
       "accessTokenKey",
       result["credential"]["accessToken"]

+ 2 - 2
app/src/providers/crypto/crypto.ts

@@ -50,7 +50,7 @@ export class CryptoProvider {
     }
 
     if(privateKeyHistory){
-      // Ecnrypt key history
+      // Encrypt key history
       const encryptedPrivateKeyHistory = JSON.stringify(privateKeyHistory);
 
       // Publish updated key history...
@@ -66,7 +66,7 @@ export class CryptoProvider {
   private async getKeyHistory(userId: string) {
     //get private key history from gun
     let link = await this.gun.getPvtKeyHistory(userId);
-    // Fetch public key history
+    // Fetch Private key history
     if (link) {
       const encryptedKeyHistory = await this.ipfs.fetchJson(link.key);
       // Decrypt key history

+ 1 - 0
app/src/providers/feed/feed.ts

@@ -72,6 +72,7 @@ export class FeedProvider {
    */
   public async loadHomeTimeline(oldestPublicTweet ? , oldestPrivateTweet ? ) {
     // Fetch tweets from Twitter
+    console.log("loading hometimeline");
     const maxId = oldestPublicTweet ? oldestPublicTweet["id_str"] : undefined;
     let tweets = await this.twitter.fetchHomeFeed(maxId);
     tweets = tweets.filter(tweet => tweet.id_str != maxId);

+ 6 - 3
app/src/providers/pgp-key-server/pgp-key-server.ts

@@ -53,8 +53,6 @@ export class PgpKeyServerProvider {
       }
 
     } 
-    
-
 
   /**
    * Encrypt text with RSA
@@ -64,6 +62,8 @@ export class PgpKeyServerProvider {
   public async encrypt(plainText) {
     if (!this.pk) { console.log("this.pk is empty"); return; }
     console.log("this.pk",this.pk);
+     this.pk = this.pk.filter(pk => pk != undefined);
+     console.log("sanitized this.pk",this.pk);
     const options = {
       message: openpgp.message.fromText(plainText), // input as Message object
       publicKeys: await Promise.all(this.pk), // for encryption
@@ -73,7 +73,6 @@ export class PgpKeyServerProvider {
   }
 
   public async decrypt(encrypted: string, privKeyObj) {
-    
     const options2 = {
       message: await openpgp.message.readArmored(encrypted), // parse armored message
       privateKeys: [privKeyObj] // for decryption
@@ -119,4 +118,8 @@ export class PgpKeyServerProvider {
       return key;
   }
 
+  async clearStoredKeys(){
+    this.pk=[];
+  }
+
 }

+ 7 - 8
app/src/providers/twitter-api/twitter-api.ts

@@ -2,12 +2,13 @@ import { Injectable } from "@angular/core";
 import { HttpClient } from "@angular/common/http";
 import { Storage } from "@ionic/storage";
 import Twit from "twit";
+import { PgpKeyServerProvider } from "../../providers/pgp-key-server/pgp-key-server";
 
 @Injectable()
 export class TwitterApiProvider {
   client: Twit;
 
-  constructor(public http: HttpClient, private storage: Storage) {
+  constructor(public http: HttpClient, private storage: Storage, private openpgp: PgpKeyServerProvider,) {
     this.initApi();
   }
 
@@ -15,19 +16,17 @@ export class TwitterApiProvider {
    * initialize Twitter API provider
    */
   public async initApi() {
-    console.log('initAPi iis initting');
     const access_token_key = await this.storage.get("accessTokenKey");
     const access_token_secret = await this.storage.get("accessTokenSecret");
-    console.log('inside twitter initapi access_token_key:', access_token_key, 'access_token_secret', access_token_secret);
-    if (1) {
+    if (access_token_key && access_token_secret) {
       this.client = new Twit({
         consumer_key: "ewAyFOepelB1Dgczl7LReD3pN",
         consumer_secret: "xblu59EZCTrNnW5waDvPjkpaiothQBjDCaJlLaxuezfIdol9Ot",
-        access_token: "1205934370546241541-Ma5zbQIMPTVnbRIYTCaUGgpQnqwApu",
-        access_token_secret: "mnCbVPV0IuQ8UeRCzZSfM6qnn29m41tkAjXVHTBpySP5i",
+        access_token: access_token_key,
+        access_token_secret: access_token_secret,
         timeout_ms: 60 * 1000 // optional HTTP request timeout to apply to all requests.
       });
-      console.log('new twit client created successfully');
+     await  this.openpgp.clearStoredKeys();
     } else {
       console.error(
         "Access Token Key and Secret not set. Creating Twit-client not possible."
@@ -41,7 +40,6 @@ export class TwitterApiProvider {
    * @param maxId tweet id
    */
   public async fetchHomeFeed(maxId ? ) {
-    console.log('fetchine home feed', this.client);
     const res = await this.client.get("statuses/home_timeline", {
       count: 20,
       include_entities: true,
@@ -191,6 +189,7 @@ export class TwitterApiProvider {
 
       cursor = res.data["next_cursor"];
       friends = friends.concat(res.data["users"]);
+      console.log("friends are:",friends);
     }
 
     return friends;