Browse Source

document public interfaces

Carsten Porth 3 years ago
parent
commit
60db36673f

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

@@ -27,6 +27,9 @@ export class AuthProvider {
     });
   }
 
+  /**
+   * Performs the login to Twitter
+   */
   login() {
     return firebase
       .auth()
@@ -36,16 +39,25 @@ export class AuthProvider {
       .then(() => this.twitter.initApi());
   }
 
+  /**
+   * Logs the user out by deleting session data
+   */
   logout() {
     this.storage.clear();
   }
 
+  /**
+   * Checks if a user is currently logged in
+   */
   async isLoggedIn() {
     let accessToken = await this.storage.get("accessTokenKey");
     let accessTokenKey = await this.storage.get("accessTokenSecret");
     return accessToken && accessTokenKey;
   }
 
+  /**
+   * Saves acces token and user id to locale storage
+   */
   setKeys = async result => {
     await this.storage.set(
       "accessTokenKey",

+ 35 - 0
app/src/providers/crypto/crypto.ts

@@ -23,6 +23,10 @@ export class CryptoProvider {
     this.ownUserId = await this.storage.get("userId");
   }
 
+  /**
+   * Publishs the public key history with the latest key
+   * @param key key to publish
+   */
   public async publishPublicKey(key: string) {
     let publicKeyHistory = await this.getKeyHistory(this.ownUserId);
 
@@ -115,6 +119,9 @@ export class CryptoProvider {
     return /tweet:\/\/[0-9]+/.test(word);
   }
 
+  /**
+   * Generates a RSA key pair object
+   */
   public async generateRsaKeys() {
     return await crypto.subtle.generateKey(
       {
@@ -128,6 +135,10 @@ export class CryptoProvider {
     );
   }
 
+  /**
+   * extracts the private key from the key object and transforms it to readable text
+   * @param keys key object
+   */
   public async extractPrivateKey(keys): Promise<string> {
     return btoa(
       String.fromCharCode.apply(
@@ -137,6 +148,10 @@ export class CryptoProvider {
     );
   }
 
+  /**
+   * extracts the public key from the key object and transforms it to readable text
+   * @param keys key object
+   */
   public async extractPublicKey(keys): Promise<string> {
     return btoa(
       String.fromCharCode.apply(
@@ -146,6 +161,9 @@ export class CryptoProvider {
     );
   }
 
+  /**
+   * checks if the latest published key is the same as the one saved in app settings
+   */
   public async isPublicKeyPublished(): Promise<boolean> {
     const publicKey = await this.storage.get("publicKey");
     const keyHistory = await this.getKeyHistory(this.ownUserId);
@@ -158,11 +176,19 @@ export class CryptoProvider {
     }
   }
 
+  /**
+   * checks if a private key is already set
+   */
   public async isPrivateKeySet(): Promise<boolean> {
     const privateKey = await this.storage.get("privateKey");
     return privateKey;
   }
 
+  /**
+   * Encrypt text with RSA
+   * @param plainText plain text
+   * @param privateKey private key
+   */
   public encrypt(plainText: string, privateKey: string) {
     const key = new NodeRSA(
       `-----BEGIN PRIVATE KEY-----${privateKey}-----END PRIVATE KEY-----`
@@ -170,6 +196,11 @@ export class CryptoProvider {
     return key.encryptPrivate(plainText, "base64");
   }
 
+  /**
+   * Decrypt secret with RSA
+   * @param encryptedMessage encrypted message
+   * @param publicKey public key
+   */
   public decrypt(encryptedMessage: string, publicKey: string): string {
     const key = new NodeRSA(
       `-----BEGIN PUBLIC KEY-----${publicKey}-----END PUBLIC KEY-----`
@@ -177,6 +208,10 @@ export class CryptoProvider {
     return key.decryptPublic(encryptedMessage).toString();
   }
 
+  /**
+   * Fetches the public key history for a given user id
+   * @param userId user id
+   */
   public async fetchPublicKeyHistoryForUser(userId: string): Promise<object[]> {
     const keyHistory = await this.getKeyHistory(userId);
     return keyHistory["keys"].reverse();

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

@@ -19,6 +19,13 @@ export class FeedProvider {
     this.storage.get("userId").then(userId => (this.userId = userId));
   }
 
+  /**
+   * Retrives the public and private tweets for a user
+   * Since it is loaded in batches of 20 public tweets, public and private tweet are used as reference to load next 20 tweets
+   * @param userId user id
+   * @param oldestPublicTweet oldest public tweet
+   * @param oldestPrivateTweet oldest private tweet
+   */
   public async loadUserTimeline(
     userId,
     oldestPublicTweet?,
@@ -55,6 +62,12 @@ export class FeedProvider {
     }
   }
 
+  /**
+   * Retrieves the home feed for the logged in user
+   * Since it is loaded in batches of 20 public tweets, public and private tweet are used as reference to load next 20 tweets
+   * @param oldestPublicTweet oldest public tweet
+   * @param oldestPrivateTweet oldest private tweet
+   */
   public async loadHomeTimeline(oldestPublicTweet?, oldestPrivateTweet?) {
     // Fetch tweets from Twitter
     const maxId = oldestPublicTweet ? oldestPublicTweet["id_str"] : undefined;

+ 20 - 0
app/src/providers/p2p-database-gun/p2p-database-gun.ts

@@ -35,6 +35,12 @@ export class P2pDatabaseGunProvider {
       .set(hashtags);
   }
 
+  /**
+   * Store the ipfs hash to a private tweet in GUN
+   * @param userId user id
+   * @param hash ipfs hash
+   * @param timestamp timestamp
+   */
   public storeLastTweetHashForUser(userId, hash, timestamp): void {
     const tweet = this.gun
       .get(timestamp)
@@ -47,6 +53,12 @@ export class P2pDatabaseGunProvider {
       .set(tweet);
   }
 
+  /**
+   * Retrieves the ipfs hashes of private tweets for a user in the given time interval
+   * @param userId user id
+   * @param intervalStart interval start timestamp
+   * @param intervalEnd interval end timestamp
+   */
   public async fetchPrivateTweetHashsForUserInInterval(
     userId,
     intervalStart,
@@ -79,6 +91,10 @@ export class P2pDatabaseGunProvider {
     }
   }
 
+  /**
+   * Adds a like to a tweet privately
+   * @param tweetId tweet id
+   */
   public async addLike(tweetId: string) {
     const likeEntry = await this.getLikes(tweetId);
 
@@ -92,6 +108,10 @@ export class P2pDatabaseGunProvider {
       .set(likes);
   }
 
+  /**
+   * Retrieves the private likes for a tweet
+   * @param tweetId tweet id
+   */
   public async getLikes(tweetId: string) {
     const likeEntry = await this.gun
       .get(this.osnPrefix)

+ 20 - 0
app/src/providers/p2p-storage-ipfs/p2p-storage-ipfs.ts

@@ -7,10 +7,18 @@ export class P2pStorageIpfsProvider {
 
   constructor(public http: HttpClient) {}
 
+  /**
+   * Store private tweet on ipfs
+   * @param tweet tweet object
+   */
   public storeTweet(tweet) {
     return this.storeOnIPFS(tweet);
   }
 
+  /**
+   * Store public key history on ipfs
+   * @param publicKeyHistory public key history object
+   */
   public storePublicKey(publicKeyHistory) {
     return this.storeOnIPFS(publicKeyHistory);
   }
@@ -22,6 +30,10 @@ export class P2pStorageIpfsProvider {
     return this.http.post(this.infuraUrl + "add", formData).toPromise();
   }
 
+  /**
+   * fetch data from ipfs for hash
+   * @param hash address hash
+   */
   public async fetchJson(hash: string) {
     const options = {
       params: { arg: hash }
@@ -30,6 +42,10 @@ export class P2pStorageIpfsProvider {
     return await this.http.get(this.infuraUrl + "cat", options).toPromise();
   }
 
+  /**
+   * fetch tweet from ipfs for hash
+   * @param hash address hash
+   */
   public fetchTweet(hash: string): Promise<string> {
     const options = {
       params: { arg: hash }
@@ -38,6 +54,10 @@ export class P2pStorageIpfsProvider {
     return this.http.get<string>(this.infuraUrl + "cat", options).toPromise();
   }
 
+  /**
+   * fetch multiple tweets from ipfs
+   * @param hashs array of hashes
+   */
   public async fetchTweets(hashs: string[]): Promise<string[]> {
     return await Promise.all(hashs.map(hash => this.fetchTweet(hash)));
   }

+ 87 - 0
app/src/providers/twitter-api/twitter-api.ts

@@ -11,6 +11,9 @@ export class TwitterApiProvider {
     this.initApi();
   }
 
+  /**
+   * initialize Twitter API provider
+   */
   public async initApi() {
     const access_token_key = await this.storage.get("accessTokenKey");
     const access_token_secret = await this.storage.get("accessTokenSecret");
@@ -30,6 +33,10 @@ export class TwitterApiProvider {
     }
   }
 
+  /**
+   * fetch home feed in batches of 20 tweets starting at maxId
+   * @param maxId tweet id
+   */
   public async fetchHomeFeed(maxId?) {
     const res = await this.client.get("statuses/home_timeline", {
       count: 20,
@@ -40,11 +47,18 @@ export class TwitterApiProvider {
     return res.data;
   }
 
+  /**
+   * fetch user object to given id
+   * @param userId user id
+   */
   public async fetchUser(userId) {
     const res = await this.client.get("users/show", { user_id: userId });
     return res.data;
   }
 
+  /**
+   * lookup user for screenname
+   */
   public async fetchUserFromScreenName(screenName) {
     const res = await this.client.get("users/lookup", {
       screen_name: screenName
@@ -52,6 +66,11 @@ export class TwitterApiProvider {
     return res.data;
   }
 
+  /**
+   * fetch user feed in batches of 20 tweets starting at maxId
+   * @param userId user id
+   * @param maxId max tweet id
+   */
   public async fetchUserTimeline(userId, maxId?) {
     try {
       const res = await this.client.get("statuses/user_timeline", {
@@ -68,30 +87,60 @@ export class TwitterApiProvider {
     }
   }
 
+  /**
+   * Follow user
+   * @param userId user id
+   */
   public async createFriendship(userId) {
     return await this.client.post("friendships/create", { user_id: userId });
   }
 
+  /**
+   * Unfollow user
+   * @param userId user id
+   */
   public async destroyFriendship(userId) {
     return await this.client.post("friendships/destroy", { user_id: userId });
   }
 
+  /**
+   * Mute user
+   * @param userId user id
+   */
   public async muteUser(userId) {
     return await this.client.post("mutes/users/create", { user_id: userId });
   }
 
+  /**
+   * Unmute user
+   * @param userId user id
+   */
   public async unmuteUser(userId) {
     return await this.client.post("mutes/users/destroy", { user_id: userId });
   }
 
+  /**
+   * Block user
+   * @param userId user id
+   */
   public async blockUser(userId) {
     return await this.client.post("blocks/create", { user_id: userId });
   }
 
+  /**
+   * Unblock user
+   * @param userId user id
+   */
   public async unblockUser(userId) {
     return await this.client.post("blocks/destroy", { user_id: userId });
   }
 
+  /**
+   * Post tweet
+   * @param status tweet message
+   * @param retweet tweet object to retweet
+   * @param replyToStatusId tweet id to reply to
+   */
   public async tweet(status, retweet?, replyToStatusId?) {
     if (status.length === 0 && retweet) {
       // Simple retweet
@@ -120,6 +169,10 @@ export class TwitterApiProvider {
     }
   }
 
+  /**
+   * Fetch friends for user id
+   * @param userId user id
+   */
   public async fetchFriends(userId) {
     let friends = [];
     let cursor = -1;
@@ -139,14 +192,26 @@ export class TwitterApiProvider {
     return friends;
   }
 
+  /**
+   * Like tweet
+   * @param tweetId tweet id
+   */
   public async likeTweet(tweetId) {
     return await this.client.post("favorites/create", { id: tweetId });
   }
 
+  /**
+   * Remove like from tweet
+   * @param tweetId tweet id
+   */
   public async unlikeTweet(tweetId) {
     return await this.client.post("favorites/destroy", { id: tweetId });
   }
 
+  /**
+   * Retrieve a single tweet
+   * @param tweetId tweet id
+   */
   public async fetchTweet(tweetId) {
     return await this.client.get("statuses/show", {
       id: tweetId,
@@ -154,6 +219,12 @@ export class TwitterApiProvider {
     });
   }
 
+  /**
+   * Search Twitter for recent tweets
+   * Since the results are loaded in batches of 20 tweets, max tweet id is a reference for the next batch
+   * @param keyword keyword
+   * @param maxId max tweet id
+   */
   public async searchRecentTweets(keyword: string, maxId?: string) {
     const res = await this.client.get("search/tweets", {
       q: keyword,
@@ -166,6 +237,12 @@ export class TwitterApiProvider {
     return res.data;
   }
 
+  /**
+   * Search Twitter for popular tweets
+   * Since the results are loaded in batches of 20 tweets, max tweet id is a reference for the next batch
+   * @param keyword keyword
+   * @param maxId max tweet id
+   */
   public async searchPopularTweets(keyword: string, maxId?: string) {
     const res = await this.client.get("search/tweets", {
       q: keyword,
@@ -178,6 +255,12 @@ export class TwitterApiProvider {
     return res.data;
   }
 
+  /**
+   * Search Twitter for users
+   * Since the API returns users paginated, a page has to be provided
+   * @param keyword keyword
+   * @param page page number
+   */
   public async searchUsers(keyword: string, page?: number) {
     const res = await this.client.get("users/search", {
       q: keyword,
@@ -188,6 +271,10 @@ export class TwitterApiProvider {
     return res.data;
   }
 
+  /**
+   * Updates the profile description
+   * @param description profile description
+   */
   public async updateProfileDescription(description: string) {
     const res = await this.client.post("account/update_profile", {
       description: description