Hook to use before messages load


Home Forums Front End PM PRO Hook to use before messages load

This topic is: Not Resolved
Viewing 6 posts - 16 through 21 (of 21 total)
  • Author
    Posts
  • #11406
    Alex Brearley
    Participant

    yes, you are right about $args :/ I’ve removed the child code for the time being. The child messages show if you chose the option to show each email rather than email thread. I have gone back to only showing email thread which resolves the issue.

    I now have the following code but am still seeing the unread hidden messages being included in the count.

            $this->loader->wp_add_filter('fep_message_query_args', array(
                $this->fep,
                'cmdu_hide_message'
            ), 10, 2);
    
            $this->loader->wp_add_filter('fep_message_count_query_args', array(
                $this->fep,
                'cmdu_hide_message'
            ), 10, 2);
        public function cmdu_hide_message($args, $user_id)
        {
            
            // Admin users can see all
            if (! current_user_can('administrator')) {           
                $args['post__not_in'] = $this->hide_mes_id();
            }
            
            return $args;
        }

    And inside private function hide_mes_id()

            $not_post = array();
            foreach ($findrefs as $ref) {
                array_push($not_post, $ref->mes_id);
                
                /*
                 * $child_args = array(
                 * 'post_parent' => $ref->mes_id,
                 * 'post_type' => 'any',
                 * 'numberposts' => - 1,
                 * 'post_status' => 'any'
                 * );
                 * $children = get_children($child_args);
                 *
                 * foreach ($children as $child) {
                 *
                 * array_push($not_post, $child);
                 * }
                 */
            }
            return $not_post;
    
    #11410
    Shamim Hasan
    Keymaster

    Please send a message to that user after added this code. That will delete previous cache for that user and show proper count.

    It will be better if you can hide message when that message is sent rather then when view.

    #11413
    Alex Brearley
    Participant

    Hiding on send won’t work as the act of hiding is the result of some business logic that is asynchronous to the act of sending a message in the first instance. Would it be possible to mark messages as read when they are hidden or somehow force the cached message count to be refreshed once the messages are hidden?

    #11415
    Shamim Hasan
    Keymaster

    Please send a message to that user after added this code. That should delete previous cache for that user and show proper count.

    #11417
    Alex Brearley
    Participant

    I appreciate sending a message afterwards forces the cache to be reset but this does not meet the requirements – I would like messages to be hidden and then made visible based on a business logic status change and not when a message happens to be sent. Desired behaviour:

    1. General message exchange, some messages read and some unread.
    2. business process reaches a particular status and message are all hidden and the unread message count has unread hidden messages removed.
    3. business process reaches another status and message are unhidden and the unread message count now includes the count of those previously hidden messages.

    Currently, If I move the business process to a state where they are supposed to be hidden, the messages are hidden and the unread count seems to be correct. However, when I move the process to the state where messages are visible again, they don’t get shown until I send another message to that user again.

    #11442
    Shamim Hasan
    Keymaster

    When message in changed from hidden to shown add this code there, this will clear cache so that you get correct count.

    
    $participants = fep_get_participants( $message_id );
    
    foreach( $participants as $participant ) 
    {
        delete_user_option( $participant, '_fep_user_message_count' );
    }
    

    change $message_id with which message is hidden to shown

Viewing 6 posts - 16 through 21 (of 21 total)

You need to purchase ‘Front End PM PRO’ to create topic in this support forum.

If you already purchased ‘Front End PM PRO’ please LOGIN.