import BasePlugin from "./basePlugin" ; export default abstract class BaseMessageCounterPlugin extends BasePlugin { public constructor ( name , settings ) { super ( name , settings ) ; this . shouldInterceptWS = true ; this . shouldInterceptReact = true ; } protected abstract unreadChanged ( ) ; public interceptWS ( data ) { if ( data . type === "message" ) { const slackModel = this . getSlackModel ( ) ; if ( data . channel === slackModel . active_channel_id && data . user !== slackModel . user . id ) { let currentUnread = this . getLocalValue ( "currentUnread" ) ; if ( ! data . subtype ) { if ( ! data . thread_ts ) { currentUnread ++ ; } } else if ( data . subtype === "message_changed" && data . message . user !== slackModel . user . id ) { if ( ! data . hidden ) { currentUnread ++ ; } } this . setLocalValue ( "currentUnread" , currentUnread ) ; this . unreadChanged ( ) ; } } return data ; } public interceptReact ( displayName , props ) { if ( displayName === "UnreadBanner" ) { if ( ! props . hasUnreads && props . channelId ) { this . setLocalValue ( "currentUnread" , 0 ) ; this . unreadChanged ( ) ; } } return props ; } }