<commit_before>// @flow
import * as Chat2Gen from './chat2-gen'
import * as FsGen from './fs-gen'
import * as GitGen from './git-gen'
import * as NotificationsGen from './notifications-gen'
import * as RPCTypes from '../constants/types/rpc-gen'
import * as Saga from '../util/saga'
import * as TeamsGen from './teams-gen'
import * as TrackerGen from './tracker-gen'
import * as UnlockFoldersGen from './unlock-folders-gen'
import setUpNotificationActions from '../native/notification-listeners'
import engine, {Engine} from '../engine'
import logger from '../logger'
import {isMobile} from '../constants/platform'
import {createSetupPeopleHandlers} from './people-gen'

function* _listenSaga(): Saga.SagaGenerator<any, any> {
  const channels = {
    app: true,
    badges: true,
    chat: true,
    ephemeral: false,
    favorites: false,
    kbfs: !isMobile,
    kbfsrequest: !isMobile,
    keyfamily: false,
    paperkeys: false,
    pgp: true,
    reachability: true,
    service: true,
    session: true,
    team: true,
    tracking: true,
    users: true,
    chatkbfsedits: false,
  }

  const engineInst: Engine = yield Saga.call(engine)
  yield Saga.call([engineInst, engineInst.listenOnConnect], 'setNotifications', () => {
    RPCTypes.notifyCtlSetNotificationsRpcPromise({channels}).catch(error => {
      if (error != null) {
        logger.warn('error in toggling notifications: ', error)
      }
    })
  })

  setUpNotificationActions()

  yield Saga.put(TrackerGen.createSetupTrackerHandlers())
}

function* _listenKBFSSaga(): Saga.SagaGenerator<any, any> {
  yield Saga.put(FsGen.createSetupFSHandlers())
  yield Saga.put(Chat2Gen.createSetupChatHandlers())
  yield Saga.put(TeamsGen.createSetupTeamHandlers())
  yield Saga.put(UnlockFoldersGen.createRegisterRekeyListener())
  yield Saga.put(createSetupPeopleHandlers())
}

function _onRecievedBadgeState(action: NotificationsGen.ReceivedBadgeStatePayload) {
  const {
    conversations,
    newGitRepoGlobalUniqueIDs,
    newTeamNames,
    newTeamAccessRequests,
    teamsWithResetUsers,
  } = action.payload.badgeState
  return Saga.sequentially([
    Saga.put(Chat2Gen.createBadgesUpdated({conversations: conversations || []})),
    Saga.put(GitGen.createBadgeAppForGit({ids: newGitRepoGlobalUniqueIDs || []})),
    Saga.put(
      TeamsGen.createBadgeAppForTeams({
        newTeamAccessRequests: newTeamAccessRequests || [],
        newTeamNames: newTeamNames || [],
        teamsWithResetUsers: teamsWithResetUsers || [],
      })
    ),
    Saga.put(FsGen.createFavoritesLoad()),
  ])
}

function* _listenNotifications(): Saga.SagaGenerator<any, any> {
  yield Saga.take(NotificationsGen.listenForNotifications)
  yield Saga.call(_listenSaga)
}

function* _listenForKBFSNotifications(): Saga.SagaGenerator<any, any> {
  yield Saga.take(NotificationsGen.listenForKBFSNotifications)
  yield Saga.call(_listenKBFSSaga)
}

function* notificationsSaga(): Saga.SagaGenerator<any, any> {
  yield Saga.fork(_listenNotifications)
  yield Saga.fork(_listenForKBFSNotifications)
  yield Saga.safeTakeLatestPure(NotificationsGen.receivedBadgeState, _onRecievedBadgeState)
}

export default notificationsSaga<commit_msg>fs: Remove favorites listing trigger from badge state notification (#12467)<commit_after>// @flow
import * as Chat2Gen from './chat2-gen'
import * as FsGen from './fs-gen'
import * as GitGen from './git-gen'
import * as NotificationsGen from './notifications-gen'
import * as RPCTypes from '../constants/types/rpc-gen'
import * as Saga from '../util/saga'
import * as TeamsGen from './teams-gen'
import * as TrackerGen from './tracker-gen'
import * as UnlockFoldersGen from './unlock-folders-gen'
import setUpNotificationActions from '../native/notification-listeners'
import engine, {Engine} from '../engine'
import logger from '../logger'
import {isMobile} from '../constants/platform'
import {createSetupPeopleHandlers} from './people-gen'

function* _listenSaga(): Saga.SagaGenerator<any, any> {
  const channels = {
    app: true,
    badges: true,
    chat: true,
    ephemeral: false,
    favorites: false,
    kbfs: !isMobile,
    kbfsrequest: !isMobile,
    keyfamily: false,
    paperkeys: false,
    pgp: true,
    reachability: true,
    service: true,
    session: true,
    team: true,
    tracking: true,
    users: true,
    chatkbfsedits: false,
  }

  const engineInst: Engine = yield Saga.call(engine)
  yield Saga.call([engineInst, engineInst.listenOnConnect], 'setNotifications', () => {
    RPCTypes.notifyCtlSetNotificationsRpcPromise({channels}).catch(error => {
      if (error != null) {
        logger.warn('error in toggling notifications: ', error)
      }
    })
  })

  setUpNotificationActions()

  yield Saga.put(TrackerGen.createSetupTrackerHandlers())
}

function* _listenKBFSSaga(): Saga.SagaGenerator<any, any> {
  yield Saga.put(FsGen.createSetupFSHandlers())
  yield Saga.put(Chat2Gen.createSetupChatHandlers())
  yield Saga.put(TeamsGen.createSetupTeamHandlers())
  yield Saga.put(UnlockFoldersGen.createRegisterRekeyListener())
  yield Saga.put(createSetupPeopleHandlers())
}

function _onRecievedBadgeState(action: NotificationsGen.ReceivedBadgeStatePayload) {
  const {
    conversations,
    newGitRepoGlobalUniqueIDs,
    newTeamNames,
    newTeamAccessRequests,
    teamsWithResetUsers,
  } = action.payload.badgeState
  return Saga.sequentially([
    Saga.put(Chat2Gen.createBadgesUpdated({conversations: conversations || []})),
    Saga.put(GitGen.createBadgeAppForGit({ids: newGitRepoGlobalUniqueIDs || []})),
    Saga.put(
      TeamsGen.createBadgeAppForTeams({
        newTeamAccessRequests: newTeamAccessRequests || [],
        newTeamNames: newTeamNames || [],
        teamsWithResetUsers: teamsWithResetUsers || [],
      })
    ),
  ])
}

function* _listenNotifications(): Saga.SagaGenerator<any, any> {
  yield Saga.take(NotificationsGen.listenForNotifications)
  yield Saga.call(_listenSaga)
}

function* _listenForKBFSNotifications(): Saga.SagaGenerator<any, any> {
  yield Saga.take(NotificationsGen.listenForKBFSNotifications)
  yield Saga.call(_listenKBFSSaga)
}

function* notificationsSaga(): Saga.SagaGenerator<any, any> {
  yield Saga.fork(_listenNotifications)
  yield Saga.fork(_listenForKBFSNotifications)
  yield Saga.safeTakeLatestPure(NotificationsGen.receivedBadgeState, _onRecievedBadgeState)
}

export default notificationsSaga
{'fraction_non_alphanumeric': 0.11887235708692248, 'fraction_numerical': 0.0020360219263899767, 'mean_word_length': 4.557876414273281, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5193535', 'n_tokens_mistral': 2060, 'n_tokens_neox': 2044, 'n_words': 403}