use of org.awesomeapp.messenger.model.ImException in project Zom-Android by zom.
the class XmppConnection method initUser.
public void initUser(long providerId, long accountId) throws ImException {
ContentResolver contentResolver = mContext.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 settings");
Imps.ProviderSettings.QueryMap providerSettings = new Imps.ProviderSettings.QueryMap(cursor, contentResolver, providerId, false, null);
mProviderId = providerId;
mAccountId = accountId;
mUser = makeUser(providerSettings, contentResolver);
try {
mUserJid = JidCreate.bareFrom(mUser.getAddress().getAddress());
} catch (Exception e) {
}
providerSettings.close();
}
use of org.awesomeapp.messenger.model.ImException in project Zom-Android by zom.
the class LoopbackConnection method doUpdateUserPresenceAsync.
@Override
protected void doUpdateUserPresenceAsync(Presence presence) {
// mimic presence
ContactList cl;
try {
cl = mContactListManager.getDefaultContactList();
} catch (ImException e) {
throw new RuntimeException(e);
}
if (cl == null)
return;
Collection<Contact> contacts = cl.getContacts();
for (Iterator<Contact> iter = contacts.iterator(); iter.hasNext(); ) {
Contact contact = iter.next();
contact.setPresence(presence);
}
Contact[] contacts_array = new Contact[contacts.size()];
contacts.toArray(contacts_array);
mContactListManager.doPresence(contacts_array);
}
use of org.awesomeapp.messenger.model.ImException 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;
}
}
use of org.awesomeapp.messenger.model.ImException in project Zom-Android by zom.
the class ContactListManagerAdapter method setContactName.
public int setContactName(String address, String name) {
// update the server
try {
mAdaptee.setContactName(address, name);
} catch (ImException e) {
return e.getImError().getCode();
}
// update locally
String selection = Imps.Contacts.USERNAME + "=?";
String[] selectionArgs = { address };
ContentValues values = new ContentValues(1);
values.put(Imps.Contacts.NICKNAME, name);
int updated = mResolver.update(mContactUrl, values, selection, selectionArgs);
if (updated != 1) {
return ImErrorInfo.ILLEGAL_CONTACT_ADDRESS;
}
return ImErrorInfo.NO_ERROR;
}
use of org.awesomeapp.messenger.model.ImException in project Zom-Android by zom.
the class ImConnectionAdapter method loadSavedPresence.
private void loadSavedPresence() {
ContentResolver cr = mService.getContentResolver();
// Imps.ProviderSettings.setPresence(cr, mProviderId, status, statusText);
int presenceState = Imps.ProviderSettings.getIntValue(cr, mProviderId, Imps.ProviderSettings.PRESENCE_STATE);
String presenceStatusMessage = Imps.ProviderSettings.getStringValue(cr, mProviderId, Imps.ProviderSettings.PRESENCE_STATUS_MESSAGE);
if (presenceState != -1) {
Presence presence = new Presence();
presence.setStatus(presenceState);
presence.setStatusText(presenceStatusMessage);
try {
mConnection.updateUserPresenceAsync(presence);
} catch (ImException e) {
Log.e(ImApp.LOG_TAG, "unable able to update presence", e);
}
}
}
Aggregations