예제 #1
0
def unFollow(ctx, uid, uFAddr, index_a, index_b):
    """
    Unfollow another user

    Args:
        uid -> unique user id
        uFAddr -> to-follow script hash
        index_a -> Index of iterated storage of uid, for the following of fUid
        index_b -> Index of iterated storage of FUid, for the follow of uid
    """
    uFUid = isRegistered(ctx, uFAddr)
    if not uFUid == False:
        if uFUid == uid:
            Notify("User cannot unfollow himself")
            return False
        if isFollowing(ctx, uid, uFUid):
            #User has to be follower, respecitve follower has to be followed by user
            a_temp = GetThree(ctx, uid, ".following.", index_a)
            a_temp_d = Deserialize(a_temp)
            b_temp = GetThree(ctx, uFUid, ".followers.", index_b)
            b_temp_d = Deserialize(b_temp)
            if a_temp_d[0] == uFUid and b_temp_d[0] == uid:
                # Count unfollowing += 1 for uid
                ##a_save = Get(ctx, uid)
                ##a_save_d = Deserialize(a_save)
                ##a_count = a_save_d[8]
                ##aa_count = a_count + 1
                ##a_save_d[8] = aa_count
                ##a_save_s = Serialize(a_save_d)
                ##Put(ctx, uid, a_save_s)
                updateAccCount(ctx, uid, 8, False)

                # Count unfollowed += 1 for uFUid
                ##b_save = Get(ctx, uFUid)
                ##b_save_d = Deserialize(b_save)
                ##b_count = b_save_d[7]
                ##bb_count = b_count + 1
                ##b_save_d[7] = bb_count
                ##b_save_s = Serialize(b_save_d)
                ##Put(ctx, uFUid, b_save_s)
                updateAccCount(ctx, uFUid, 7, False)

                # Mark index as unfollowed for uid
                PutThree(ctx, uid, ".following.", index_a, "unfollowing")
                # Mark index as unfollowed for uFUid
                PutThree(ctx, uFUid, ".followers.", index_b, "unfollowed")

                #Set follow indicator = false
                PutThree(ctx, uid, ".followcheck.", uFUid, False)

                OnUnfollow(uid, uFUid)
                return True
            Notify("Following and Follower indexes do not match")
            return False
        Notify("User is not following.")
        return False
    Notify("User to unfollow not registered")
    return False
예제 #2
0
def follow(ctx, uid, fAddr):
    """
    Follow another user

    Args:
        uid -> unique user id
        fAddr -> to-follow script hash
    """
    #how to prevent multiple following?
    fUid = isRegistered(ctx, fAddr)
    if not fUid == False:
        if fUid == uid:
            Notify("User cannot follow himself")
            return False
        if not isFollowing(ctx, uid, fUid):
            # Count following += 1 for uid
            ##a_save = Get(ctx, uid)
            ##a_save_d = Deserialize(a_save)
            ##a_count = a_save_d[6]
            ##aa_count = a_count + 1
            ##a_save_d[6] = aa_count
            ##a_save_s = Serialize(a_save_d)
            ##Put(ctx, uid, a_save_s)
            aa_count = updateAccCount(ctx, uid, 6, False)

            # Count follower += 1 for fUid
            ##b_save = Get(ctx, fUid)
            ##b_save_d = Deserialize(b_save)
            ##b_count = b_save_d[5]
            ##bb_count = b_count + 1
            ##b_save_d[5] = bb_count
            ##b_save_s = Serialize(b_save_d)
            ##Put(ctx, fUid, b_save_s)
            bb_count = updateAccCount(ctx, fUid, 5, False)

            # Add follow to iterated storage for uid
            t1 = [fUid, bb_count]
            t1_s = Serialize(t1)
            PutThree(ctx, uid, ".following.", aa_count, t1_s)

            # Add follow to iterated storage for fUid
            t2 = [uid, aa_count]
            t2_s = Serialize(t2)
            PutThree(ctx, fUid, ".followers.", bb_count, t2_s)

            #Set follow indicator = true
            PutThree(ctx, uid, ".followcheck.", fUid, True)

            OnFollow(uid, fUid)
            return True
        Notify("User already following")
        return False
    Notify("User to follow not registered")
    return False
예제 #3
0
def addMessage(ctx, party, direction, message, partySecond, time, ipfs,
               encrypted):
    newLastIndex = IncrementThree(ctx, party, direction, "latest")
    messageData = [message, time, partySecond, ipfs, encrypted]
    messageTemp = Serialize(messageData)
    PutThree(ctx, party, direction, newLastIndex, messageTemp)
    return True
예제 #4
0
def like(ctx, uid, tweet):
    """
    Like a tweet
    
    Args:
        uid -> unique user id
        tweet -> key of to-comment  
    """
    # check if user is liking already
    if not isLiking(ctx, uid, tweet):
        count = updateTweetCount(ctx, tweet, "like")
        if count > 0:
            # save comment for tweet
            PutThree(ctx, tweet, ".like.", count, uid)
            #Set like indicator = true
            PutThree(ctx, uid, ".likecheck.", tweet, True)
            OnLike(uid, tweet)
            return True
        Notify("To-like tweet does not exist")
        return False
    Notify("User already liking tweet")
    return False
예제 #5
0
def tweet(ctx, addr, uid, content, retweet):
    """
    Post tweet
    
    Args:
        addr -> script hash of invoker
        uid -> unique user id
        content -> Tweet content
        retweet -> If '' then normal tweet. If key is given (from retweet operation) then this is a retweet
    
    Return: storage key for new tweet
    
    Tweet storage uid.tweet.{id (incremented per user)} => array[]:
        0 -> script hash of invoker
        1 -> uid
        2 -> display name
        3 -> tweet text
        4 -> time of tweet
        5 -> count comments
        6 -> count retweets        
        7 -> count likes
        8 -> count unlikes
        9 -> storage key retweeted tweet
    """

    #get user account data and count+1 for tweet
    accData = updateAccCount(ctx, uid, 4, True)
    newIndex = accData[4]
    name = accData[2]

    # save new tweet
    time = GetTime()
    save = [addr, uid, name, content, time, 0, 0, 0, 0, retweet]
    save_s = Serialize(save)
    PutThree(ctx, uid, ".tweet.", newIndex, save_s)

    # increment total tweet count
    tweetIndex = IncrementOne(ctx, "tweets")

    # set the storage key for latest tweet
    tmp1 = concat(uid, ".tweet.")
    tmp2 = concat(tmp1, newIndex)
    PutTwo(ctx, "tweet.", tweetIndex, tmp2)

    OnTweet(tweetIndex, uid, tmp2)
    return tmp2
예제 #6
0
def comment(ctx, uid, tweet, comment):
    """
    Comment a tweet
    
    Args:
        uid -> unique user id
        tweet -> key of to-comment
        comment -> comment text    
    """
    count = updateTweetCount(ctx, tweet, "comment")
    if count > 0:
        # save comment for tweet
        time = GetTime()
        save = [uid, time, comment]
        save_s = Serialize(save)
        PutThree(ctx, tweet, ".comment.", count, save_s)
        OnComment(uid, tweet)
        return True
    Notify("To-comment tweet does not exist")
    return False
예제 #7
0
def retweet(ctx, addr, uid, content, retweet):
    """
    Retweet is a tweet with a reference to anhother tweet
    
    Args:
        addr -> script hash of invoker
        uid -> unique user id
        retweet -> key of to-retweet
    
    Return: storage key for new tweet
    """
    # check if to-retweetretweet tweet exists and count+1
    count = updateTweetCount(ctx, retweet, "retweet")
    if count > 0:
        # save retweet for uid
        tmp = tweet(ctx, addr, uid, content, retweet)
        # save uid of retweeter
        PutThree(ctx, retweet, ".retweet.", count, uid)
        OnRetweet(uid, retweet)
        return tmp
    Notify("To-retweet tweet does not exist.")
    return False