mirror of
				https://github.com/Mibew/design.git
				synced 2025-10-31 18:41:05 +03:00 
			
		
		
		
	Force set plugin message id in Chat JS application
This commit is contained in:
		
							parent
							
								
									d77047f62c
								
							
						
					
					
						commit
						7c648ce829
					
				| @ -5,6 +5,6 @@ | ||||
|  Copyright (c) 2005-2011 Mibew Messenger Community | ||||
|  License: http://mibew.org/license.php
 | ||||
| */ | ||||
| (function(c,d,h){c.Collections.Messages=d.Collection.extend({model:c.Models.Message,initialize:function(){this.periodicallyCalled=[];this.periodicallyCalled.push(c.Objects.server.callFunctionsPeriodically(h.bind(this.updateMessagesFunctionBuilder,this),h.bind(this.updateMessages,this)))},finalize:function(){for(var a=0;a<this.periodicallyCalled.length;a++)c.Objects.server.stopCallFunctionsPeriodically(this.periodicallyCalled[a])},updateMessages:function(a){a.lastId&&c.Objects.Models.thread.set({lastId:a.lastId}); | ||||
| for(var j=c.Models.Message.prototype.KIND_PLUGIN,f=[],b,e,g=0,d=a.messages.length;g<d;g++)b=a.messages[g],b.kind!=j?f.push(new c.Models.Message(b)):"object"!=typeof b.message||null===b.message||(e=b.message.plugin||!1,e="process:"+(!1!==e?e+":":"")+"plugin:message",b={messageData:b,model:!1},this.trigger(e,b),b.model&&f.push(b.model));0<f.length&&this.add(f)},updateMessagesFunctionBuilder:function(){var a=c.Objects.Models.thread,d=c.Objects.Models.user;return[{"function":"updateMessages",arguments:{"return":{messages:"messages", | ||||
| lastId:"lastId"},references:{},threadId:a.get("id"),token:a.get("token"),lastId:a.get("lastId"),user:!d.get("isAgent")}}]},add:function(){var a=Array.prototype.slice.apply(arguments),a=d.Collection.prototype.add.apply(this,a);this.trigger("multiple:add");return a}})})(Mibew,Backbone,_); | ||||
| (function(b,d,j){b.Collections.Messages=d.Collection.extend({model:b.Models.Message,initialize:function(){this.periodicallyCalled=[];this.periodicallyCalled.push(b.Objects.server.callFunctionsPeriodically(j.bind(this.updateMessagesFunctionBuilder,this),j.bind(this.updateMessages,this)))},finalize:function(){for(var a=0;a<this.periodicallyCalled.length;a++)b.Objects.server.stopCallFunctionsPeriodically(this.periodicallyCalled[a])},updateMessages:function(a){a.lastId&&b.Objects.Models.thread.set({lastId:a.lastId}); | ||||
| for(var k=b.Models.Message.prototype.KIND_PLUGIN,g=[],c,f,e,h=0,d=a.messages.length;h<d;h++)c=a.messages[h],c.kind!=k?g.push(new b.Models.Message(c)):"object"!=typeof c.message||null===c.message||(f=c.message.plugin||!1,f="process:"+(!1!==f?f+":":"")+"plugin:message",e={messageData:c,model:!1},this.trigger(f,e),e.model&&(e.model.get("id")||e.model.set({id:c.id}),g.push(e.model)));0<g.length&&this.add(g)},updateMessagesFunctionBuilder:function(){var a=b.Objects.Models.thread,d=b.Objects.Models.user; | ||||
| return[{"function":"updateMessages",arguments:{"return":{messages:"messages",lastId:"lastId"},references:{},threadId:a.get("id"),token:a.get("token"),lastId:a.get("lastId"),user:!d.get("isAgent")}}]},add:function(){var a=Array.prototype.slice.apply(arguments),a=d.Collection.prototype.add.apply(this,a);this.trigger("multiple:add");return a}})})(Mibew,Backbone,_); | ||||
|  | ||||
| @ -141,9 +141,9 @@ groupId:a.get("groupId"),name:a.get("name"),info:a.get("info"),email:a.get("emai | ||||
|  Copyright (c) 2005-2011 Mibew Messenger Community | ||||
|  License: http://mibew.org/license.php
 | ||||
| */ | ||||
| (function(c,d,h){c.Collections.Messages=d.Collection.extend({model:c.Models.Message,initialize:function(){this.periodicallyCalled=[];this.periodicallyCalled.push(c.Objects.server.callFunctionsPeriodically(h.bind(this.updateMessagesFunctionBuilder,this),h.bind(this.updateMessages,this)))},finalize:function(){for(var a=0;a<this.periodicallyCalled.length;a++)c.Objects.server.stopCallFunctionsPeriodically(this.periodicallyCalled[a])},updateMessages:function(a){a.lastId&&c.Objects.Models.thread.set({lastId:a.lastId}); | ||||
| for(var j=c.Models.Message.prototype.KIND_PLUGIN,f=[],b,e,g=0,d=a.messages.length;g<d;g++)b=a.messages[g],b.kind!=j?f.push(new c.Models.Message(b)):"object"!=typeof b.message||null===b.message||(e=b.message.plugin||!1,e="process:"+(!1!==e?e+":":"")+"plugin:message",b={messageData:b,model:!1},this.trigger(e,b),b.model&&f.push(b.model));0<f.length&&this.add(f)},updateMessagesFunctionBuilder:function(){var a=c.Objects.Models.thread,d=c.Objects.Models.user;return[{"function":"updateMessages",arguments:{"return":{messages:"messages", | ||||
| lastId:"lastId"},references:{},threadId:a.get("id"),token:a.get("token"),lastId:a.get("lastId"),user:!d.get("isAgent")}}]},add:function(){var a=Array.prototype.slice.apply(arguments),a=d.Collection.prototype.add.apply(this,a);this.trigger("multiple:add");return a}})})(Mibew,Backbone,_); | ||||
| (function(b,d,j){b.Collections.Messages=d.Collection.extend({model:b.Models.Message,initialize:function(){this.periodicallyCalled=[];this.periodicallyCalled.push(b.Objects.server.callFunctionsPeriodically(j.bind(this.updateMessagesFunctionBuilder,this),j.bind(this.updateMessages,this)))},finalize:function(){for(var a=0;a<this.periodicallyCalled.length;a++)b.Objects.server.stopCallFunctionsPeriodically(this.periodicallyCalled[a])},updateMessages:function(a){a.lastId&&b.Objects.Models.thread.set({lastId:a.lastId}); | ||||
| for(var k=b.Models.Message.prototype.KIND_PLUGIN,g=[],c,f,e,h=0,d=a.messages.length;h<d;h++)c=a.messages[h],c.kind!=k?g.push(new b.Models.Message(c)):"object"!=typeof c.message||null===c.message||(f=c.message.plugin||!1,f="process:"+(!1!==f?f+":":"")+"plugin:message",e={messageData:c,model:!1},this.trigger(f,e),e.model&&(e.model.get("id")||e.model.set({id:c.id}),g.push(e.model)));0<g.length&&this.add(g)},updateMessagesFunctionBuilder:function(){var a=b.Objects.Models.thread,d=b.Objects.Models.user; | ||||
| return[{"function":"updateMessages",arguments:{"return":{messages:"messages",lastId:"lastId"},references:{},threadId:a.get("id"),token:a.get("token"),lastId:a.get("lastId"),user:!d.get("isAgent")}}]},add:function(){var a=Array.prototype.slice.apply(arguments),a=d.Collection.prototype.add.apply(this,a);this.trigger("multiple:add");return a}})})(Mibew,Backbone,_); | ||||
| /* | ||||
|  This file is part of Mibew Messenger project. | ||||
|  http://mibew.org
 | ||||
|  | ||||
| @ -121,6 +121,12 @@ | ||||
|                     this.trigger(eventName, eventArgs); | ||||
| 
 | ||||
|                     if (eventArgs.model) { | ||||
|                         // Check if plugin set message id
 | ||||
|                         if (! eventArgs.model.get('id')) { | ||||
|                             // Message must have an id, set it
 | ||||
|                             eventArgs.model.set({'id': messageData.id}); | ||||
|                         } | ||||
| 
 | ||||
|                         // Store custom plugin message in the collection
 | ||||
|                         newMessages.push( | ||||
|                             eventArgs.model | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user