<commit_before>/*
	Copyright (c) 2010, <NAME>
	All rights reserved.

	THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
	WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
	MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
	EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
	PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
	OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
	WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
	OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
	ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

enyo.kind({

name:									"MessageList",
classes:								"messagelist enyo-fit",

published: {
	user:								null,

	resource:							"home",

	refreshTime:						-1,
	notify:								false,
	cache:								false,

	unseen:								0,
	type:								null,
	label:								null,

	/*
		Minimum number of pixels that the list must be pulled down before a
		refresh will be triggered in order to prevent accidental refreshes.
	*/
	minRefreshPixels:					40,

	/* Will be set to true if the panel is in the middle of a refresh already */
	loading:							false
},

events: {
	onRefreshStart:						"",
	onRefreshStop:						"",
	onOpenToaster:						"",
	onActivity:							""
},

handlers: {
	onScroll:							"handleActivity"
},

components: [
	{
		name:							"list",
		kind:							enyo.PulldownList,
		classes:						"enyo-fit",

		ontap:							"itemTap",
		onSetupItem:					"setupItem",
		onSelect:						"setupItem",
		onPullRelease:					"pullRelease",
		onPullComplete:					"pullComplete",

		horizontal:						"hidden",
		vertical:						"scroll",

		thumb:							true,
		enableSwipe:					false,

		noSelect:						false,
		multiSelect:					false,

		preventDragPropagation:			false,
		preventScrollPropagation:		false,

		components: [{
			classes:					"listitem",

			components: [{
				name:					"msg",
				classes:				"hide"
			}, {
				name:					"message",
				kind:					"MessageItem"
			}, {
				name:					"cover",
				classes:				"cover enyo-fit"
			}]
		}]
	}
],

create: function()
{
	this.inherited(arguments);

	this.lastActivity = new Date();

	if (this.user) {
		this.service = this.user.service;
	}

    try {
        var info	= enyo.webOS.deviceInfo();
        var name    = info.modelNameAscii;

        if (name.indexOf("pre")  !== -1 ||
            name.indexOf("veer") !== -1 ||
            name.indexOf("pixi") !== -1)
		{
			/* Attempt to improve scrolling on webOS phones */
			this.$.list.setRowsPerPage(2);
		}
    } catch (e) {
    }

	if (window.android) {
		var strategy;

		this.$.list.setRowsPerPage(20);
		this.$.list.setStrategyKind("TranslateScrollStrategy");

		if ((strategy = this.$.list.getStrategy())) {
			/* This doesn't seem to help...  */
			// strategy.setScrim(true);

			/* This isn't published... */
			strategy.translateOptimized = true;
		}
	}
},

destroy: function()
{
	clearTimeout(this.timeout);

	this.inherited(arguments);
},

rendered: function()
{
	this.inherited(arguments);

	this.results		= [];

	/* Load cached messages */
	var results;

	if (this.cache) {
		/*
			Previous versions stored 2 copies of the messages in some cases. If
			cachedfull is there then use it and remove it from the cache.
		*/
		if ((results = prefs.get('cachedfull:' + this.user.id + ':' + this.resource))) {
			prefs.set('cachedfull:' + this.user.id + ':' + this.resource, null);
			prefs.set('cachedmsgs:' + this.user.id + ':' + this.resource, results);
		}

		results = prefs.get('cachedmsgs:' + this.user.id + ':' + this.resource) || [];
	} else {
		results = [];
	}

	this.service.cleanupMessages(results);

	var cleanupItem = function(item) {
		if (item.media) {
			for (var c = 0, m; m = item.media[i]; i++) {
				if (m.blobthumbnail) {
					delete m.blobthumbnail;
				}
			}
		}

		if (item.user && item.user.blobavatar) {
			delete item.user.blobavatar;<commit_msg>Allow loading even if the message cache is badly broken<commit_after>/*
	Copyright (c) 2010, <NAME>
	All rights reserved.

	THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
	WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
	MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
	EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
	PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
	OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
	WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
	OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
	ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

enyo.kind({

name:									"MessageList",
classes:								"messagelist enyo-fit",

published: {
	user:								null,

	resource:							"home",

	refreshTime:						-1,
	notify:								false,
	cache:								false,

	unseen:								0,
	type:								null,
	label:								null,

	/*
		Minimum number of pixels that the list must be pulled down before a
		refresh will be triggered in order to prevent accidental refreshes.
	*/
	minRefreshPixels:					40,

	/* Will be set to true if the panel is in the middle of a refresh already */
	loading:							false
},

events: {
	onRefreshStart:						"",
	onRefreshStop:						"",
	onOpenToaster:						"",
	onActivity:							""
},

handlers: {
	onScroll:							"handleActivity"
},

components: [
	{
		name:							"list",
		kind:							enyo.PulldownList,
		classes:						"enyo-fit",

		ontap:							"itemTap",
		onSetupItem:					"setupItem",
		onSelect:						"setupItem",
		onPullRelease:					"pullRelease",
		onPullComplete:					"pullComplete",

		horizontal:						"hidden",
		vertical:						"scroll",

		thumb:							true,
		enableSwipe:					false,

		noSelect:						false,
		multiSelect:					false,

		preventDragPropagation:			false,
		preventScrollPropagation:		false,

		components: [{
			classes:					"listitem",

			components: [{
				name:					"msg",
				classes:				"hide"
			}, {
				name:					"message",
				kind:					"MessageItem"
			}, {
				name:					"cover",
				classes:				"cover enyo-fit"
			}]
		}]
	}
],

create: function()
{
	this.inherited(arguments);

	this.lastActivity = new Date();

	if (this.user) {
		this.service = this.user.service;
	}

    try {
        var info	= enyo.webOS.deviceInfo();
        var name    = info.modelNameAscii;

        if (name.indexOf("pre")  !== -1 ||
            name.indexOf("veer") !== -1 ||
            name.indexOf("pixi") !== -1)
		{
			/* Attempt to improve scrolling on webOS phones */
			this.$.list.setRowsPerPage(2);
		}
    } catch (e) {
    }

	if (window.android) {
		var strategy;

		this.$.list.setRowsPerPage(20);
		this.$.list.setStrategyKind("TranslateScrollStrategy");

		if ((strategy = this.$.list.getStrategy())) {
			/* This doesn't seem to help...  */
			// strategy.setScrim(true);

			/* This isn't published... */
			strategy.translateOptimized = true;
		}
	}
},

destroy: function()
{
	clearTimeout(this.timeout);

	this.inherited(arguments);
},

rendered: function()
{
	this.inherited(arguments);

	this.results		= [];

	/* Load cached messages */
	var results;

	if (this.cache) {
		/*
			Previous versions stored 2 copies of the messages in some cases. If
			cachedfull is there then use it and remove it from the cache.
		*/
		if ((results = prefs.get('cachedfull:' + this.user.id + ':' + this.resource))) {
			prefs.set('cachedfull:' + this.user.id + ':' + this.resource, null);
			prefs.set('cachedmsgs:' + this.user.id + ':' + this.resource, results);
		}

		results = prefs.get('cachedmsgs:' + this.user.id + ':' + this.resource) || [];
	} else {
		results = [];
	}

	try {
		this.service.cleanupMessages(results);
	} catch (e) {
		/* Throw away the cached items if cleaning them fails */
		console.log('Throwing away cached messages that can not be cleaned', e);
		results = [];
	}

	var cleanupItem = function(item) {
		if (item.media) {
			for (var c = 0, m; m = item.media[i]; i++) {
				if (m.blobthumbnail) {
					delete m.blobthumbnail;
				}
			}
		}

		if (item.user && item.user.blobavatar) {
			delete item.user.blobavatar;
{'fraction_non_alphanumeric': 0.1294131679389313, 'fraction_numerical': 0.003816793893129771, 'mean_word_length': 2.7101769911504423, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4590694', 'n_tokens_mistral': 3476, 'n_tokens_neox': 2786, 'n_words': 785}