use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class XmppConnectionService method fetchAvatarVcard.
private void fetchAvatarVcard(final Account account, final Avatar avatar, final UiCallback<Avatar> callback) {
IqPacket packet = this.mIqGenerator.retrieveVcardAvatar(avatar);
this.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
final boolean previouslyOmittedPepFetch;
synchronized (mInProgressAvatarFetches) {
final String KEY = generateFetchKey(account, avatar);
mInProgressAvatarFetches.remove(KEY);
previouslyOmittedPepFetch = mOmittedPepAvatarFetches.remove(KEY);
}
if (packet.getType() == IqPacket.TYPE.RESULT) {
Element vCard = packet.findChild("vCard", "vcard-temp");
Element photo = vCard != null ? vCard.findChild("PHOTO") : null;
String image = photo != null ? photo.findChildContent("BINVAL") : null;
if (image != null) {
avatar.image = image;
if (getFileBackend().save(avatar)) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": successfully fetched vCard avatar for " + avatar.owner + " omittedPep=" + previouslyOmittedPepFetch);
if (avatar.owner.isBareJid()) {
if (account.getJid().asBareJid().equals(avatar.owner) && account.getAvatar() == null) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": had no avatar. replacing with vcard");
account.setAvatar(avatar.getFilename());
databaseBackend.updateAccount(account);
getAvatarService().clear(account);
updateAccountUi();
} else {
final Contact contact = account.getRoster().getContact(avatar.owner);
contact.setAvatar(avatar, previouslyOmittedPepFetch);
syncRoster(account);
getAvatarService().clear(contact);
updateRosterUi();
}
updateConversationUi();
} else {
Conversation conversation = find(account, avatar.owner.asBareJid());
if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {
MucOptions.User user = conversation.getMucOptions().findUserByFullJid(avatar.owner);
if (user != null) {
if (user.setAvatar(avatar)) {
getAvatarService().clear(user);
updateConversationUi();
updateMucRosterUi();
}
if (user.getRealJid() != null) {
Contact contact = account.getRoster().getContact(user.getRealJid());
contact.setAvatar(avatar);
syncRoster(account);
getAvatarService().clear(contact);
updateRosterUi();
}
}
}
}
}
}
}
}
});
}
use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class ContactChooserTargetService method onGetChooserTargets.
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
final ArrayList<ChooserTarget> chooserTargets = new ArrayList<>();
if (!EventReceiver.hasEnabledAccounts(this)) {
return chooserTargets;
}
final Intent intent = new Intent(this, XmppConnectionService.class);
intent.setAction("contact_chooser");
Compatibility.startService(this, intent);
bindService(intent, this, Context.BIND_AUTO_CREATE);
try {
waitForService();
final ArrayList<Conversation> conversations = new ArrayList<>();
if (!mXmppConnectionService.areMessagesInitialized()) {
return chooserTargets;
}
mXmppConnectionService.populateWithOrderedConversations(conversations, textOnly(matchedFilter));
final ComponentName componentName = new ComponentName(this, ConversationsActivity.class);
final int pixel = AvatarService.getSystemUiAvatarSize(this);
for (Conversation conversation : conversations) {
if (conversation.sentMessagesCount() == 0) {
continue;
}
final String name = conversation.getName().toString();
final Icon icon = Icon.createWithBitmap(mXmppConnectionService.getAvatarService().get(conversation, pixel));
final float score = 1 - (1.0f / MAX_TARGETS) * chooserTargets.size();
final Bundle extras = new Bundle();
extras.putString(ConversationsActivity.EXTRA_CONVERSATION, conversation.getUuid());
chooserTargets.add(new ChooserTarget(name, icon, score, componentName, extras));
if (chooserTargets.size() >= MAX_TARGETS) {
break;
}
}
} catch (InterruptedException e) {
}
unbindService(this);
return chooserTargets;
}
use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class MessageArchiveService method finalizeQuery.
private void finalizeQuery(final Query query, boolean done) {
synchronized (this.queries) {
if (!this.queries.remove(query)) {
throw new IllegalStateException("Unable to remove query from queries");
}
}
final Conversation conversation = query.getConversation();
if (conversation != null) {
conversation.sort();
conversation.setHasMessagesLeftOnServer(!done);
} else {
for (Conversation tmp : this.mXmppConnectionService.getConversations()) {
if (tmp.getAccount() == query.getAccount()) {
tmp.sort();
}
}
}
if (query.hasCallback()) {
query.callback(done);
} else {
this.mXmppConnectionService.updateConversationUi();
}
}
use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class StartConversationActivity method onJoinDialogPositiveClick.
@Override
public void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, TextInputLayout layout, AutoCompleteTextView jid, boolean isBookmarkChecked) {
if (!xmppConnectionServiceBound) {
return;
}
final Account account = getSelectedAccount(this, spinner);
if (account == null) {
return;
}
final String input = jid.getText().toString();
Jid conferenceJid;
try {
conferenceJid = Jid.ofEscaped(input);
} catch (final IllegalArgumentException e) {
final XmppUri xmppUri = new XmppUri(input);
if (xmppUri.isValidJid() && xmppUri.isAction(XmppUri.ACTION_JOIN)) {
final Editable editable = jid.getEditableText();
editable.clear();
editable.append(xmppUri.getJid().toEscapedString());
conferenceJid = xmppUri.getJid();
} else {
layout.setError(getString(R.string.invalid_jid));
return;
}
}
if (isBookmarkChecked) {
Bookmark bookmark = account.getBookmark(conferenceJid);
if (bookmark != null) {
dialog.dismiss();
openConversationsForBookmark(bookmark);
} else {
bookmark = new Bookmark(account, conferenceJid.asBareJid());
bookmark.setAutojoin(getBooleanPreference("autojoin", R.bool.autojoin));
final String nick = conferenceJid.getResource();
if (nick != null && !nick.isEmpty() && !nick.equals(MucOptions.defaultNick(account))) {
bookmark.setNick(nick);
}
xmppConnectionService.createBookmark(account, bookmark);
final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true, true);
bookmark.setConversation(conversation);
dialog.dismiss();
switchToConversation(conversation);
}
} else {
final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true, true);
dialog.dismiss();
switchToConversation(conversation);
}
}
use of eu.siacs.conversations.entities.Conversation in project Conversations by siacs.
the class StartConversationActivity method openConversationForContact.
protected void openConversationForContact(Contact contact) {
Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false, true);
SoftKeyboardUtils.hideSoftKeyboard(this);
switchToConversation(conversation);
}
Aggregations