.homeworks/hw5/Post.cpp
/* add a update TO a post */
add a update TO a post
add a update TO a post
void Post::operator+=(const Post& update)
{
    if (update.profile_id != this->profile_id &&
        update.post_id != this->post_id)
    {
        cerr << "Error: Invalid Update (ID Not Match)" << endl;
        return;
    }
    for (auto var : *update.comments)
    {
        CommentKeyPair thisKey = var.second->getKeyPair();
        if (this->comments->count(thisKey))
            *(*this->comments)[thisKey] += *var.second;
        else
            (*this->comments)[thisKey] = var.second->clone();
    }
    this->is_published = update.is_published;
    if (update.updated_time)
    {
        delete this->updated_time;
        this->updated_time = update.updated_time->clone();
    }
    for (auto var : *update.reactions)
        this->reactions->push_back(var->clone());
    for (auto var: *update.receivers)
        this->receivers->push_back(var->clone());
}
void Post :: operator += ( const Post & update ) { if ( update . profile_id != this -> profile_id && update . post_id != this -> post_id ) { cerr << " " << endl ; return ; } for ( auto var : * update . comments ) { CommentKeyPair thisKey = var . second -> getKeyPair ( ) ; if ( this -> comments -> count ( thisKey ) ) * ( * this -> comments ) [ thisKey ] += * var . second ; else ( * this -> comments ) [ thisKey ] = var . second -> clone ( ) ; } this -> is_published = update . is_published ; if ( update . updated_time ) { delete this -> updated_time ; this -> updated_time = update . updated_time -> clone ( ) ; } for ( auto var : * update . reactions ) this -> reactions -> push_back ( var -> clone ( ) ) ; for ( auto var : * update . receivers ) this -> receivers -> push_back ( var -> clone ( ) ) ; }
add a update TO a post
add a update TO a post
// spacial case:  // get the new comments or update to excesting comments // if this comment already exists, add to it // otherwise it is a new comment // change to new update time // get the new reactions // get the new receivers