<commit_before>import Messages from './collections/messages/collection.js';
import Conversations from './collections/conversations/collection.js';
import Users from 'meteor/vulcan:users';
import { Utils, getCollection } from 'meteor/vulcan:core';


/**
* @summary Get relative link to conversation (used only in session)
* @param {Object} conversation
**/
Conversations.getLink = (conversation) => {
  return `/inbox?select=${conversation._id}`;
};

/**
* @summary Get relative link to conversation of message (conversations are only linked to relatively)
* @param {Object} message
**/
Messages.getLink = (message) => {
  return `/inbox?select=${message.conversationId}`;
};


/**
* @summary Check whether User is subscribed to a document
* @param {Object} user
* @param {Object} document
**/
Users.isSubscribedTo = (user, document) => {
  if (!user || !document) {
    // should return an error
    return false;
  }

  const { __typename, _id: itemId } = document;
  const documentType = Utils.capitalize(Utils.getCollectionNameFromTypename(__typename));

  if (user.subscribedItems && user.subscribedItems[documentType]) {
    return !!user.subscribedItems[documentType].find(subscribedItems => subscribedItems.itemId === itemId);
  } else {
    return false;
  }
};
// LESSWRONG version of getting unused slug. Modified to also include "oldSlugs" array
Utils.getUnusedSlug = function (collection, slug, useOldSlugs = false) {
  let suffix = '';
  let index = 0;
  const query = useOldSlugs ? {$or: [{slug: slug+suffix},{oldSlugs: slug+suffix}]} : {slug: slug+suffix}

  // test if slug is already in use
  while (!!collection.findOne(query)) {
    index++
    suffix = '-'+index;
  }

  return slug+suffix;<commit_msg>Fix infinite loop in getUnusedSlug<commit_after>import Messages from './collections/messages/collection.js';
import Conversations from './collections/conversations/collection.js';
import Users from 'meteor/vulcan:users';
import { Utils, getCollection } from 'meteor/vulcan:core';


/**
* @summary Get relative link to conversation (used only in session)
* @param {Object} conversation
**/
Conversations.getLink = (conversation) => {
  return `/inbox?select=${conversation._id}`;
};

/**
* @summary Get relative link to conversation of message (conversations are only linked to relatively)
* @param {Object} message
**/
Messages.getLink = (message) => {
  return `/inbox?select=${message.conversationId}`;
};


/**
* @summary Check whether User is subscribed to a document
* @param {Object} user
* @param {Object} document
**/
Users.isSubscribedTo = (user, document) => {
  if (!user || !document) {
    // should return an error
    return false;
  }

  const { __typename, _id: itemId } = document;
  const documentType = Utils.capitalize(Utils.getCollectionNameFromTypename(__typename));

  if (user.subscribedItems && user.subscribedItems[documentType]) {
    return !!user.subscribedItems[documentType].find(subscribedItems => subscribedItems.itemId === itemId);
  } else {
    return false;
  }
};
// LESSWRONG version of getting unused slug. Modified to also include "oldSlugs" array
Utils.getUnusedSlug = function (collection, slug, useOldSlugs = false) {
  let suffix = '';
  let index = 0;

  // test if slug is already in use
  while (!!collection.findOne(useOldSlugs ? {$or: [{slug: slug+suffix},{oldSlugs: slug+suffix}]} : {slug: slug+suffix})) {
    index++
    suffix = '-'+index;
  }

  return slug+suffix;
{'fraction_non_alphanumeric': 0.13854196921289574, 'fraction_numerical': 0.0005808887598024978, 'mean_word_length': 4.6, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2866559', 'n_tokens_mistral': 1076, 'n_tokens_neox': 1044, 'n_words': 292}