Browse Source

show private tweet in timeline

Carsten Porth 5 years ago
parent
commit
b3766462ef

+ 1 - 1
app/src/components/tweet-body/tweet-body.html

@@ -1,6 +1,6 @@
 <!-- Generated template for the TweetBodyComponent component -->
 <div>
-  <p [innerHTML]="status | replaceUrls: entities.urls | replaceHashtags: entities.hashtags"></p>
+  <p [innerHTML]="status"></p>
   <img *ngIf="hasPhoto" src="{{ entities.media[0]['media_url_https'] }}" alt="Photo" class="photo">
   <quoted-status *ngIf="data.quoted_status" [data]="data.quoted_status"></quoted-status>
 </div>

+ 2 - 1
app/src/components/tweet-body/tweet-body.ts

@@ -34,7 +34,8 @@ export class TweetBodyComponent {
 
   get hasPhoto() {
     return (
-      this.entities["media"] && this.entities["media"][0]["type"] == "photo"
+      !this.data["private_tweet"] &&
+      (this.entities["media"] && this.entities["media"][0]["type"] == "photo")
     );
   }
 }

+ 1 - 1
app/src/components/tweet/tweet.html

@@ -1,4 +1,4 @@
-<ion-item text-wrap>
+<ion-item text-wrap [class.private]="data.private_tweet">
   <p *ngIf="data.retweeted_status" class="retweet-info">{{ data.user.name }} has retweeted:</p>
   <tweet-header [user]="user" [tweetCreatedAt]="createdAt"></tweet-header>
   <tweet-body [data]="data"></tweet-body>

+ 10 - 6
app/src/components/tweet/tweet.scss

@@ -1,7 +1,11 @@
 tweet {
-  .retweet-info {
-    font-weight: 250;
-    font-size: 10px;
-    margin-bottom: 8px;
-  }
-}
+    .retweet-info {
+        font-weight: 250;
+        font-size: 10px;
+        margin-bottom: 8px;
+    }
+    .private {
+        background: #333;
+        color: #efefef;
+    }
+}

+ 21 - 2
app/src/pages/home/home.ts

@@ -7,6 +7,8 @@ import {
 } from "ionic-angular";
 import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";
 import { WriteTweetPage } from "../write-tweet/write-tweet";
+import { P2pDatabaseGunProvider } from "../../providers/p2p-database-gun/p2p-database-gun";
+import { P2pStorageIpfsProvider } from "../../providers/p2p-storage-ipfs/p2p-storage-ipfs";
 
 @IonicPage()
 @Component({
@@ -20,7 +22,9 @@ export class HomePage {
   constructor(
     public navCtrl: NavController,
     private twitter: TwitterApiProvider,
-    private menuCtrl: MenuController
+    private menuCtrl: MenuController,
+    private gun: P2pDatabaseGunProvider,
+    private ipfs: P2pStorageIpfsProvider
   ) {}
 
   ionViewDidLoad() {
@@ -28,7 +32,17 @@ export class HomePage {
   }
 
   ionViewDidEnter() {
-    this.twitter.fetchHomeFeed().then(res => (this.data = res.data));
+    this.twitter
+      .fetchHomeFeed()
+      .then(res => (this.data = this.data.concat(res.data)));
+    this.gun
+      .getLastTweetFromUser("username")
+      .then(hash => this.ipfs.fetchTweet(hash))
+      .then(tweet => this.addUserObject(tweet))
+      .then(res => {
+        this.data = this.data.concat(res);
+        console.log(this.data, res);
+      });
   }
 
   doRefresh(refresher) {
@@ -51,4 +65,9 @@ export class HomePage {
   writeTweet() {
     this.navCtrl.push(WriteTweetPage);
   }
+
+  private async addUserObject(tweet) {
+    tweet.user = await this.twitter.fetchUser(tweet.user_id);
+    return tweet;
+  }
 }

+ 5 - 3
app/src/pages/write-tweet/write-tweet.ts

@@ -69,9 +69,11 @@ export class WriteTweetPage {
 
   private async buildPrivateTweet() {
     return {
-      text: this.tweet.value["text"].trim(),
-      userId: await this.storage.get("userId"),
-      timestamp: Date.now()
+      full_text: this.tweet.value["text"].trim(),
+      user_id: await this.storage.get("userId"),
+      created_at: Date.now(),
+      private_tweet: true,
+      entities: {}
     };
   }
 }