
            -- addit with
            with M as (
                select
                    M.Evn_id as Evn_id,
                    M.Message_id as Message_id,
                    M.Message_pid as Message_pid,
                    M.Message_setDT,
                    M.UserSend_ID as UserSend_ID,
                    M.Message_Subject as Message_Subject,
                    M.Message_Text as Message_Text,
                    M.Message_isSent as Message_isSent,
                    
            MR.Message_isRead as "Message_isRead",
            MR.MessageRecipient_id as "MessageRecipient_id",
            MR.UserRecipient_id as "UserRecipient_id",
            MR.Message_isFlag as "Message_isFlag",
        
                    M.NoticeType_id as NoticeType_id
                FROM msg.v_Message M
                    inner join msg.v_MessageRecipient MR  on MR.Message_id = M.Message_id
                WHERE
                   M.Evn_id is not null
                   and  M.UserSend_ID = 0
                   and MR.UserRecipient_id = '378489551198'
                   and M.Message_isSent is not null
                ORDER BY
                    MR.Message_isRead desc,
                    M.Message_setDT desc
            )
            -- end addit with
            select
                 count(  * ) AS cnt 
            from
                -- from
                M
            INNER join lateral ( select * from v_Evn E  WHERE E.Evn_id = M.Evn_id limit 1) E on true
            left join lateral (
                select EvnClass_SysNick from   v_Evn rEvn  WHERE rEvn.Evn_id = e.Evn_rid limit 1
            ) rEvn on TRUE
            left join v_Person_all P  on P.Person_id=E.Person_id and P.PersonEvn_id=E.PersonEvn_id
            left join v_Evnxml exml on e.Evn_rid = exml.Evn_id
            left join msg.v_MessageLink ML on ML.Message_id = M.Message_id
            left join msg.v_MessageRecipient MR  on MR.Message_id = M.Message_id
            left join pmUserCache MP  on MP.PMUser_id = '378489551198'
            left join msg.v_messagerecipient vmr on (
                M.message_id = vmr.message_id and vmr.userrecipient_id = '378489551198'
            )
                -- end from
            where
                -- where

                 M.Evn_id is not null and E.EvnClass_SysNick is not null and M.UserSend_ID = 0  and MR.UserRecipient_id = '378489551198' and M.Message_isSent is not null
                -- end where
            
        
