<commit_before>export let serviceName = 'network';
export default /*@ngInject*/ function network(
  $interval,
  $q,
  $window,
  channels,
  contacts,
  notifications,
  messages,
  R,
  state,
  time,
  telehash
) {
  let activatingSession = $q.defer();
  let activeSession;

  let checkSession = function checkSession(session) {
    if (session) {
      return;
    }

    throw new Error('network: no active session');
  };

  let handleInvite = function handleInvite(invitePayload) {
    return contacts.saveReceivedInvite(invitePayload);
  };

  let handleProfile = function handleProfile(profilePayload) {
    return contacts.saveReceivedProfile(profilePayload);
  };

  let handleStatus = function handleStatus(statusPayload, contactId) {
    let statusId = statusPayload;

    let contactCursor = state.cloud.contacts
      .select([contactId]);

    let currentContactStatus = contactCursor.get(['statusId']);

    if (currentContactStatus === statusId) {
      return $q.when();
    }

    return state.save(
      state.cloud.contacts,
      [contactId, 'statusId'],
      statusId
    );
  };

  let handleMessage = function handleMessage(messagePayload, messageMetadata) {
    return messages.saveReceivedMessage(messagePayload, messageMetadata);
  };

  let listen = function listen(channelInfo, session = activeSession) {
    let handlePacket = (error, packet, channel, callback) => {
      let handledPacket = () => {
        if (error) {
          return $q.reject(error);
        }

        let senderId = packet.from.hashname;
        let channelId = channel.type.substr(1); //removes leading underscore

        let ackPayload = packet.js.a;
        let invitePayload = packet.js.i;
        let profilePayload = packet.js.p;
        let statusPayload = packet.js.s;
        let messagePayload = packet.js.m;

        callback(true);

        let sendAck = (ackPayload) => {
          channel.send({js: {a: ackPayload}});
        };

        if (ackPayload) {
          return handleStatus(1, senderId);
        } else if (invitePayload) {
          sendAck({});
          return handleInvite(invitePayload);
        } else if (profilePayload) {
          sendAck({});
          return handleProfile(profilePayload);
        } else if (statusPayload !== undefined) {
          sendAck({});
          return handleStatus(statusPayload, senderId);
        } else if (messagePayload) {
          let receivedTime = time.getTime();
          let sentTime = packet.js.t;

          let ackPayload = {
            s: sentTime,
            r: receivedTime
          };
          sendAck(sendAck);<commit_msg>Fixed typo in message ack response<commit_after>export let serviceName = 'network';
export default /*@ngInject*/ function network(
  $interval,
  $q,
  $window,
  channels,
  contacts,
  notifications,
  messages,
  R,
  state,
  time,
  telehash
) {
  let activatingSession = $q.defer();
  let activeSession;

  let checkSession = function checkSession(session) {
    if (session) {
      return;
    }

    throw new Error('network: no active session');
  };

  let handleInvite = function handleInvite(invitePayload) {
    return contacts.saveReceivedInvite(invitePayload);
  };

  let handleProfile = function handleProfile(profilePayload) {
    return contacts.saveReceivedProfile(profilePayload);
  };

  let handleStatus = function handleStatus(statusPayload, contactId) {
    let statusId = statusPayload;

    let contactCursor = state.cloud.contacts
      .select([contactId]);

    let currentContactStatus = contactCursor.get(['statusId']);

    if (currentContactStatus === statusId) {
      return $q.when();
    }

    return state.save(
      state.cloud.contacts,
      [contactId, 'statusId'],
      statusId
    );
  };

  let handleMessage = function handleMessage(messagePayload, messageMetadata) {
    return messages.saveReceivedMessage(messagePayload, messageMetadata);
  };

  let listen = function listen(channelInfo, session = activeSession) {
    let handlePacket = (error, packet, channel, callback) => {
      let handledPacket = () => {
        if (error) {
          return $q.reject(error);
        }

        let senderId = packet.from.hashname;
        let channelId = channel.type.substr(1); //removes leading underscore

        let ackPayload = packet.js.a;
        let invitePayload = packet.js.i;
        let profilePayload = packet.js.p;
        let statusPayload = packet.js.s;
        let messagePayload = packet.js.m;

        callback(true);

        let sendAck = (ackPayload) => {
          channel.send({js: {a: ackPayload}});
        };

        if (ackPayload) {
          return handleStatus(1, senderId);
        } else if (invitePayload) {
          sendAck({});
          return handleInvite(invitePayload);
        } else if (profilePayload) {
          sendAck({});
          return handleProfile(profilePayload);
        } else if (statusPayload !== undefined) {
          sendAck({});
          return handleStatus(statusPayload, senderId);
        } else if (messagePayload) {
          let receivedTime = time.getTime();
          let sentTime = packet.js.t;

          let ackPayload = {
            s: sentTime,
            r: receivedTime
          };
          sendAck(ackPayload);
{'fraction_non_alphanumeric': 0.10976072920622863, 'fraction_numerical': 0.0007595898214963919, 'mean_word_length': 2.5587837837837837, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '242575', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1454, 'n_words': 352}