<commit_before>(function() {

/**
 * @class Echo.StreamServer.Controls.Stream.Item.Plugins.Like
 * Adds extra controls Like/Unlike to each item in the Echo Stream control. Note that these controls will appear only for authenticated users.
 *
 *     new Echo.StreamServer.Controls.Stream({
 *         "target": document.getElementById("echo-stream"),
 *         "appkey": "test.echoenabled.com",
 *         "plugins": [{
 *             "name": "Like"
 *         }]
 *     });
 *
 * @extends Echo.Plugin
 */
var plugin = Echo.Plugin.manifest("Like", "Echo.StreamServer.Controls.Stream.Item");

plugin.init = function() {
	var self = this;
	this.extendTemplate("insertAsLastChild", "data", plugin.template);
	this.component.addButtonSpec("Like", this._assembleButton("Like"));
	this.component.addButtonSpec("Like", this._assembleButton("Unlike"));
};

plugin.labels = {
	/**
	 * @echo_label
	 */
	"likeThis": " like this.",
	/**
	 * @echo_label
	 */
	"likesThis": " likes this.",
	/**
	 * @echo_label
	 */
	"likeControl": "Like",
	/**
	 * @echo_label
	 */
	"unlikeControl": "Unlike",
	/**
	 * @echo_label
	 */
	"likeProcessing": "Liking...",
	/**
	 * @echo_label
	 */
	"unlikeProcessing": "Unliking..."
};

plugin.events = {
	"Echo.StreamServer.Controls.FacePile.Item.Plugins.Like.onUnlike": function(topic, args) {
		this._sendActivity("Unlike", this.component);
		return {"stop": ["bubble"]};
	}
};

plugin.template = '<div class="{plugin.class:likedBy}"></div>';

plugin.renderers.likedBy = function(element) {
	var plugin = this;
	var item = this.component;
	if (!item.get("data.object.likes").length) {
		return element.hide();
	}
	var likesPerPage = 5;
	var visibleUsersCount = plugin.get("facePile")
		? plugin.get("facePile").getVisibleUsersCount()
		: likesPerPage;
	var youLike = false;
	var userId = item.user.get("id");
	var users = item.get("data.object.likes");
	$.each(users, function(i, like) {
		if (like.actor.id === userId) {
			youLike = true;
			return false; // break
		}
	});
	var config = plugin.config.assemble({
		"target": element.get(0),
		"data": {
			"itemsPerPage": likesPerPage,
			"entries": users
		},
		"initialUsersCount": visibleUsersCount,
		"totalUsersCount": item.get("data.object.accumulators.likesCount"),
		"suffixText": plugin.labels.get(users.length > 1 || youLike ? "likeThis" : "likesThis")
	});
	config.plugins.push({"name": "Like"});
	if (item.user.is("admin")) {
		element.addClass(plugin.cssPrefix + "highlight");
	}
	var facePile = new Echo.StreamServer.Controls.FacePile(config);
	plugin.set("facePile", facePile);
	return element.show();
};

plugin.methods._sendRequest = function(data, callback) {
	Echo.StreamServer.API.request({
		"endpoint": "submit",
		"submissionProxyURL": this.component.config.get("submissionProxyURL"),
		"onData": callback,
		"data": data
	}).send();
};

plugin.methods._sendActivity = function(name, item) {
	var plugin = this;
	var activity = {
		"verbs": ["http://activitystrea.ms/schema/1.0/" + name.toLowerCase()],
		"targets": [{"id": item.get("data.object.id")}]
	};
	this._sendRequest({
		"content": activity,
		"appkey": item.config.get("appkey"),
		"sessionID": item.user.get("sessionID"),
		"target-query": item.config.get("parent.query")
	}, function() {
		/**
		 * @event onLikeComplete
		 * @echo_event Echo.StreamServer.Controls.Stream.Item.Plugins.Like.onLikeComplete
		 * Triggered when the Like operation is finished.
		 */
		/**
		 * @event onUnlikeComplete
		 * @echo_event Echo.StreamServer.Controls.Stream.Item.Plugins.Like.onUnlikeComplete
		 * Triggered when the reverse Like operation is finished.
		 */
		plugin.events.publish({
			"topic": "on" + name + "Complete",
			"data": {
				"item": {
					"data": item.get("data"),
					"target": item.config.get("target")
				}
			}
		});
		plugin.requestDataRefresh();
	});
};

plugin.methods._assembleButton = function(name) {
	var plugin = this;
	var component = this.component;
	var callback = function() {
		var item = this;
		item.get("buttons." + plugin.name + "." + name + ".element")
			.empty()
			.append(plugin.labels.get(name.toLowerCase() + "Processing"));
		plugin._sendActivity(name, item);
	};
	return function() {
		var item = this;
		var action =
			($.map(item.get("data.object.likes"), function(entry) {
				if (item.user.has("identity", entry.actor.id)) return entry;
			})).length > 0 ? "Unlike" : "Like";
		return {
			"name": name,
			"label": plugin.labels.get(name.toLowerCase() + "Control"),
			"visible": item.user.is("logged") && action === name,
			"once": true,
			"callback": callback
		};
	};
};

plugin.css =
	'.{plugin.class:likedBy} { background: url(' + Echo.Loader.getURL("sdk/images/likes.png") + ') no-repeat 0px 4px; padding: 0px 0px 4px 21px; }' +
	'.{plugin.class:highlight} { line-height: 23px; }' +
	($.browser.msie ?
		'.{plugin.class:highlight} span { vertical-align: middle; }' +
		'.{plugin.class:likedBy} { background-position: 0px 2px; }'
		: ''
	);

Echo.Plugin.create(plugin);

})();

(function() {

var plugin = Echo.Plugin.manifest("Like", "Echo.StreamServer.Controls.FacePile.Item");

plugin.labels = {
	"unlikeOnBehalf": "Unlike on behalf of this user"
};

plugin.init = function() {
	this.extendTemplate("insertAsLastChild", "container", plugin.template);
};

plugin.template = '<img class="{plugin.class:adminUnlike}" src="' + Echo.Loader.getURL("sdk/images/container/closeWindow.png") + '" title="{plugin.label:unlikeOnBehalf}" width="10" height="9">';

plugin.component.renderers.container = function(element) {
	this.parentRenderer("container", arguments);
	if (this.component.user.is("admin")) {
		element.addClass(this.cssPrefix + "highlight");
	}
};

plugin.renderers.adminUnlike = function(element) {
	var plugin = this;
	var item = this.component;
	if (!item.user.is("admin")) {
		return element.remove();
	}
	return element.one("click", function() {
		item.dom.get("container").css("opacity", 0.3);
		/**
		 * @event onUnlike
		 * @echo_event Echo.StreamServer.Controls.FacePile.Item.Plugins.Like.onUnlike
		 * Triggered when the item is "unliked" by admin on behalf of a user.
		 */
		plugin.events.publish({
			"topic": "onUnlike",
			"actor": item.get("data"),
			"data": {
				"actor": item.get("data"),<commit_msg>[CR] Like plugin - minor updates<commit_after>(function() {

/**
 * @class Echo.StreamServer.Controls.Stream.Item.Plugins.Like
 * Adds extra controls Like/Unlike to each item in the Echo Stream control. Note that these controls will appear only for authenticated users.
 *
 *     new Echo.StreamServer.Controls.Stream({
 *         "target": document.getElementById("echo-stream"),
 *         "appkey": "test.echoenabled.com",
 *         "plugins": [{
 *             "name": "Like"
 *         }]
 *     });
 *
 * @extends Echo.Plugin
 */
var plugin = Echo.Plugin.manifest("Like", "Echo.StreamServer.Controls.Stream.Item");

plugin.init = function() {
	this.extendTemplate("insertAsLastChild", "data", plugin.template);
	this.component.addButtonSpec("Like", this._assembleButton("Like"));
	this.component.addButtonSpec("Like", this._assembleButton("Unlike"));
};

plugin.labels = {
	/**
	 * @echo_label
	 */
	"likeThis": " like this.",
	/**
	 * @echo_label
	 */
	"likesThis": " likes this.",
	/**
	 * @echo_label
	 */
	"likeControl": "Like",
	/**
	 * @echo_label
	 */
	"unlikeControl": "Unlike",
	/**
	 * @echo_label
	 */
	"likeProcessing": "Liking...",
	/**
	 * @echo_label
	 */
	"unlikeProcessing": "Unliking..."
};

plugin.events = {
	"Echo.StreamServer.Controls.FacePile.Item.Plugins.Like.onUnlike": function(topic, args) {
		this._sendActivity("Unlike", this.component);
		return {"stop": ["bubble"]};
	}
};

plugin.template = '<div class="{plugin.class:likedBy}"></div>';

plugin.renderers.likedBy = function(element) {
	var plugin = this;
	var item = this.component;
	if (!item.get("data.object.likes").length) {
		return element.hide();
	}
	var likesPerPage = 5;
	var visibleUsersCount = plugin.get("facePile")
		? plugin.get("facePile").getVisibleUsersCount()
		: likesPerPage;
	var youLike = false;
	var userId = item.user.get("id");
	var users = item.get("data.object.likes");
	$.each(users, function(i, like) {
		if (like.actor.id === userId) {
			youLike = true;
			return false; // break
		}
	});
	var config = plugin.config.assemble({
		"target": element.get(0),
		"data": {
			"itemsPerPage": likesPerPage,
			"entries": users
		},
		"initialUsersCount": visibleUsersCount,
		"totalUsersCount": item.get("data.object.accumulators.likesCount"),
		"suffixText": plugin.labels.get(users.length > 1 || youLike ? "likeThis" : "likesThis")
	});
	config.plugins.push({"name": "Like"});
	if (item.user.is("admin")) {
		element.addClass(plugin.cssPrefix + "highlight");
	}
	var facePile = new Echo.StreamServer.Controls.FacePile(config);
	plugin.set("facePile", facePile);
	return element.show();
};

plugin.methods._sendRequest = function(data, callback) {
	Echo.StreamServer.API.request({
		"endpoint": "submit",
		"submissionProxyURL": this.component.config.get("submissionProxyURL"),
		"onData": callback,
		"data": data
	}).send();
};

plugin.methods._sendActivity = function(name, item) {
	var plugin = this;
	var activity = {
		"verbs": ["http://activitystrea.ms/schema/1.0/" + name.toLowerCase()],
		"targets": [{"id": item.get("data.object.id")}]
	};
	this._sendRequest({
		"content": activity,
		"appkey": item.config.get("appkey"),
		"sessionID": item.user.get("sessionID"),
		"target-query": item.config.get("parent.query")
	}, function() {
		/**
		 * @event onLikeComplete
		 * @echo_event Echo.StreamServer.Controls.Stream.Item.Plugins.Like.onLikeComplete
		 * Triggered when the Like operation is finished.
		 */
		/**
		 * @event onUnlikeComplete
		 * @echo_event Echo.StreamServer.Controls.Stream.Item.Plugins.Like.onUnlikeComplete
		 * Triggered when the reverse Like operation is finished.
		 */
		plugin.events.publish({
			"topic": "on" + name + "Complete",
			"data": {
				"item": {
					"data": item.get("data"),
					"target": item.config.get("target")
				}
			}
		});
		plugin.requestDataRefresh();
	});
};

plugin.methods._assembleButton = function(name) {
	var plugin = this;
	var callback = function() {
		var item = this;
		item.get("buttons." + plugin.name + "." + name + ".element")
			.empty()
			.append(plugin.labels.get(name.toLowerCase() + "Processing"));
		plugin._sendActivity(name, item);
	};
	return function() {
		var item = this;
		var action =
			($.map(item.get("data.object.likes"), function(entry) {
				if (item.user.has("identity", entry.actor.id)) return entry;
			})).length > 0 ? "Unlike" : "Like";
		return {
			"name": name,
			"label": plugin.labels.get(name.toLowerCase() + "Control"),
			"visible": item.user.is("logged") && action === name,
			"once": true,
			"callback": callback
		};
	};
};

plugin.css =
	'.{plugin.class:likedBy} { background: url(' + Echo.Loader.getURL("sdk/images/likes.png") + ') no-repeat 0px 4px; padding: 0px 0px 4px 21px; }' +
	'.{plugin.class:highlight} { line-height: 23px; }' +
	($.browser.msie ?
		'.{plugin.class:highlight} span { vertical-align: middle; }' +
		'.{plugin.class:likedBy} { background-position: 0px 2px; }'
		: ''
	);

Echo.Plugin.create(plugin);

})();

(function() {

var plugin = Echo.Plugin.manifest("Like", "Echo.StreamServer.Controls.FacePile.Item");

plugin.init = function() {
	this.extendTemplate("insertAsLastChild", "container", plugin.template);
};

plugin.labels = {
	"unlikeOnBehalf": "Unlike on behalf of this user"
};

plugin.template = '<img class="{plugin.class:adminUnlike}" src="' + Echo.Loader.getURL("sdk/images/container/closeWindow.png") + '" title="{plugin.label:unlikeOnBehalf}" width="10" height="9">';

plugin.component.renderers.container = function(element) {
	this.parentRenderer("container", arguments);
	if (this.component.user.is("admin")) {
		element.addClass(this.cssPrefix + "highlight");
	}
};

plugin.renderers.adminUnlike = function(element) {
	var plugin = this;
	var item = this.component;
	if (!item.user.is("admin")) {
		return element.remove();
	}
	return element.one("click", function() {
		item.dom.get("container").css("opacity", 0.3);
		/**
		 * @event onUnlike
		 * @echo_event Echo.StreamServer.Controls.FacePile.Item.Plugins.Like.onUnlike
		 * Triggered when the item is "unliked" by admin on behalf of a user.
		 */
		plugin.events.publish({
			"topic": "onUnlike",
			"actor": item.get("data"),
			"data": {
				"actor": item.get("data"),
{'fraction_non_alphanumeric': 0.1887459807073955, 'fraction_numerical': 0.003536977491961415, 'mean_word_length': 4.057317073170732, 'pattern_counts': {'":': 92, '<': 9, '<?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': '6939718', 'n_tokens_mistral': 4550, 'n_tokens_neox': 4158, 'n_words': 773}