Several updates.
This commit is contained in:
		
							parent
							
								
									17bb88050a
								
							
						
					
					
						commit
						54d7d5b74e
					
				| @ -13,6 +13,10 @@ class ChannelModel(BaseModel): | ||||
|     last_message_on = ModelField(name="last_message_on", required=False, kind=str) | ||||
|     history_start = ModelField(name="history_start", required=False, kind=str) | ||||
|      | ||||
|     @property | ||||
|     def is_dm(self): | ||||
|         return 'dm' in self['tag'].lower() | ||||
| 
 | ||||
|     async def get_last_message(self) -> ChannelMessageModel: | ||||
|         history_start_filter = "" | ||||
|         if self["history_start"]: | ||||
|  | ||||
| @ -1,5 +1,3 @@ | ||||
| 
 | ||||
| 
 | ||||
| class RestClient { | ||||
|   constructor({ baseURL = '', headers = {} } = {}) { | ||||
|     this.baseURL = baseURL; | ||||
| @ -210,27 +208,52 @@ class Njet extends HTMLElement { | ||||
|         customElements.define(name, component); | ||||
|     } | ||||
| 
 | ||||
|     constructor() { | ||||
|     constructor(config) { | ||||
|         super(); | ||||
|         // Store the config for use in render and other methods
 | ||||
|         this.config = config || {}; | ||||
|          | ||||
|         if (!Njet._root) { | ||||
|             Njet._root = this | ||||
|             Njet._rest = new RestClient({ baseURL: '/' || null }) | ||||
|         } | ||||
|         this.root._elements.push(this) | ||||
|         this.classList.add('njet'); | ||||
|          | ||||
|         // Initialize properties from config before rendering
 | ||||
|         this.initProps(this.config); | ||||
|          | ||||
|         // Call render after properties are initialized
 | ||||
|         this.render.call(this); | ||||
|         //this.initProps(config);
 | ||||
|         //if (typeof this.config.construct === 'function')
 | ||||
|         //    this.config.construct.call(this)
 | ||||
|          | ||||
|         // Call construct if defined
 | ||||
|         if (typeof this.config.construct === 'function') { | ||||
|             this.config.construct.call(this) | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     initProps(config) { | ||||
|         const props = Object.keys(config) | ||||
|         props.forEach(prop => { | ||||
|             if (config[prop] !== undefined) { | ||||
|             // Skip special properties that are handled separately
 | ||||
|             if (['construct', 'items', 'classes'].includes(prop)) { | ||||
|                 return; | ||||
|             } | ||||
|              | ||||
|             // Check if there's a setter for this property
 | ||||
|             const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this), prop); | ||||
|             if (descriptor && descriptor.set) { | ||||
|                 // Use the setter
 | ||||
|                 this[prop] = config[prop]; | ||||
|             } else if (prop in this) { | ||||
|                 // Property exists, set it directly
 | ||||
|                 this[prop] = config[prop]; | ||||
|             } else { | ||||
|                 // Set as attribute for unknown properties
 | ||||
|                 this.setAttribute(prop, config[prop]); | ||||
|             } | ||||
|         }); | ||||
|          | ||||
|         if (config.classes) { | ||||
|             this.classList.add(...config.classes); | ||||
|         } | ||||
| @ -342,7 +365,7 @@ class NjetDialog extends Component { | ||||
|         const buttonContainer = document.createElement('div'); | ||||
|         buttonContainer.style.marginTop = '20px'; | ||||
|         buttonContainer.style.display = 'flex'; | ||||
|         buttonContainer.style.justifyContent = 'flenjet-end'; | ||||
|         buttonContainer.style.justifyContent = 'flex-end'; | ||||
|         buttonContainer.style.gap = '10px'; | ||||
|         if (secondaryButton) { | ||||
|             const secondary = new NjetButton(secondaryButton); | ||||
| @ -372,8 +395,9 @@ class NjetWindow extends Component { | ||||
|             header.textContent = title; | ||||
|             this.appendChild(header); | ||||
|         } | ||||
|         this.config.items.forEach(item => this.appendChild(item));  | ||||
|        | ||||
|         if (this.config.items) { | ||||
|             this.config.items.forEach(item => this.appendChild(item)); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     show(){ | ||||
| @ -408,7 +432,8 @@ class NjetGrid extends Component { | ||||
|     } | ||||
| } | ||||
| Njet.registerComponent('njet-grid', NjetGrid); | ||||
| /* | ||||
| 
 | ||||
| /* Example usage: | ||||
| const button = new NjetButton({ | ||||
|     classes: ['my-button'], | ||||
|     text: 'Shared', | ||||
| @ -493,7 +518,7 @@ document.body.appendChild(dialog); | ||||
| */ | ||||
| 
 | ||||
| class NjetComponent extends Component {} | ||||
|     const njet = Njet | ||||
| const njet = Njet | ||||
| njet.showDialog = function(args){ | ||||
|     const dialog = new NjetDialog(args)  | ||||
|     dialog.show() | ||||
| @ -545,15 +570,16 @@ njet.showWindow = function(args) { | ||||
|     return w | ||||
| } | ||||
| njet.publish = function(event, data) { | ||||
|     if (this.root._subscriptions[event]) { | ||||
|     if (this.root && this.root._subscriptions && this.root._subscriptions[event]) { | ||||
|         this.root._subscriptions[event].forEach(callback => callback(data)) | ||||
|     } | ||||
| } | ||||
| njet.subscribe = function(event, callback) { | ||||
|     if (!this.root) return; | ||||
|     if (!this.root._subscriptions[event]) { | ||||
|         this.root._subscriptions[event] = [] | ||||
|     } | ||||
|     this.root._subscriptions[event].push(callback) | ||||
| } | ||||
| 
 | ||||
| export { Njet, NjetButton, NjetPanel, NjetDialog, NjetGrid, NjetComponent, njet, NjetWindow,eventBus }; | ||||
| export { Njet, NjetButton, NjetPanel, NjetDialog, NjetGrid, NjetComponent, njet, NjetWindow, eventBus }; | ||||
|  | ||||
| @ -12,7 +12,7 @@ function showTerm(options){ | ||||
| 
 | ||||
| 
 | ||||
| class StarField { | ||||
|   constructor({ count = 200, container = document.body } = {}) { | ||||
|   constructor({ count = 100, container = document.body } = {}) { | ||||
|     this.container = container; | ||||
|     this.starCount = count; | ||||
|     this.stars = []; | ||||
| @ -567,7 +567,7 @@ const count = Array.from(messages).filter(el => el.textContent.trim() === text). | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| const starField = new StarField({starCount: 200}); | ||||
| const starField = new StarField({starCount: 100}); | ||||
| app.starField = starField; | ||||
| 
 | ||||
| class DemoSequence { | ||||
|  | ||||
| @ -55,7 +55,7 @@ class WebView(BaseView): | ||||
|             user_uid=self.session.get("uid"), channel_uid=channel["uid"] | ||||
|         ) | ||||
|         if not channel_member: | ||||
|             if not channel["is_private"]: | ||||
|             if not channel["is_private"] and not channel.is_dm: | ||||
|                 channel_member = await self.app.services.channel_member.create( | ||||
|                     channel_uid=channel["uid"], | ||||
|                     user_uid=self.session.get("uid"), | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user