<commit_before>import require \prelude-ls

require! {
	'./is-null'
	'../models/talk-message': TalkMessage
}

$or = (a, b) --> $or: [a, b]
$and = (a, b) --> $and: [a, b]

# Number -> Number -> Number -> Number -> Number -> Promise [Message]
exports = (me-id, otherparty-id, limit, since-id, max-id) ->
	resolve, reject <- new Promise!
	
	base-query = ({user-id: me-id} `$and` {otherparty-id}) `$or` ({user-id: otherparty-id} `$and` {otherparty-id: me-id})
	
	query = | all is-null, [since-id, max-id] => base-query
		| since-id? => base-query `$and` {id: {$gt: since-id}}
		| max-id? => base-query `$and` {id: {$lt: max-id}}

	err, messages <- TalkMessage.find query .sort \-created-at .limit limit .exec
	
	if err?
		then reject err
		else resolve messages
<commit_msg>Improve readability<commit_after>import require \prelude-ls
import require './mongoose-query'

require! {
	'./is-null'
	'../models/talk-message': TalkMessage
}

# Number -> Number -> Number -> Number -> Number -> Promise [Message]
exports = (me-id, otherparty-id, limit, since-id, max-id) ->
	resolve, reject <- new Promise!
	
	base-query = ({user-id: me-id} `$and` {otherparty-id}) `$or` ({user-id: otherparty-id} `$and` {otherparty-id: me-id})
	
	query = | all is-null, [since-id, max-id] => base-query
		| since-id? => base-query `$and` {id: {$gt: since-id}}
		| max-id? => base-query `$and` {id: {$lt: max-id}}

	err, messages <- TalkMessage.find query .sort \-created-at .limit limit .exec
	
	if err?
		then reject err
		else resolve messages

{'fraction_non_alphanumeric': 0.2063282794990112, 'fraction_numerical': 0.0, 'mean_word_length': 3.324786324786325, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, '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': '4854235', 'n_tokens_mistral': 593, 'n_tokens_neox': 564, 'n_words': 156}