<commit_before>Cryptocat.otr = {}
Cryptocat.otr.keys = {}
Cryptocat.otr.fileKeys = {}

Cryptocat.otr.fileSize = 5120 // Maximum encrypted file sharing size, in kilobytes.
Cryptocat.otr.chunkSize = 64511 // Size in which file chunks are split, in bytes.

// Cryptocat OTR functions and callbacks.

// OTR functions:
// Handle incoming messages.
Cryptocat.otr.onIncoming = function(buddy) {
	return function(msg, encrypted) {
		// drop unencrypted messages
		if (encrypted) {
			Cryptocat.addToConversation(msg, buddy, buddy, 'message')
			if (Cryptocat.currentConversation !== buddy) {
				Cryptocat.messagePreview(msg, buddy)
			}
		}
	}
}

// Handle outgoing messages.
Cryptocat.otr.onOutgoing = function(buddy) {
	return function(message) {
		Cryptocat.xmpp.connection.muc.message(
			Cryptocat.conversationName + '@' + Cryptocat.xmpp.conferenceServer,
			buddy, message, null, 'chat', 'active'
		)
	}
}

// Receive an SMP question
Cryptocat.otr.onSMPQuestion = function(nickname, question) {
	$('#dialogBoxClose').click()
	var authRequest = Cryptocat.locale['chatWindow']['authRequest']
		.replace('(NICKNAME)', nickname)
	var answerMustMatch = Cryptocat.locale['chatWindow']['answerMustMatch']
		.replace('(NICKNAME)', nickname)
	window.setTimeout(function() {
		Cryptocat.dialogBox(Mustache.render(Cryptocat.templates.authRequest, {
			authenticate: Cryptocat.locale['chatWindow']['authenticate'],
			authRequest: authRequest,
			answerMustMatch: answerMustMatch,
			question: question,
			answer: Cryptocat.locale['chatWindow']['answer']
		}), 240, false, function() {
			$('#authReplySubmit').unbind('click').bind('click', function(e) {
				e.preventDefault()
				var answer = $('#authReply').val().toLowerCase().replace(/(\s|\.|\,|\'|\"|\;|\?|\!)/, '')
				Cryptocat.otr.keys[nickname].smpSecret(answer)
				$('#dialogBoxClose').click()
			})
		})
	}, 500)
}

// Add a new OTR key for a new conversation participant
Cryptocat.otr.add = function(buddy) {
	Cryptocat.otr.keys[buddy] = new OTR({
		priv: Cryptocat.otr.myKey,
		smw: {<commit_msg>Allow recipients of SMP questions to close dialog without problem<commit_after>Cryptocat.otr = {}
Cryptocat.otr.keys = {}
Cryptocat.otr.fileKeys = {}

Cryptocat.otr.fileSize = 5120 // Maximum encrypted file sharing size, in kilobytes.
Cryptocat.otr.chunkSize = 64511 // Size in which file chunks are split, in bytes.

// Cryptocat OTR functions and callbacks.

// OTR functions:
// Handle incoming messages.
Cryptocat.otr.onIncoming = function(buddy) {
	return function(msg, encrypted) {
		// drop unencrypted messages
		if (encrypted) {
			Cryptocat.addToConversation(msg, buddy, buddy, 'message')
			if (Cryptocat.currentConversation !== buddy) {
				Cryptocat.messagePreview(msg, buddy)
			}
		}
	}
}

// Handle outgoing messages.
Cryptocat.otr.onOutgoing = function(buddy) {
	return function(message) {
		Cryptocat.xmpp.connection.muc.message(
			Cryptocat.conversationName + '@' + Cryptocat.xmpp.conferenceServer,
			buddy, message, null, 'chat', 'active'
		)
	}
}

// Receive an SMP question
Cryptocat.otr.onSMPQuestion = function(nickname, question) {
	$('#dialogBoxClose').click()
	var answer = false
	window.setTimeout(function(nickname) {
		Cryptocat.dialogBox(Mustache.render(Cryptocat.templates.authRequest, {
			authenticate: Cryptocat.locale['chatWindow']['authenticate'],
			authRequest: Cryptocat.locale['chatWindow']['authRequest']
				.replace('(NICKNAME)', nickname),
			answerMustMatch: Cryptocat.locale['chatWindow']['answerMustMatch']
				.replace('(NICKNAME)', nickname),
			question: question,
			answer: Cryptocat.locale['chatWindow']['answer']
		}), 240, true, function() {
			$('#authReplySubmit').unbind('click').bind('click', function(e) {
				e.preventDefault()
				answer = $('#authReply').val().toLowerCase()
					.replace(/(\s|\.|\,|\'|\"|\;|\?|\!)/, '')
				Cryptocat.otr.keys[nickname].smpSecret(answer)
				$('#dialogBoxClose').click()
			})
		}, function() {
			if (!answer) { Cryptocat.otr.keys[nickname].smpSecret('noAnswer') }
		})
	}, 500, nickname)
}

// Add a new OTR key for a new conversation participant
Cryptocat.otr.add = function(buddy) {
	Cryptocat.otr.keys[buddy] = new OTR({
		priv: Cryptocat.otr.myKey,
		smw: {
{'fraction_non_alphanumeric': 0.16065495965828192, 'fraction_numerical': 0.007119126720455624, 'mean_word_length': 4.553359683794467, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4190227', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1428, 'n_words': 265}