<commit_before>import {IUser, ITalkMessage, ITalkUserMessage, ITalkGroupMessage} from '../interfaces';
import publishStream from './publish-streaming-message';

function isUserMessage(message: ITalkMessage): message is ITalkUserMessage {
	'use strict';
	return message.type === 'user-message';
}

function isGroupMessage(message: ITalkMessage): message is ITalkGroupMessage {
	'use strict';
	return message.type === 'group-message';
}

/**
 * メッセージを既読にします
 * @param me ユーザー
 * @param message 対象のメッセージ
 */
export default function(
	me: IUser,
	message: ITalkMessage
): Promise<void> {
	'use strict';

	return new Promise<void>((resolve, reject) => {
		if (isUserMessage(message)) {
			if (message.user.toString() === me.id.toString()) {
				return reject('is-me');
			}

			const otherpartyId: string = typeof message.user === 'string'
				? message.user
				: (<any>message.user).id;

			message.isRead = true;
			message.save();

			// Publish stream message
			publishStream(`talk-user-stream:${otherpartyId}-${me.id}`, JSON.stringify({
				type: 'read',
				value: message.id
			}));
		} else if (isGroupMessage(message)) {
			if (message.user.toString() === me.id.toString()) {
				return reject('is-me');
			}

			(<string[]>message.reads).push(me.id);
			message.save();

			// Publish stream message
			publishStream(`talk-group-stream:${message.group}`, JSON.stringify({
				type: 'read',
				value: message.id
			}));
		} else {
			resolve();
		}
	});
}<commit_msg>Fix bug<commit_after>import {IUser, ITalkMessage, ITalkUserMessage, ITalkGroupMessage} from '../interfaces';
import publishStream from './publish-streaming-message';

function isUserMessage(message: ITalkMessage): message is ITalkUserMessage {
	'use strict';
	return message.type === 'user-message';
}

function isGroupMessage(message: ITalkMessage): message is ITalkGroupMessage {
	'use strict';
	return message.type === 'group-message';
}

/**
 * メッセージを既読にします
 * @param me ユーザー
 * @param message 対象のメッセージ
 */
export default function(
	me: IUser,
	message: ITalkMessage
): Promise<void> {
	'use strict';

	return new Promise<void>((resolve, reject) => {
		if (isUserMessage(message)) {
			if (message.user.toString() === me.id.toString()) {
				return reject('is-me');
			}

			const otherpartyId: string = <string>message.user;

			message.isRead = true;
			message.save();

			// Publish stream message
			publishStream(`talk-user-stream:${otherpartyId}-${me.id}`, JSON.stringify({
				type: 'read',
				value: message.id
			}));
		} else if (isGroupMessage(message)) {
			if (message.user.toString() === me.id.toString()) {
				return reject('is-me');
			}

			(<string[]>message.reads).push(me.id);
			message.save();

			// Publish stream message
			publishStream(`talk-group-stream:${message.group}`, JSON.stringify({
				type: 'read',
				value: message.id
			}));
		} else {
			resolve();
		}
	});
}
{'fraction_non_alphanumeric': 0.16655100624566274, 'fraction_numerical': 0.0, 'mean_word_length': 3.9878892733564015, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '7195197', 'n_tokens_mistral': 1082, 'n_tokens_neox': 953, 'n_words': 201}