<commit_before>import {constructHydraId} from '@ciscospark/react-component-utils';

export const eventNames = {
  SPACES_READ: 'rooms:read',
  SPACES_UNREAD: 'rooms:unread',
  SPACES_SELECTED: 'rooms:selected',
  MESSAGES_CREATED: 'messages:created',
  CALLS_CREATED: 'calls:created',
  ACTION_CALL_ANSWER: 'call.answer',
  ACTION_CALL_REJECT: 'call.reject',
  ACTION_CALL: 'call',
  MEMBERSHIPS_CREATED: 'memberships:created',
  MEMBERSHIPS_DELETED: 'memberships:deleted'
};

/**
 * Constructs an event detail object for messages:created
 * @export
 * @param {Object} activity from mercury
 * @param {Object} toUser
 * @returns {Object} constructed event
 */
export function constructMessagesEventData(activity, toUser) {
  const roomType = activity.target.tags.includes('ONE_ON_ONE') ? 'direct' : 'group';
  let files, toPersonEmail, toPersonId;

  if (roomType === 'direct' && toUser) {
    toPersonEmail = toUser.emailAddress;
    toPersonId = constructHydraId('PEOPLE', toUser.id);
  }

  let mentionedPeople = activity.object.mentions;
  if (mentionedPeople && mentionedPeople.items.length) {
    mentionedPeople = mentionedPeople.items.map((people) => ({
      id: constructHydraId('PEOPLE', people.id)
    }));
  }

  // Files need to be decrypted and converted into a usable URL
  if (activity.object.files && activity.object.files.items.length) {
    files = activity.object.files.items;
  }

  const personId = constructHydraId('PEOPLE', activity.actor.id);
  return {
    actorId: personId,
    id: constructHydraId('MESSAGE', activity.id),
    roomId: constructHydraId('ROOM', activity.target.id),
    roomType: activity.target.tags.includes('ONE_ON_ONE') ? 'direct' : 'group',
    text: activity.object.displayName,
    html: activity.object.content,
    files,
    personId,
    personEmail: activity.actor.emailAddress,
    created: activity.published,
    mentionedPeople,
    toPersonId,
    toPersonEmail
  };
}


export function constructRoomsEventData(space, activity) {
  return {
    id: constructHydraId('ROOM', space.id),
    title: space.name,
    type: space.type,
    isLocked: space.isLocked,
    teamId: constructHydraId('TEAM', space.teamId),
    lastActivity: activity && activity.published || space.lastActivityTimestamp,
    created: space.published,
    toPersonEmail: space.toPersonEmail
  };
}


export function constructMembershipEventData(activity) {
  return {
    actorId: constructHydraId('PEOPLE', activity.actor.id),
    id: constructHydraId('MESSAGE', activity.id),
    roomId: constructHydraId('ROOM', activity.target.id),
    personId: constructHydraId('PEOPLE', activity.object.id),
    personEmail: activity.object.emailAddress,
    created: activity.published
  };
}

export function constructCallEventData(call, space) {
  return {
    actorId: constructHydraId('PEOPLE', call.locus.host.id),
    personId: constructHydraId('PEOPLE', call.locus.host.id),
    personEmail: call.locus.host.email,
    roomId: constructHydraId('ROOM', space.id),
    call
  };
}<commit_msg>refactor(widget-recents): use the widgetTypes object<commit_after>import {constructHydraId, hydraTypes} from '@ciscospark/react-component-utils';

export const eventNames = {
  SPACES_READ: 'rooms:read',
  SPACES_UNREAD: 'rooms:unread',
  SPACES_SELECTED: 'rooms:selected',
  MESSAGES_CREATED: 'messages:created',
  CALLS_CREATED: 'calls:created',
  ACTION_CALL_ANSWER: 'call.answer',
  ACTION_CALL_REJECT: 'call.reject',
  ACTION_CALL: 'call',
  MEMBERSHIPS_CREATED: 'memberships:created',
  MEMBERSHIPS_DELETED: 'memberships:deleted'
};

/**
 * Constructs an event detail object for messages:created
 * @export
 * @param {Object} activity from mercury
 * @param {Object} toUser
 * @returns {Object} constructed event
 */
export function constructMessagesEventData(activity, toUser) {
  const roomType = activity.target.tags.includes('ONE_ON_ONE') ? 'direct' : 'group';
  let files, toPersonEmail, toPersonId;

  if (roomType === 'direct' && toUser) {
    toPersonEmail = toUser.emailAddress;
    toPersonId = constructHydraId(hydraTypes.PEOPLE, toUser.id);
  }

  let mentionedPeople = activity.object.mentions;
  if (mentionedPeople && mentionedPeople.items.length) {
    mentionedPeople = mentionedPeople.items.map((people) => ({
      id: constructHydraId(hydraTypes.PEOPLE, people.id)
    }));
  }

  // Files need to be decrypted and converted into a usable URL
  if (activity.object.files && activity.object.files.items.length) {
    files = activity.object.files.items;
  }

  const personId = constructHydraId(hydraTypes.PEOPLE, activity.actor.id);
  return {
    actorId: personId,
    id: constructHydraId(hydraTypes.MESSAGE, activity.id),
    roomId: constructHydraId(hydraTypes.ROOM, activity.target.id),
    roomType: activity.target.tags.includes('ONE_ON_ONE') ? 'direct' : 'group',
    text: activity.object.displayName,
    html: activity.object.content,
    files,
    personId,
    personEmail: activity.actor.emailAddress,
    created: activity.published,
    mentionedPeople,
    toPersonId,
    toPersonEmail
  };
}


export function constructRoomsEventData(space, activity) {
  return {
    id: constructHydraId(hydraTypes.ROOM, space.id),
    title: space.name,
    type: space.type,
    isLocked: space.isLocked,
    teamId: constructHydraId(hydraTypes.TEAM, space.teamId),
    lastActivity: activity && activity.published || space.lastActivityTimestamp,
    created: space.published,
    toPersonEmail: space.toPersonEmail
  };
}


export function constructMembershipEventData(activity) {
  return {
    actorId: constructHydraId(hydraTypes.PEOPLE, activity.actor.id),
    id: constructHydraId(hydraTypes.MESSAGE, activity.id),
    roomId: constructHydraId(hydraTypes.ROOM, activity.target.id),
    personId: constructHydraId(hydraTypes.PEOPLE, activity.object.id),
    personEmail: activity.object.emailAddress,
    created: activity.published
  };
}

export function constructCallEventData(call, space) {
  return {
    actorId: constructHydraId(hydraTypes.PEOPLE, call.locus.host.id),
    personId: constructHydraId(hydraTypes.PEOPLE, call.locus.host.id),
    personEmail: call.locus.host.email,
    roomId: constructHydraId(hydraTypes.ROOM, space.id),
    call
  };
}
{'fraction_non_alphanumeric': 0.12140215468724876, 'fraction_numerical': 0.0, 'mean_word_length': 4.618789521228545, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6438848', 'n_tokens_mistral': 2049, 'n_tokens_neox': 2000, 'n_words': 381}