<commit_before>export let serviceName = 'messages';
export default /*@ngInject*/ function messages(
  state
) {
  let saveReceivedMessage = saveReceivedMessage() {

  };

  let saveSentMessage = saveSentMessage(channelId, messageContent) {
    return state.save()
  };

  return {};
}
<commit_msg>Added saving message to buffer<commit_after>export let serviceName = 'messages';
export default /*@ngInject*/ function messages(
  $q,
  network,
  time,
  state,
  R
) {
  let saveReceivedMessage = saveReceivedMessage() {

  };

  let saveSendingMessage = saveSendingMessage(channelId, messageContent) {
    if (!messageContent) {
      return $q.reject('messages: message must not be empty');
    }

    let userId = state.cloud.identity.get(['userInfo', 'id']);
    let logicalClock = state.cloud.channels.get([channelId, 'logicalClock']);
    let newLogicalClock = logicalClock + 1;
    let sentTime = time.getTime();
    let contactIds = state.cloud.channels.get([channelId, 'contactIds']);

    let messageId = `${sentTime}-${userId}`;

    let messageInfo = {
      id: messageId,
      senderId: userId,
      sentTime: sentTime,
      logicalClock: newLogicalClock,
      content: messageContent
    };

    let bumpLogicalClock = () => state.save(
      state.cloud.channels,
      [channelId, 'logicalClock'],
      newLogicalClock
    );

    let saveMessageInfo = () => state.save(
      state.cloud.messages,
      [channelId, 'messageInfo'],
      messageInfo
    );

    let addToMessageBuffer = () => $q.all(R.map((contactId) => state.save(
      state.cloud.buffer,
      ['messages', contactId, messageId],
      { messageId, channelId, contactId }
    ))(contactIds));

    return bumpLogicalClock()
      .then(saveMessageInfo)
      .then(addToMessageBuffer);
  };

  return {
    saveSendingMessage
  };
}

{'fraction_non_alphanumeric': 0.12924424972617743, 'fraction_numerical': 0.000547645125958379, 'mean_word_length': 3.2988235294117647, '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': '7307951', 'n_tokens_mistral': 553, 'n_tokens_neox': 546, 'n_words': 120}