<commit_before>import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';

const feedItemSchema = {
  _id: { type: String, regEx: SimpleSchema.RegEx.Id, denyUpdate: true },
  userId: { type: String, regEx: SimpleSchema.RegEx.Id, denyUpdate: true },
  actionId: { type: String, regEx: SimpleSchema.RegEx.Id, denyUpdate: true },
  createdAt: { type: Date, denyUpdate: true },
};

export const NewsItems = new Mongo.Collection('news');

NewsItems.schema = new SimpleSchema({
  ...feedItemSchema,
  authorId: { type: String, regEx: SimpleSchema.RegEx.Id, denyUpdate: true },
});

NewsItems.attachSchema(NewsItems.schema);

export const NotifyItems = new Mongo.Collection('notices');

NotifyItems.schema = new SimpleSchema({
  ...feedItemSchema,
  isRead: { type: Boolean, defaultValue: false },
});

NotifyItems.attachSchema(NotifyItems.schema);<commit_msg>feeds: Add `news`, `notifications` publications<commit_after>import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { check } from 'meteor/check';

import { Actions, actionChildrenCursors } from './actions';

const feedItemSchema = {
  _id: { type: String, regEx: SimpleSchema.RegEx.Id, denyUpdate: true },
  userId: { type: String, regEx: SimpleSchema.RegEx.Id, denyUpdate: true },
  actionId: { type: String, regEx: SimpleSchema.RegEx.Id, denyUpdate: true },
  createdAt: { type: Date, denyUpdate: true },
};

export const NewsItems = new Mongo.Collection('news');

NewsItems.schema = new SimpleSchema({
  ...feedItemSchema,
  authorId: { type: String, regEx: SimpleSchema.RegEx.Id, denyUpdate: true },
});

NewsItems.attachSchema(NewsItems.schema);

export const NotifyItems = new Mongo.Collection('notices');

NotifyItems.schema = new SimpleSchema({
  ...feedItemSchema,
  isRead: { type: Boolean, defaultValue: false },
});

NotifyItems.attachSchema(NotifyItems.schema);

if (Meteor.isServer) {
  Meteor.publishComposite('news', function(limit) {
    check(limit, Number);

    if (!this.userId)
      return this.ready();

    return {
      find: () => NewsItems.find({ userId: this.userId }, { sort: { createdAt: -1 }, limit: limit }),
      children: [{
        find: newsItem => Actions.find(newsItem.actionId),
        children: actionChildrenCursors,
      }],
    };
  });

  Meteor.publishComposite('notifications', function(limit) {
      check(limit, Number);

      if (!this.userId)
        return this.ready();

      return {
        find: () => NotifyItems.find({ userId: this.userId }, { sort: { createdAt: -1 }, limit: limit }),
        children: [{
          find: notifyItem => Actions.find(notifyItem.actionId),
          children: actionChildrenCursors,
        }],
      };
    }
  );
}
{'fraction_non_alphanumeric': 0.14699570815450644, 'fraction_numerical': 0.000715307582260372, 'mean_word_length': 4.021543985637343, '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': '727387', 'n_tokens_mistral': 885, 'n_tokens_neox': 867, 'n_words': 202}