Search in sources :

Example 31 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ChatStateManager method updateChatState.

/**
 * Update chat state information and send message if necessary.
 */
private void updateChatState(AccountJid account, UserJid user, ChatState chatState) {
    if (!SettingsManager.chatsStateNotification() || sent.get(account.toString(), user.toString()) == chatState) {
        return;
    }
    AbstractChat chat = MessageManager.getInstance().getChat(account, user);
    if (chat == null || !isSupported(chat, false)) {
        return;
    }
    sent.put(chat.getAccount().toString(), chat.getUser().toString(), chatState);
    Message message = new Message();
    message.setType(chat.getType());
    message.setTo(chat.getTo());
    message.addExtension(new ChatStateExtension(chatState));
    try {
        StanzaSender.sendStanza(account, message);
    } catch (NetworkException e) {
    // Just ignore it.
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) ChatStateExtension(org.jivesoftware.smackx.chatstates.packet.ChatStateExtension) AbstractChat(com.xabber.android.data.message.AbstractChat) NetworkException(com.xabber.android.data.NetworkException)

Example 32 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class MUCManager method createRoom.

/**
 * Creates or updates existed room.
 */
public void createRoom(AccountJid account, EntityBareJid room, Resourcepart nickname, String password, boolean join) {
    removeInvite(getInvite(account, room));
    AbstractChat chat = null;
    try {
        chat = MessageManager.getInstance().getChat(account, UserJid.from(room));
    } catch (UserJid.UserJidCreateException e) {
        LogManager.exception(this, e);
    }
    RoomChat roomChat;
    if (chat == null || !(chat instanceof RoomChat)) {
        if (chat != null) {
            MessageManager.getInstance().removeChat(chat);
        }
        try {
            roomChat = RoomChat.create(account, room, nickname, password);
            MessageManager.getInstance().addChat(roomChat);
        } catch (UserJid.UserJidCreateException e) {
            LogManager.exception(this, e);
        }
    } else {
        roomChat = (RoomChat) chat;
        roomChat.setNickname(nickname);
        roomChat.setPassword(password);
    }
    requestToWriteRoom(account, room, nickname, password, join);
    if (join) {
        joinRoom(account, room, true);
    }
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) UserJid(com.xabber.android.data.entity.UserJid)

Example 33 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class OTRManager method endSession.

private void endSession(String account, String user) throws NetworkException {
    LogManager.i(this, "Ending session for " + user);
    try {
        getOrCreateSession(account, user).endSession();
    } catch (OtrException e) {
        throw new NetworkException(R.string.OTR_ERROR, e);
    }
    AbstractChat abstractChat = getChat(account, user);
    if (abstractChat != null) {
        SSNManager.getInstance().setSessionOtrMode(account, user, abstractChat.getThreadId(), OtrMode.concede);
        LogManager.i(this, "Ended session for " + user);
    }
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) OtrException(net.java.otr4j.OtrException) NetworkException(com.xabber.android.data.NetworkException)

Example 34 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class OTRManager method newAction.

/**
 * Creates new action in specified chat.
 */
private void newAction(String account, String user, String text, ChatAction action) {
    LogManager.i(this, "newAction. text: " + text + " action " + action);
    AbstractChat chat = getChat(account, user);
    if (chat != null) {
        chat.newAction(null, text, action);
    }
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat)

Example 35 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class OTRManager method injectMessage.

private void injectMessage(String account, String user, String msg) throws OtrException {
    LogManager.i(this, "injectMessage. user: " + user + " message: " + msg);
    AbstractChat abstractChat = getChat(account, user);
    SSNManager.getInstance().setSessionOtrMode(account, user, abstractChat.getThreadId(), OtrMode.prefer);
    Message message = abstractChat.createMessagePacket(msg);
    CarbonManager.getInstance().setMessageToIgnoreCarbons(message);
    try {
        StanzaSender.sendStanza(abstractChat.getAccount(), message);
    } catch (NetworkException e) {
        throw new OtrException(e);
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) AbstractChat(com.xabber.android.data.message.AbstractChat) OtrException(net.java.otr4j.OtrException) NetworkException(com.xabber.android.data.NetworkException)

Aggregations

AbstractChat (com.xabber.android.data.message.AbstractChat)55 UserJid (com.xabber.android.data.entity.UserJid)10 RoomChat (com.xabber.android.data.extension.muc.RoomChat)10 NetworkException (com.xabber.android.data.NetworkException)9 RegularChat (com.xabber.android.data.message.RegularChat)9 ArrayList (java.util.ArrayList)8 AccountJid (com.xabber.android.data.entity.AccountJid)7 RoomContact (com.xabber.android.data.extension.muc.RoomContact)6 ChatContact (com.xabber.android.data.message.ChatContact)6 AbstractContact (com.xabber.android.data.roster.AbstractContact)6 RosterContact (com.xabber.android.data.roster.RosterContact)6 NotificationState (com.xabber.android.data.message.NotificationState)5 Message (org.jivesoftware.smack.packet.Message)5 GroupConfiguration (com.xabber.android.ui.adapter.contactlist.GroupConfiguration)4 View (android.view.View)3 MessageManager (com.xabber.android.data.message.MessageManager)3 Map (java.util.Map)3 Intent (android.content.Intent)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2