B4J Tutorial [BANanoWebix] Lesson 17 - Comments / Chat Widget

Hi

The comments widget works like a chat screen. Now I need to learn BANanoWebsockets and feed that into this.

Lesson17.gif


One of the nice things about this component is that the users data, the comments can be hosted and fed directly from any source type of data. For example in our example, we have saved everything in a JS file and added this to our project with BANano.Header.AddJavascriptFile

B4X:
BANano.Header.AddJavascriptFile("data.js")

This data file has 'var' definitions for the various arrays we need for this example.

data.png


As these are global variables, what we did was to have javascript functions defined to be able to return the contents of the arrays.

B4X:
#if javascript
    function getUsers(){
        return usersData;
    }
    
    function getComments(){
        return commentsData;
    }
#End If

In Row 1 we have added our toolbar, so we create a new row and insert our WixComment element there. As you will note, there is nothing much to set here.

As the current user, .SetCurrentUser(?) is needed to ensure that you are easily identified. Each user can have a status set to indicate online activity.

B4X:
Dim R2 As WixRow
    R2.Initialize("R2")
    '
    Dim ud As List = BANano.RunJavascriptMethod("getUsers",Null)
    Dim cd As List = BANano.RunJavascriptMethod("getComments", Null)
    '
    Dim comments As WixComments
    comments.Initialize("comments").SetUsers(ud).SetData(cd).SetCurrentUser(4).SetMentions(True).SetModeChat("")
    
    R2.AddColumns(comments.item)
    pg.Page.AddRow(R2)
    pg.ui

We run the JS methods to get the variable details for the users and comments and then assign them to the widget.

These are the constants for the users for the 'status' key from the list of users. For this example, this was not included.

B4X:
Public USER_ACTIVE As String = "active"
    Public USER_AWAY As String = "away"
    Public USER_BUSY As String = "busy"
    Public USER_NONE As String = "none"

There are more functions for this to load more comments etc, and one to trap the various events like sending and retrieving the comments and loading them.
 
Top