use of org.awesomeapp.messenger.model.ImConnection in project Zom-Android by zom.
the class RemoteImService method do_createConnection.
private IImConnection do_createConnection(long providerId, long accountId) {
if (providerId == -1)
return null;
Map<String, String> settings = loadProviderSettings(providerId);
// make sure OTR is init'd before you create your first connection
initOtrChatManager();
ConnectionFactory factory = ConnectionFactory.getInstance();
try {
ImConnection conn = factory.createConnection(settings, this);
conn.initUser(providerId, accountId);
ImConnectionAdapter imConnectionAdapter = new ImConnectionAdapter(providerId, accountId, conn, this);
conn.addConnectionListener(new ConnectionListener() {
@Override
public void onStateChanged(int state, ImErrorInfo error) {
}
@Override
public void onUserPresenceUpdated() {
}
@Override
public void onUpdatePresenceError(ImErrorInfo error) {
}
});
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(Imps.ProviderSettings.CONTENT_URI, new String[] { Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE }, Imps.ProviderSettings.PROVIDER + "=?", new String[] { Long.toString(providerId) }, null);
if (cursor == null)
throw new ImException("unable to query the provider settings");
Imps.ProviderSettings.QueryMap providerSettings = new Imps.ProviderSettings.QueryMap(cursor, contentResolver, providerId, false, null);
String userName = Imps.Account.getUserName(contentResolver, accountId);
String domain = providerSettings.getDomain();
providerSettings.close();
mConnections.put(providerId + "." + accountId, imConnectionAdapter);
mConnectionsByUser.put(imConnectionAdapter.getLoginUser().getAddress().getBareAddress(), imConnectionAdapter);
Debug.recordTrail(this, CONNECTIONS_TRAIL_TAG, "" + mConnections.size());
synchronized (mRemoteListeners) {
try {
final int N = mRemoteListeners.beginBroadcast();
for (int i = 0; i < N; i++) {
IConnectionCreationListener listener = mRemoteListeners.getBroadcastItem(i);
try {
listener.onConnectionCreated(imConnectionAdapter);
} catch (RemoteException e) {
// The RemoteCallbackList will take care of removing the
// dead listeners.
}
}
} finally {
mRemoteListeners.finishBroadcast();
}
}
return imConnectionAdapter;
} catch (ImException e) {
debug("Error creating connection", e);
return null;
}
}
Aggregations