Chat is a complex widget created with Webix Jet, the MV* framework for Webix Library. It is a ready-to-use application with minimum configuration settings but has API for redefining the logic of inner modules.
You will need to study the source code to customize views and models.
Chat is built as a Jet App and wrapped into a Webix view, so you can initialize it in either of the ways.
The interface of Chat is split into parts (views). Each view is a class that extends the JetView class and has own handlers for setting the configuration and logic.
The sources for interface parts (Jet Views) are located in the sources/views folder.
views
chats.js
list.js
messages
toolbar.js
...
Go to the Class Map page to see the list of all Jet views in Chat and where they are in the interface.
Chat models contain the logic for loading and storing data, uploading avatars, working with templates etc. They are defined as Jet Services.
The sources for models (Jet Services) are located in the sources/models folder.
models
Backend.js
Helpers.js
Local.js
Operations.js
Upload.js
Emojis.js
VoiceMessages.js
Service methods are called by the UI and can be called by a programmer as:
$$('myChat').getService('helpers').listAvatar(user, cssClass);
Firstly, create your own view class and inherit it from one of the default views or from chat.views.JetView:
class CustomToolbar extends chat.views['messages/toolbar'] {
config() {
//get JSON object with configuration
const ui = super.config();
//exact changes depend on a particular view
ui.height = 60;
return ui;
}
init() {
// call default logic
super.init();
// custom logic below
this.doSomething();
}
doSomething() {
// do something on init
}
}
Secondly, replace the default view via the override map:
webix.ui({
view: 'chat',
url: 'https://docs.webix.com/chat-backend/',
override: new Map([[chat.views['messages/toolbar'], CustomToolbar]]),
});
To add custom content to the toolbar take the following steps:
1. Create a new class and inherit it from the default chat.views["messages/toolbar"] one.
2. Redefine the TitleTemplate method so that it returns the desired content.
class CustomToolbar extends chat.views['messages/toolbar'] {
TitleTemplate(chat) {
var helpers = this.app.getService('helpers');
// getting avatar
var result = helpers.listAvatar(chat, 'webix_chat_toolbar_avatar');
return (
result +
`
<div class='webix_chat_title'>
<div class="webix_chat_messages_groupchat_name">${chat.name}</div>
<div class="webix_chat_messages_groupchat_members">
Custom content here
</div>
</div>`
);
}
}
3. Then, replace the default class with a custom one via the override map:
webix.ui({
view: 'chat',
override: new Map([[chat.views['messages/toolbar'], CustomToolbar]]),
// other properties
});
Related sample: Chat: Custom Toolbar Content
You can find more use cases in the How-tos article.
Notes
1. We do not recommend to remove any component from the interface as the inner logic might still try accessing it. Instead, hide the components.
class CustomToolbar extends chat.views.sidebar {
init(view) {
// preserving default logic
super.init();
// removing components can cause errors
// hiding components is safe
this.$$('search').hide();
}
}
2. You can access component instances within a Jet view by:
It works for an inner component that is assigned the localId setting.
init(view) {
// preserving default logic
super.init();
// removing components can cause errors
// hiding components is safe
this.$$("search").hide();
}
init(view) {
// default logic
super.init();
// get instance of the search input
view.queryView("chat-search").hide();
}
3. You can find out whether the app is currently compact from any view or service method as:
const compact = this.getParam('compact', true);
4. You can get state properties from any view or service method as:
const state = this.app.getState();
// or
const state = this.getParam('state');
Firstly, create your own service class and inherit it from one of the default services:
class MyBackend extends chat.services.backend {
chats() {
// client-side data
return webix.promise.resolve(chats);
}
}
Secondly, replace the default service via the override map:
{
view: "chat",
url:"https://docs.webix.com/chat-backend/",
override: new Map([
[chat.services.Backend, MyBackend]
])
}
Related sample: Chat: Local Data
You can find more information about Chat Backend service in the Working with Server article.
Chat is extremely flexible when it comes to customizations: you can change almost anything in it. However, keep in mind the following:
Code for Edge Сhromium must be with different syntax.