use of org.awesomeapp.messenger.model.ImEntity 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.ImEntity in project Zom-Android by zom.
the class XmppConnection method findOrCreateParticipant.
synchronized ImEntity findOrCreateParticipant(String address, boolean isGroupChat) {
ImEntity participant = null;
if (isGroupChat) {
Address xmppAddress = new XmppAddress(address);
participant = mChatGroupManager.getChatGroup(xmppAddress);
if (participant == null) {
try {
mChatGroupManager.createChatGroupAsync(address, xmppAddress.getUser(), mUser.getName());
participant = mChatGroupManager.getChatGroup(xmppAddress);
} catch (Exception e) {
debug(TAG, "unable to join group chat: " + e);
return null;
}
}
} else {
return mContactListManager.getContact(address);
}
return participant;
}
use of org.awesomeapp.messenger.model.ImEntity 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");
}
}
use of org.awesomeapp.messenger.model.ImEntity in project Zom-Android by zom.
the class XmppConnection method findOrCreateSession.
private ChatSession findOrCreateSession(String address, boolean groupChat) {
try {
if (mConnection == null || (!mConnection.isConnected()))
return null;
ChatSession session = mSessionManager.findSession(JidCreate.bareFrom(address));
BareJid bareJid = JidCreate.bareFrom(address);
if (session == null) {
if (!groupChat) {
ImEntity participant = findOrCreateParticipant(address, groupChat);
if (participant != null) {
session = mSessionManager.createChatSession(participant, false);
mContactListManager.refreshPresence(address);
qAvatar.put(bareJid.toString(), "");
if (getOmemo().getManager().contactSupportsOmemo(bareJid)) {
getOmemo().getManager().requestDeviceListUpdateFor(bareJid);
getOmemo().getManager().buildSessionsWith(bareJid);
}
}
} else {
XmppAddress xAddr = new XmppAddress(address);
mChatGroupManager.joinChatGroupAsync(xAddr, null);
MultiUserChat muc = mChatGroupManager.getMultiUserChat(xAddr.getBareAddress());
session = mSessionManager.findSession(muc.getRoom());
// create a session
if (session == null) {
ImEntity participant = findOrCreateParticipant(xAddr.getAddress(), true);
if (participant != null)
session = mSessionManager.createChatSession(participant, false);
if (session != null)
((ChatGroup) session.getParticipant()).setName(muc.getSubject());
}
}
}
return session;
} catch (Exception e) {
debug(ImApp.LOG_TAG, "error findOrCreateSession", e);
return null;
}
}
Aggregations