use of org.awesomeapp.messenger.service.IChatSessionManager in project Zom-Android by zom.
the class ImUrlActivity method openChat.
private void openChat(long provider, long account) {
try {
IChatSessionManager manager = mConn.getChatSessionManager();
IChatSession session = manager.getChatSession(mToAddress);
if (session == null) {
session = manager.createChatSession(mToAddress, false);
}
Uri data = ContentUris.withAppendedId(Imps.Chats.CONTENT_URI, session.getId());
Intent intent = new Intent(Intent.ACTION_VIEW, data);
intent.putExtra(ImServiceConstants.EXTRA_INTENT_FROM_ADDRESS, mToAddress);
intent.putExtra(ImServiceConstants.EXTRA_INTENT_PROVIDER_ID, provider);
intent.putExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, account);
intent.addCategory(ImApp.IMPS_CATEGORY);
startActivity(intent);
} catch (RemoteException e) {
// Ouch! Service died! We'll just disappear.
Log.w("ImUrlActivity", "Connection disappeared!");
}
}
use of org.awesomeapp.messenger.service.IChatSessionManager in project Zom-Android by zom.
the class ConversationView method inviteContacts.
public void inviteContacts(ArrayList<String> invitees) {
if (mConn == null)
return;
try {
IChatSessionManager manager = mConn.getChatSessionManager();
IChatSession session = manager.getChatSession(mRemoteAddress);
for (String invitee : invitees) session.inviteContact(invitee);
} catch (Exception e) {
Log.e(ImApp.LOG_TAG, "error inviting contacts to group", e);
}
}
use of org.awesomeapp.messenger.service.IChatSessionManager in project Zom-Android by zom.
the class ConversationView method createChatSession.
private IChatSession createChatSession() {
try {
if (mConn != null) {
IChatSessionManager sessionMgr = mConn.getChatSessionManager();
if (sessionMgr != null) {
String remoteAddress = mRemoteAddress;
IChatSession session = null;
if (mContactType == Imps.Contacts.TYPE_GROUP) {
// Contact contactGroup = new Contact(new XmppAddress(mRemoteAddress),mRemoteNickname,Imps.Contacts.TYPE_GROUP);
session = sessionMgr.createMultiUserChatSession(mRemoteAddress, mRemoteNickname, null, false);
// new ChatSessionInitTask(((ImApp)mActivity.getApplication()),mProviderId, mAccountId, Imps.Contacts.TYPE_GROUP)
// .executeOnExecutor(ImApp.sThreadPoolExecutor,contactGroup);
} else {
remoteAddress = Address.stripResource(mRemoteAddress);
session = sessionMgr.createChatSession(remoteAddress, false);
}
return session;
}
}
} catch (Exception e) {
// mHandler.showServiceErrorAlert(e.getLocalizedMessage());
LogCleaner.error(ImApp.LOG_TAG, "issue getting chat session", e);
}
return null;
}
use of org.awesomeapp.messenger.service.IChatSessionManager in project Zom-Android by zom.
the class GroupDisplayActivity method leaveGroup.
private void leaveGroup() {
try {
IChatSessionManager manager = mConn.getChatSessionManager();
IChatSession session = manager.getChatSession(mAddress);
if (session == null)
session = manager.createChatSession(mAddress, true);
if (session != null) {
session.leave();
// clear the stack and go back to the main activity
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
} catch (Exception e) {
Log.e(ImApp.LOG_TAG, "error leaving group", e);
}
}
use of org.awesomeapp.messenger.service.IChatSessionManager in project Zom-Android by zom.
the class MigrateAccountTask method doInBackground.
@Override
protected OnboardingAccount doInBackground(String... newDomains) {
// get existing account username
String nickname = Imps.Account.getNickname(mContext.getContentResolver(), mAccountId);
String username = Imps.Account.getUserName(mContext.getContentResolver(), mAccountId);
String password = Imps.Account.getPassword(mContext.getContentResolver(), mAccountId);
OtrAndroidKeyManagerImpl keyMan = OtrAndroidKeyManagerImpl.getInstance(mContext);
KeyPair keyPair = keyMan.generateLocalKeyPair();
String fingerprint = keyMan.getFingerprint(keyPair.getPublic());
// find or use provided new server/domain
String domain = newDomains[0];
// register account on new domain with same password
mNewAccount = registerNewAccount(nickname, username, password, domain, null);
if (mNewAccount == null) {
username = username + '.' + fingerprint.substring(fingerprint.length() - 8, fingerprint.length()).toLowerCase();
mNewAccount = registerNewAccount(nickname, username, password, domain, null);
if (mNewAccount == null)
return null;
}
String newJabberId = mNewAccount.username + '@' + mNewAccount.domain;
keyMan.storeKeyPair(newJabberId, keyPair);
// send migration message to existing contacts and/or sessions
try {
boolean loggedInToOldAccount = mConn.getState() == ImConnection.LOGGED_IN;
// login and set new default account
SignInHelper signInHelper = new SignInHelper(mContext, mHandler);
signInHelper.activateAccount(mNewAccount.providerId, mNewAccount.accountId);
signInHelper.signIn(mNewAccount.password, mNewAccount.providerId, mNewAccount.accountId, true);
mNewConn = mApp.getConnection(mNewAccount.providerId, mNewAccount.accountId);
while (mNewConn.getState() != ImConnection.LOGGED_IN) {
try {
Thread.sleep(500);
} catch (Exception e) {
}
}
String inviteLink = OnboardingManager.generateInviteLink(mContext, newJabberId, fingerprint, nickname, true);
String migrateMessage = mContext.getString(R.string.migrate_message) + ' ' + inviteLink;
IChatSessionManager sessionMgr = mConn.getChatSessionManager();
IContactListManager clManager = mConn.getContactListManager();
List<IContactList> listOfLists = clManager.getContactLists();
if (loggedInToOldAccount) {
for (IContactList contactList : listOfLists) {
String[] contacts = contactList.getContacts();
for (String contact : contacts) {
mContacts.add(contact);
IChatSession session = sessionMgr.getChatSession(contact);
if (session == null) {
session = sessionMgr.createChatSession(contact, true);
}
if (!session.isEncrypted()) {
// try to kick off some encryption here
session.getDefaultOtrChatSession().startChatEncryption();
try {
Thread.sleep(500);
}// just wait a half second here?
catch (Exception e) {
}
}
session.sendMessage(migrateMessage, false);
// archive existing contact
clManager.archiveContact(contact, session.isGroupChatSession() ? Imps.Contacts.TYPE_NORMAL : Imps.Contacts.TYPE_GROUP, true);
}
}
} else {
String[] offlineAddresses = clManager.getOfflineAddresses();
for (String address : offlineAddresses) {
mContacts.add(address);
clManager.archiveContact(address, Imps.Contacts.TYPE_NORMAL, true);
}
}
for (String contact : mContacts) {
addToContactList(mNewConn, contact, keyMan.getRemoteFingerprint(contact), null);
}
if (loggedInToOldAccount) {
// archive existing conversations and contacts
List<IChatSession> listSession = mConn.getChatSessionManager().getActiveChatSessions();
for (IChatSession session : listSession) {
session.leave();
}
mConn.broadcastMigrationIdentity(newJabberId);
}
migrateAvatars(username, newJabberId);
mApp.setDefaultAccount(mNewAccount.providerId, mNewAccount.accountId);
// logout of existing account
setKeepSignedIn(mAccountId, false);
if (loggedInToOldAccount)
mConn.logout();
return mNewAccount;
} catch (Exception e) {
Log.e(ImApp.LOG_TAG, "error with migration", e);
}
// failed
return null;
}
Aggregations