<commit_before>import notificationsResource from '../../apiResources/new/notifications';
import { summarizedNotifications } from './getters';

export default {
  namespaced: true,
  state: {
    currentClassroomId: null,
    notifications: [],
    lastPolled: null,
    poller: null,
  },
  mutations: {
    SET_NOTIFICATIONS(state, notifications) {
      state.notifications = [...notifications];
    },
    APPEND_NOTIFICATIONS(state, notifications) {
      state.notifications = [...notifications, ...state.notifications];
    },
    SET_LAST_POLLED_TO_NOW(state) {
      state.lastPolled = Date.now();
    },
    SET_POLLER(state, poller) {
      state.poller = poller;
    },
    SET_CURRENT_CLASSROOM_ID(state, classroomId) {
      state.currentClassroomId = classroomId;
    },
  },
  getters: {
    summarizedNotifications,
  },
  actions: {
    fetchNotificationsForClass(store, classroomId) {
      if (!store.state.currentClassroomId) {
        store.commit('SET_CURRENT_CLASSROOM_ID', classroomId);
      }
      const after = Date.now();
      return notificationsResource
        .fetchCollection({
          getParams: {
            collection_id: classroomId,
          },
        })
        .then(data => {
          store.commit('SET_NOTIFICATIONS', data);
          if (!store.state.poller) {
            store.dispatch('startPolling', after);<commit_msg>Add getters to filter notifications by learner group or learner<commit_after>import notificationsResource from '../../apiResources/new/notifications';
import { summarizedNotifications } from './getters';

export default {
  namespaced: true,
  state: {
    currentClassroomId: null,
    notifications: [],
    lastPolled: null,
    poller: null,
  },
  mutations: {
    SET_NOTIFICATIONS(state, notifications) {
      state.notifications = [...notifications];
    },
    APPEND_NOTIFICATIONS(state, notifications) {
      state.notifications = [...notifications, ...state.notifications];
    },
    SET_LAST_POLLED_TO_NOW(state) {
      state.lastPolled = Date.now();
    },
    SET_POLLER(state, poller) {
      state.poller = poller;
    },
    SET_CURRENT_CLASSROOM_ID(state, classroomId) {
      state.currentClassroomId = classroomId;
    },
  },
  getters: {
    summarizedNotifications,
    notificationsByUserId(state) {
      return function byUserId(userId) {
        return state.notifications.filter(notification => notification.user_id === userId);
      };
    },
    notificationsByLearnerGroupId(state, getters, rootState, rootGetters) {
      return function byLearnerGroupId(groupId) {
        const groupMembers =
          rootGetters['classSummary/notificationModuleData'].learnerGroups[groupId].member_ids;
        return state.notifications.filter(notification =>
          groupMembers.includes(notification.user_id)
        );
      };
    },
  },
  actions: {
    fetchNotificationsForClass(store, classroomId) {
      if (!store.state.currentClassroomId) {
        store.commit('SET_CURRENT_CLASSROOM_ID', classroomId);
      }
      const after = Date.now();
      return notificationsResource
        .fetchCollection({
          getParams: {
            collection_id: classroomId,
          },
        })
        .then(data => {
          store.commit('SET_NOTIFICATIONS', data);
          if (!store.state.poller) {
            store.dispatch('startPolling', after);
{'fraction_non_alphanumeric': 0.11743772241992882, 'fraction_numerical': 0.0, 'mean_word_length': 2.824263038548753, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3140919', 'n_tokens_mistral': 995, 'n_tokens_neox': 989, 'n_words': 161}