src/methods/node.js
async function handleMessagePing(state, msgObj) {

    /**
     * when there are no listener, we do nothing
     */
    if (!state.messagesCallback) return;

    let messages;
    if (!msgObj) {
        // get all
        messages = await getAllMessages(state.channelName, state.paths);
    } else {
        // get single message
        messages = [
            getSingleMessage(state.channelName, msgObj, state.paths)
        ];
    }

    const useMessages = messages
        .filter(msgObj => _filterMessage(msgObj, state))
        .sort((msgObjA, msgObjB) => msgObjA.time - msgObjB.time); // sort by time


    // if no listener or message, so not do anything
    if (!useMessages.length || !state.messagesCallback) return;

    // read contents
    await Promise.all(
        useMessages
        .map(
            msgObj => readMessage(msgObj).then(content => msgObj.content = content)
        )
    );

    useMessages.forEach(msgObj => {
        state.emittedMessagesIds.add(msgObj.token);

        if (state.messagesCallback) {
            // emit to subscribers
            state.messagesCallback(msgObj.content.data);
        }
    });
}
async function handleMessagePing(state, msgObj) {

    /**
     * when there are no listener, we do nothing
     */
    if (!state.messagesCallback) return;

    let messages;
    if (!msgObj) {
        // get all
        messages = await getAllMessages(state.channelName, state.paths);
    } else {
        // get single message
        messages = [
            getSingleMessage(state.channelName, msgObj, state.paths)
        ];
    }

    const useMessages = messages
        .filter(msgObj => _filterMessage(msgObj, state))
        .sort((msgObjA, msgObjB) => msgObjA.time - msgObjB.time); // sort by time


    // if no listener or message, so not do anything
    if (!useMessages.length || !state.messagesCallback) return;

    // read contents
    await Promise.all(
        useMessages
        .map(
            msgObj => readMessage(msgObj).then(content => msgObj.content = content)
        )
    );

    useMessages.forEach(msgObj => {
        state.emittedMessagesIds.add(msgObj.token);

        if (state.messagesCallback) {
            // emit to subscribers
            state.messagesCallback(msgObj.content.data);
        }
    });
}
async function handleMessagePing ( state , msgObj ) { /**
     * when there are no listener, we do nothing
     */ if ( ! state . messagesCallback ) return ; let messages ; if ( ! msgObj ) { // get all messages = await getAllMessages ( state . channelName , state . paths ) ; } else { // get single message messages = [ getSingleMessage ( state . channelName , msgObj , state . paths ) ] ; } const useMessages = messages . filter ( msgObj => _filterMessage ( msgObj , state ) ) . sort ( ( msgObjA , msgObjB ) => msgObjA . time - msgObjB . time ) ; // sort by time // if no listener or message, so not do anything if ( ! useMessages . length || ! state . messagesCallback ) return ; // read contents await Promise . all ( useMessages . map ( msgObj => readMessage ( msgObj ) . then ( content => msgObj . content = content ) ) ) ; useMessages . forEach ( msgObj => { state . emittedMessagesIds . add ( msgObj . token ) ; if ( state . messagesCallback ) { // emit to subscribers state . messagesCallback ( msgObj . content . data ) ; } } ) ; }
when the socket pings, so that we now new messages came,
run this
when the socket pings so that we now new messages came run this