
/*
 * Make a new post from 'author' to the 'target' user,
 * containing the given contents, IF the users are friends.
 *
 * Insert the new post at the *front* of the user's list of posts.
 *
 * 'contents' is a pointer to heap-allocated memory - you do not need
 * to allocate more memory to store the contents of the post.
 *
 * Return:
 *   - 0 on success
 *   - 1 if users exist but are not friends
 *   - 2 if either User pointer is NULL
 */
int make_post(const User *author, User *target, char *contents) {
    User *a = (User *) author;
    User *t = target;
     // check that both users exist
    if(a == NULL || t == NULL){
        return 2;
    }
// CHECK THAT THEY ARE FRIENDS AND RETURN 1 IF NOT
    int are_friends = check_if_friends(a, t);
    if(are_friends == 0){
        return 1;
    }
    // now that it has been verified that they both exist and are friends
    // create the new post
    time_t *post_time = malloc(sizeof(time_t));
    *post_time = time(post_time);
    Post *new_post = malloc(sizeof(Post));
    strcpy(new_post->author, a->name);
    new_post->contents = contents;
    new_post->date = post_time;
    new_post->next = NULL;

    // add it in
    // if the target user does not have any posts just make it the first post
    if(target->first_post == NULL){
        target->first_post = new_post;
    }
    else {
        // otherwise
        // store a pointer to the rest of the linked list
        Post *rest_of_posts = target->first_post->next;
        // make the target's first post point to the memory address of the new_post
        target->first_post = new_post;
        // make new_post next point to the rest of the linked list of posts
        new_post->next = rest_of_posts;
        // return 0 upon successfully making the post
    }
    return 0;
}

properly store the new post at the beginning of the linked list without losing the rest of the linked list