<commit_before>this.EXPORTED_SYMBOLS = ["otr"];

var { interfaces: Ci, utils: Cu, classes: Cc } = Components;

Cu.import("resource:///modules/imServices.jsm");
Cu.import("resource:///modules/imXPCOMUtils.jsm");
Cu.import("resource://gre/modules/PromiseWorker.jsm");
Cu.import("resource://gre/modules/ctypes.jsm");
Cu.import("resource://gre/modules/osfile.jsm");
Cu.import("chrome://otr/content/libotr.js");

XPCOMUtils.defineLazyGetter(this, "_", () =>
  l10nHelper("chrome://otr/locale/otr.properties")
);

// some helpers

function setInterval(fn, delay) {
  let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
  timer.init(fn, delay, Ci.nsITimer.TYPE_REPEATING_SLACK);
  return timer;
}

function clearInterval(timer) {
  timer.cancel();
}

function profilePath(filename) {
  return OS.Path.join(OS.Constants.Path.profileDir, filename);
}

// See: https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/Using_js-ctypes/Working_with_data#Determining_if_two_pointers_are_equal
function comparePointers(p, q) {
  p = ctypes.cast(p, ctypes.uintptr_t).value.toString();
  q = ctypes.cast(q, ctypes.uintptr_t).value.toString();
  return p === q;
}

function trustFingerprint(fingerprint) {
  return (!fingerprint.isNull() &&
    !fingerprint.contents.trust.isNull() &&
    fingerprint.contents.trust.readString().length > 0);
}

function getStatus(level) {
  switch(level) {
  case otr.trustState.TRUST_NOT_PRIVATE:
    return _("trust.not_private");
  case otr.trustState.TRUST_UNVERIFIED:
    return _("trust.unverified");
  case otr.trustState.TRUST_PRIVATE:
    return _("trust.private");
  case otr.trustState.TRUST_FINISHED:
    return _("trust.finished");
  }
}

function isOnline(conv) {
  let ret = -1;
  if (conv.buddy)
    ret = conv.buddy.online ? 1 : 0;
  else if (["irc", "twitter"].includes(conv.account.protocol.normalizedName))
    ret = 1;  // no presence, but we want to send the disconnect msg
  return ret;
}

// Use the protocol name in user facing strings. See trac #16490
var names;
function protocolName(aNormalizedName) {
  if (!names) {
    names = new Map();
    let protocols = Services.core.getProtocols();
    while (protocols.hasMoreElements()) {
      let protocol = protocols.getNext();
      names.set(protocol.normalizedName, protocol.name);
    }<commit_msg>Includes requires Gecko 43<commit_after>this.EXPORTED_SYMBOLS = ["otr"];

var { interfaces: Ci, utils: Cu, classes: Cc } = Components;

Cu.import("resource:///modules/imServices.jsm");
Cu.import("resource:///modules/imXPCOMUtils.jsm");
Cu.import("resource://gre/modules/PromiseWorker.jsm");
Cu.import("resource://gre/modules/ctypes.jsm");
Cu.import("resource://gre/modules/osfile.jsm");
Cu.import("chrome://otr/content/libotr.js");

XPCOMUtils.defineLazyGetter(this, "_", () =>
  l10nHelper("chrome://otr/locale/otr.properties")
);

// some helpers

function setInterval(fn, delay) {
  let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
  timer.init(fn, delay, Ci.nsITimer.TYPE_REPEATING_SLACK);
  return timer;
}

function clearInterval(timer) {
  timer.cancel();
}

function profilePath(filename) {
  return OS.Path.join(OS.Constants.Path.profileDir, filename);
}

// See: https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/Using_js-ctypes/Working_with_data#Determining_if_two_pointers_are_equal
function comparePointers(p, q) {
  p = ctypes.cast(p, ctypes.uintptr_t).value.toString();
  q = ctypes.cast(q, ctypes.uintptr_t).value.toString();
  return p === q;
}

function trustFingerprint(fingerprint) {
  return (!fingerprint.isNull() &&
    !fingerprint.contents.trust.isNull() &&
    fingerprint.contents.trust.readString().length > 0);
}

function getStatus(level) {
  switch(level) {
  case otr.trustState.TRUST_NOT_PRIVATE:
    return _("trust.not_private");
  case otr.trustState.TRUST_UNVERIFIED:
    return _("trust.unverified");
  case otr.trustState.TRUST_PRIVATE:
    return _("trust.private");
  case otr.trustState.TRUST_FINISHED:
    return _("trust.finished");
  }
}

function isOnline(conv) {
  let ret = -1;
  if (conv.buddy)
    ret = conv.buddy.online ? 1 : 0;
  else if (["irc", "twitter"].indexOf(conv.account.protocol.normalizedName) > -1)
    ret = 1;  // no presence, but we want to send the disconnect msg
  return ret;
}

// Use the protocol name in user facing strings. See trac #16490
var names;
function protocolName(aNormalizedName) {
  if (!names) {
    names = new Map();
    let protocols = Services.core.getProtocols();
    while (protocols.hasMoreElements()) {
      let protocol = protocols.getNext();
      names.set(protocol.normalizedName, protocol.name);
    }
{'fraction_non_alphanumeric': 0.1568627450980392, 'fraction_numerical': 0.006248653307476837, 'mean_word_length': 4.48051948051948, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 2, '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': '472797', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1614, 'n_words': 280}