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) |     last_message_on = ModelField(name="last_message_on", required=False, kind=str) | ||||||
|     history_start = ModelField(name="history_start", 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: |     async def get_last_message(self) -> ChannelMessageModel: | ||||||
|         history_start_filter = "" |         history_start_filter = "" | ||||||
|         if self["history_start"]: |         if self["history_start"]: | ||||||
|  | |||||||
| @ -1,5 +1,3 @@ | |||||||
| 
 |  | ||||||
| 
 |  | ||||||
| class RestClient { | class RestClient { | ||||||
|   constructor({ baseURL = '', headers = {} } = {}) { |   constructor({ baseURL = '', headers = {} } = {}) { | ||||||
|     this.baseURL = baseURL; |     this.baseURL = baseURL; | ||||||
| @ -210,27 +208,52 @@ class Njet extends HTMLElement { | |||||||
|         customElements.define(name, component); |         customElements.define(name, component); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     constructor() { |     constructor(config) { | ||||||
|         super(); |         super(); | ||||||
|  |         // Store the config for use in render and other methods
 | ||||||
|  |         this.config = config || {}; | ||||||
|  |          | ||||||
|         if (!Njet._root) { |         if (!Njet._root) { | ||||||
|             Njet._root = this |             Njet._root = this | ||||||
|             Njet._rest = new RestClient({ baseURL: '/' || null }) |             Njet._rest = new RestClient({ baseURL: '/' || null }) | ||||||
|         } |         } | ||||||
|         this.root._elements.push(this) |         this.root._elements.push(this) | ||||||
|         this.classList.add('njet'); |         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.render.call(this); | ||||||
|         //this.initProps(config);
 |          | ||||||
|         //if (typeof this.config.construct === 'function')
 |         // Call construct if defined
 | ||||||
|         //    this.config.construct.call(this)
 |         if (typeof this.config.construct === 'function') { | ||||||
|  |             this.config.construct.call(this) | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     initProps(config) { |     initProps(config) { | ||||||
|         const props = Object.keys(config) |         const props = Object.keys(config) | ||||||
|         props.forEach(prop => { |         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]; |                 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) { |         if (config.classes) { | ||||||
|             this.classList.add(...config.classes); |             this.classList.add(...config.classes); | ||||||
|         } |         } | ||||||
| @ -342,7 +365,7 @@ class NjetDialog extends Component { | |||||||
|         const buttonContainer = document.createElement('div'); |         const buttonContainer = document.createElement('div'); | ||||||
|         buttonContainer.style.marginTop = '20px'; |         buttonContainer.style.marginTop = '20px'; | ||||||
|         buttonContainer.style.display = 'flex'; |         buttonContainer.style.display = 'flex'; | ||||||
|         buttonContainer.style.justifyContent = 'flenjet-end'; |         buttonContainer.style.justifyContent = 'flex-end'; | ||||||
|         buttonContainer.style.gap = '10px'; |         buttonContainer.style.gap = '10px'; | ||||||
|         if (secondaryButton) { |         if (secondaryButton) { | ||||||
|             const secondary = new NjetButton(secondaryButton); |             const secondary = new NjetButton(secondaryButton); | ||||||
| @ -372,8 +395,9 @@ class NjetWindow extends Component { | |||||||
|             header.textContent = title; |             header.textContent = title; | ||||||
|             this.appendChild(header); |             this.appendChild(header); | ||||||
|         } |         } | ||||||
|  |         if (this.config.items) { | ||||||
|             this.config.items.forEach(item => this.appendChild(item)); |             this.config.items.forEach(item => this.appendChild(item)); | ||||||
|        |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     show(){ |     show(){ | ||||||
| @ -408,7 +432,8 @@ class NjetGrid extends Component { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| Njet.registerComponent('njet-grid', NjetGrid); | Njet.registerComponent('njet-grid', NjetGrid); | ||||||
| /* | 
 | ||||||
|  | /* Example usage: | ||||||
| const button = new NjetButton({ | const button = new NjetButton({ | ||||||
|     classes: ['my-button'], |     classes: ['my-button'], | ||||||
|     text: 'Shared', |     text: 'Shared', | ||||||
| @ -545,11 +570,12 @@ njet.showWindow = function(args) { | |||||||
|     return w |     return w | ||||||
| } | } | ||||||
| njet.publish = function(event, data) { | 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)) |         this.root._subscriptions[event].forEach(callback => callback(data)) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| njet.subscribe = function(event, callback) { | njet.subscribe = function(event, callback) { | ||||||
|  |     if (!this.root) return; | ||||||
|     if (!this.root._subscriptions[event]) { |     if (!this.root._subscriptions[event]) { | ||||||
|         this.root._subscriptions[event] = [] |         this.root._subscriptions[event] = [] | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -12,7 +12,7 @@ function showTerm(options){ | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class StarField { | class StarField { | ||||||
|   constructor({ count = 200, container = document.body } = {}) { |   constructor({ count = 100, container = document.body } = {}) { | ||||||
|     this.container = container; |     this.container = container; | ||||||
|     this.starCount = count; |     this.starCount = count; | ||||||
|     this.stars = []; |     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; | app.starField = starField; | ||||||
| 
 | 
 | ||||||
| class DemoSequence { | class DemoSequence { | ||||||
|  | |||||||
| @ -55,7 +55,7 @@ class WebView(BaseView): | |||||||
|             user_uid=self.session.get("uid"), channel_uid=channel["uid"] |             user_uid=self.session.get("uid"), channel_uid=channel["uid"] | ||||||
|         ) |         ) | ||||||
|         if not channel_member: |         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_member = await self.app.services.channel_member.create( | ||||||
|                     channel_uid=channel["uid"], |                     channel_uid=channel["uid"], | ||||||
|                     user_uid=self.session.get("uid"), |                     user_uid=self.session.get("uid"), | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user