<commit_before>messages = new Meteor.Collection 'messages'

allMessages = messages.find {}

latestMessage = messages.find {}, { sort: { $natural: -1 }, limit: 1 }

messages.isValid = (message) -> typeof message is 'string' and message.length <= 70

messages.add = (message) -> if @isValid message then @insert message: message, isRead: false

if Meteor.is_server
	Meteor.publish 'messages', -> latestMessage
else
	Meteor.subscribe 'messages'

	allMessages.observe added: (msg) -> if not msg.isRead then speak msg.message, speed: 140, pitch: 30, wordgap: 10
	
	getMessage = -> messages.findOne {}

	isRead = -> not getMessage() or getMessage().isRead

	addMessage = ->
		textbox = document.getElementById 'textbox'
		if isRead() and messages.add textbox.value then textbox.value = ''

	_.extend Template.main,
		messages: -> allMessages
		inputClassName: -> if isRead() then 'read' else 'unread'
		events:
			'click button': addMessage
			'keypress input': (e) -> addMessage() if e.which is 13

	_.extend Template.message,
		className: -> if @isRead then 'read' else 'unread'
		events: click: -> messages.update this, $set: isRead: true<commit_msg>Support latest meteorjs<commit_after>messages = new Meteor.Collection 'messages'

allMessages = messages.find {}

latestMessage = messages.find {}, { sort: { $natural: -1 }, limit: 1 }

messages.isValid = (message) -> typeof message is 'string' and message.length <= 70

messages.add = (message) -> if @isValid message then @insert message: message, isRead: false

messages.allow
  insert: (userId, doc) ->
    true

if Meteor.isServer
	Meteor.publish 'messages', -> latestMessage

if Meteor.isClient
	Meteor.subscribe 'messages'

	allMessages.observe added: (msg) -> if not msg.isRead then speak msg.message, speed: 140, pitch: 30, wordgap: 10

	getMessage = -> messages.findOne {}

	isRead = -> not getMessage() or getMessage().isRead

	addMessage = ->
		textbox = document.getElementById 'textbox'
		if isRead() and messages.add textbox.value then textbox.value = ''

	_.extend Template.main,
		messages: -> allMessages
		inputClassName: -> if isRead() then 'read' else 'unread'
		events:
			'click button': addMessage
			'keypress input': (e) -> addMessage() if e.which is 13

	_.extend Template.message,
		className: -> if @isRead then 'read' else 'unread'
		events: click: -> messages.update this, $set: isRead: true

{'fraction_non_alphanumeric': 0.12995780590717299, 'fraction_numerical': 0.010970464135021098, 'mean_word_length': 4.143167028199566, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '3898960', 'n_tokens_mistral': 784, 'n_tokens_neox': 718, 'n_words': 233}