use of org.awesomeapp.messenger.model.ChatGroup in project Zom-Android by zom.
the class XmppConnection method setState.
@Override
protected void setState(int state, ImErrorInfo error) {
debug(TAG, "setState to " + state);
super.setState(state, error);
if (state == LOGGED_IN) {
// update and send new presence packet out
mUserPresence = new Presence(Presence.AVAILABLE, "", Presence.CLIENT_TYPE_MOBILE);
} else if (state == DISCONNECTED || state == SUSPENDED) {
for (ChatGroup group : getChatGroupManager().getAllChatGroups()) {
group.clearMembers(false);
}
}
}
use of org.awesomeapp.messenger.model.ChatGroup in project Zom-Android by zom.
the class ChatSessionAdapter method getNickName.
String getNickName(String username) {
ImEntity participant = mChatSession.getParticipant();
if (mIsGroupChat) {
ChatGroup group = (ChatGroup) participant;
/**
* List<Contact> members = group.getMembers();
* for (Contact c : members) {
* if (username.equals(c.getAddress().getAddress())) {
*
* return c.getAddress().getResource();
*
* }
* }*
*/
Contact groupMember = group.getMember(username);
if (groupMember != null) {
return groupMember.getAddress().getAddress();
} else {
// not found, impossible
String[] parts = username.split("/");
return parts[parts.length - 1];
}
} else {
return ((Contact) participant).getName();
}
}
use of org.awesomeapp.messenger.model.ChatGroup in project Zom-Android by zom.
the class ChatSessionAdapter method getParticipants.
public String[] getParticipants() {
if (mIsGroupChat) {
Contact self = mConnection.getLoginUser();
ChatGroup group = (ChatGroup) mChatSession.getParticipant();
List<Contact> members = group.getMembers();
String[] result = new String[members.size() - 1];
int index = 0;
for (Contact c : members) {
if (!c.equals(self)) {
result[index++] = c.getAddress().getAddress();
}
}
return result;
} else {
return new String[] { mChatSession.getParticipant().getAddress().getAddress() };
}
}
use of org.awesomeapp.messenger.model.ChatGroup in project Zom-Android by zom.
the class ChatSessionManagerAdapter method createMultiUserChatSession.
public IChatSession createMultiUserChatSession(String roomAddress, String subject, String nickname, boolean isNewChat) {
ChatGroupManager groupMan = mConnection.getAdaptee().getChatGroupManager();
try {
if (roomAddress.endsWith("@")) {
String confServer = groupMan.getDefaultGroupChatService();
if (confServer != null)
roomAddress += confServer;
}
// TODO hard coding XMPP for now
Address address = new XmppAddress(roomAddress);
groupMan.createChatGroupAsync(roomAddress, subject, nickname);
ChatGroup chatGroup = groupMan.getChatGroup(address);
if (chatGroup != null && mConnection.getState() == ImConnection.LOGGED_IN) {
ChatSession session = getChatSessionManager().createChatSession(chatGroup, isNewChat);
ChatSessionAdapter adapter = getChatSessionAdapter(session, isNewChat);
groupMan.loadMembers(chatGroup);
return adapter;
} else {
return null;
}
} catch (Exception e) {
Log.e(ImApp.LOG_TAG, "unable to join group chat" + e.getMessage());
return null;
}
}
use of org.awesomeapp.messenger.model.ChatGroup in project Zom-Android by zom.
the class XmppConnection method initConnectionAndLogin.
private void initConnectionAndLogin(Imps.ProviderSettings.QueryMap providerSettings, String userName) throws InterruptedException, IOException, SmackException, XMPPException, KeyManagementException, NoSuchAlgorithmException, IllegalStateException, RuntimeException {
// Roster.SubscriptionMode.accept_all;//load this from a preference
Roster.SubscriptionMode subMode = Roster.SubscriptionMode.manual;
// only activates if Debug TRUE is set, so you can leave this in!
Debug.onConnectionStart();
initConnection(providerSettings, userName);
if (mConnection.isConnected() && mConnection.isSecureConnection() && (!mConnection.isAuthenticated())) {
mResource = providerSettings.getXmppResource();
mRoster = Roster.getInstanceFor(mConnection);
mRoster.setRosterLoadedAtLogin(true);
mRoster.setSubscriptionMode(subMode);
getContactListManager().listenToRoster(mRoster);
ReconnectionManager manager = ReconnectionManager.getInstanceFor(mConnection);
manager.disableAutomaticReconnection();
mChatManager = ChatManager.getInstanceFor(mConnection);
mPingManager = PingManager.getInstanceFor(mConnection);
mPingManager.setPingInterval(PING_INTERVAL);
if (mUser == null)
mUser = makeUser(providerSettings, mContext.getContentResolver());
try {
getOmemo();
} catch (Exception e) {
debug(TAG, "error init'ing omemo during connectoin", e);
}
MultiUserChatManager.getInstanceFor(mConnection).addInvitationListener(new InvitationListener() {
@Override
public void invitationReceived(XMPPConnection xmppConnection, MultiUserChat muc, EntityJid entityJid, String reason, String password, org.jivesoftware.smack.packet.Message message, MUCUser.Invite invite) {
try {
getChatGroupManager().acceptInvitationAsync(invite.getFrom().toString());
XmppAddress xa = new XmppAddress(muc.getRoom().toString());
mChatGroupManager.joinChatGroupAsync(xa, reason);
ChatSession session = mSessionManager.findSession(muc.getRoom());
// create a session
if (session == null) {
ImEntity participant = findOrCreateParticipant(xa.getAddress(), true);
if (participant != null)
session = mSessionManager.createChatSession(participant, false);
if (session != null)
((ChatGroup) session.getParticipant()).setName(muc.getSubject());
}
} catch (Exception se) {
Log.e(TAG, "error accepting invite", se);
}
}
});
mConnection.login(mUsername, mPassword, Resourcepart.from(mResource));
mStreamHandler.notifyInitialLogin();
initServiceDiscovery();
getContactListManager().loadContactListsAsync();
execute(new Runnable() {
public void run() {
sendPresencePacket();
sendVCard();
}
});
} else {
// throw some meaningful error message here
throw new SmackException("Unable to securely conenct to server");
}
}
Aggregations