samples/cordova/text_chat/www/js/messages.js
function sendMessage(text, attachmentFileId) {
    stickerpipe.onUserMessageSent(stickerpipe.isSticker(text));

    var msg = {
        type: currentDialog.type === 3 ? 'chat' : 'groupchat',
        body: text,
        extension: {
            save_to_history: 1,
        },
        markable: 1
    };

    if(attachmentFileId !== null){
        msg['extension']['attachments'] = [{id: attachmentFileId, type: 'photo'}];
    }

    if (currentDialog.type === 3) {
        opponentId = QB.chat.helpers.getRecipientId(currentDialog.occupants_ids, currentUser.id);

        QB.chat.send(opponentId, msg);

        $('.list-group-item.active .list-group-item-text')
            .text(stickerpipe.isSticker(msg.body) ? 'Sticker' : msg.body);

        if(attachmentFileId === null){
            showMessage(currentUser.id, msg);
        } else {
            showMessage(currentUser.id, msg, attachmentFileId);
        }
    } else {
        QB.chat.send(currentDialog.xmpp_room_jid, msg);
    }

    // claer timer and send 'stop typing' status
    clearTimeout(isTypingTimerId);
    isTypingTimeoutCallback();

    dialogsMessages.push(msg);
}
function sendMessage(text, attachmentFileId) {
    stickerpipe.onUserMessageSent(stickerpipe.isSticker(text));

    var msg = {
        type: currentDialog.type === 3 ? 'chat' : 'groupchat',
        body: text,
        extension: {
            save_to_history: 1,
        },
        markable: 1
    };

    if(attachmentFileId !== null){
        msg['extension']['attachments'] = [{id: attachmentFileId, type: 'photo'}];
    }

    if (currentDialog.type === 3) {
        opponentId = QB.chat.helpers.getRecipientId(currentDialog.occupants_ids, currentUser.id);

        QB.chat.send(opponentId, msg);

        $('.list-group-item.active .list-group-item-text')
            .text(stickerpipe.isSticker(msg.body) ? 'Sticker' : msg.body);

        if(attachmentFileId === null){
            showMessage(currentUser.id, msg);
        } else {
            showMessage(currentUser.id, msg, attachmentFileId);
        }
    } else {
        QB.chat.send(currentDialog.xmpp_room_jid, msg);
    }

    // claer timer and send 'stop typing' status
    clearTimeout(isTypingTimerId);
    isTypingTimeoutCallback();

    dialogsMessages.push(msg);
}
function sendMessage ( text , attachmentFileId ) { stickerpipe . onUserMessageSent ( stickerpipe . isSticker ( text ) ) ; var msg = { type : currentDialog . type === 3 ? 'chat' : 'groupchat' , body : text , extension : { save_to_history : 1 , } , markable : 1 } ; if ( attachmentFileId !== null ) { msg [ 'extension' ] [ 'attachments' ] = [ { id : attachmentFileId , type : 'photo' } ] ; } if ( currentDialog . type === 3 ) { opponentId = QB . chat . helpers . getRecipientId ( currentDialog . occupants_ids , currentUser . id ) ; QB . chat . send ( opponentId , msg ) ; $ ( '.list-group-item.active .list-group-item-text' ) . text ( stickerpipe . isSticker ( msg . body ) ? 'Sticker' : msg . body ) ; if ( attachmentFileId === null ) { showMessage ( currentUser . id , msg ) ; } else { showMessage ( currentUser . id , msg , attachmentFileId ) ; } } else { QB . chat . send ( currentDialog . xmpp_room_jid , msg ) ; } // claer timer and send 'stop typing' status clearTimeout ( isTypingTimerId ) ; isTypingTimeoutCallback ( ) ; dialogsMessages . push ( msg ) ; }
send text or attachment
send text or attachment