store avatars received over muc presence in contact

This commit is contained in:
Daniel Gultsch 2018-09-21 12:27:58 +02:00
parent b8d831f02a
commit 1985f6bdec
7 changed files with 797 additions and 782 deletions

View file

@ -431,10 +431,14 @@ public class Contact implements ListItem, Blockable {
} }
} }
public String getAvatar() { public String getAvatarFilename() {
return avatar == null ? null : avatar.getFilename(); return avatar == null ? null : avatar.getFilename();
} }
public Avatar getAvatar() {
return avatar;
}
public boolean mutualPresenceSubscription() { public boolean mutualPresenceSubscription() {
return getOption(Options.FROM) && getOption(Options.TO); return getOption(Options.FROM) && getOption(Options.TO);
} }

File diff suppressed because it is too large Load diff

View file

@ -119,6 +119,14 @@ public class PresenceParser extends AbstractParser implements
if (user.setAvatar(avatar)) { if (user.setAvatar(avatar)) {
mXmppConnectionService.getAvatarService().clear(user); mXmppConnectionService.getAvatarService().clear(user);
} }
if (user.getRealJid() != null) {
Contact c = conversation.getAccount().getRoster().getContact(user.getRealJid());
if (c.setAvatar(avatar)) {
mXmppConnectionService.syncRoster(conversation.getAccount());
mXmppConnectionService.getAvatarService().clear(c);
mXmppConnectionService.updateRosterUi();
}
}
} else if (mXmppConnectionService.isDataSaverDisabled()) { } else if (mXmppConnectionService.isDataSaverDisabled()) {
mXmppConnectionService.fetchAvatar(mucOptions.getAccount(), avatar); mXmppConnectionService.fetchAvatar(mucOptions.getAccount(), avatar);
} }

View file

@ -911,7 +911,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
final SQLiteDatabase db = this.getWritableDatabase(); final SQLiteDatabase db = this.getWritableDatabase();
db.beginTransaction(); db.beginTransaction();
for (Contact contact : roster.getContacts()) { for (Contact contact : roster.getContacts()) {
if (contact.getOption(Contact.Options.IN_ROSTER) || contact.getAvatar() != null) { if (contact.getOption(Contact.Options.IN_ROSTER) || contact.getAvatarFilename() != null) {
db.insert(Contact.TABLENAME, null, contact.getContentValues()); db.insert(Contact.TABLENAME, null, contact.getContentValues());
} else { } else {
String where = Contact.ACCOUNT + "=? AND " + Contact.JID + "=?"; String where = Contact.ACCOUNT + "=? AND " + Contact.JID + "=?";

View file

@ -69,8 +69,8 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
if (contact.getProfilePhoto() != null) { if (contact.getProfilePhoto() != null) {
avatar = mXmppConnectionService.getFileBackend().cropCenterSquare(Uri.parse(contact.getProfilePhoto()), size); avatar = mXmppConnectionService.getFileBackend().cropCenterSquare(Uri.parse(contact.getProfilePhoto()), size);
} }
if (avatar == null && contact.getAvatar() != null) { if (avatar == null && contact.getAvatarFilename() != null) {
avatar = mXmppConnectionService.getFileBackend().getAvatar(contact.getAvatar(), size); avatar = mXmppConnectionService.getFileBackend().getAvatar(contact.getAvatarFilename(), size);
} }
if (avatar == null) { if (avatar == null) {
avatar = get(contact.getDisplayName(), contact.getJid().asBareJid().toString(), size, cachedOnly); avatar = get(contact.getDisplayName(), contact.getJid().asBareJid().toString(), size, cachedOnly);
@ -128,7 +128,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
public Bitmap get(final MucOptions.User user, final int size, boolean cachedOnly) { public Bitmap get(final MucOptions.User user, final int size, boolean cachedOnly) {
Contact c = user.getContact(); Contact c = user.getContact();
if (c != null && (c.getProfilePhoto() != null || c.getAvatar() != null || user.getAvatar() == null)) { if (c != null && (c.getProfilePhoto() != null || c.getAvatarFilename() != null || user.getAvatar() == null)) {
return get(c, size, cachedOnly); return get(c, size, cachedOnly);
} else { } else {
return getImpl(user, size, cachedOnly); return getImpl(user, size, cachedOnly);
@ -165,6 +165,10 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
} }
} }
for (Conversation conversation : mXmppConnectionService.findAllConferencesWith(contact)) { for (Conversation conversation : mXmppConnectionService.findAllConferencesWith(contact)) {
MucOptions.User user = conversation.getMucOptions().findUserByRealJid(contact.getJid().asBareJid());
if (user != null) {
clear(user);
}
clear(conversation); clear(conversation);
} }
} }
@ -216,7 +220,7 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
Jid jid = bookmark.getJid(); Jid jid = bookmark.getJid();
Account account = bookmark.getAccount(); Account account = bookmark.getAccount();
Contact contact = jid == null ? null : account.getRoster().getContact(jid); Contact contact = jid == null ? null : account.getRoster().getContact(jid);
if (contact != null && contact.getAvatar() != null) { if (contact != null && contact.getAvatarFilename() != null) {
return get(contact, size, cachedOnly); return get(contact, size, cachedOnly);
} }
String seed = jid != null ? jid.asBareJid().toString() : null; String seed = jid != null ? jid.asBareJid().toString() : null;
@ -400,14 +404,14 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
return get(message.getCounterparts(), size, cachedOnly); return get(message.getCounterparts(), size, cachedOnly);
} else if (message.getStatus() == Message.STATUS_RECEIVED) { } else if (message.getStatus() == Message.STATUS_RECEIVED) {
Contact c = message.getContact(); Contact c = message.getContact();
if (c != null && (c.getProfilePhoto() != null || c.getAvatar() != null)) { if (c != null && (c.getProfilePhoto() != null || c.getAvatarFilename() != null)) {
return get(c, size, cachedOnly); return get(c, size, cachedOnly);
} else if (conversation instanceof Conversation && message.getConversation().getMode() == Conversation.MODE_MULTI) { } else if (conversation instanceof Conversation && message.getConversation().getMode() == Conversation.MODE_MULTI) {
final Jid trueCounterpart = message.getTrueCounterpart(); final Jid trueCounterpart = message.getTrueCounterpart();
final MucOptions mucOptions = ((Conversation) conversation).getMucOptions(); final MucOptions mucOptions = ((Conversation) conversation).getMucOptions();
MucOptions.User user; MucOptions.User user;
if (trueCounterpart != null) { if (trueCounterpart != null) {
user = mucOptions.findUserByRealJid(trueCounterpart); user = mucOptions.findOrCreateUserByRealJid(trueCounterpart, message.getCounterpart());
} else { } else {
user = mucOptions.findUserByFullJid(message.getCounterpart()); user = mucOptions.findUserByFullJid(message.getCounterpart());
} }
@ -508,9 +512,9 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
Uri uri = null; Uri uri = null;
if (contact.getProfilePhoto() != null) { if (contact.getProfilePhoto() != null) {
uri = Uri.parse(contact.getProfilePhoto()); uri = Uri.parse(contact.getProfilePhoto());
} else if (contact.getAvatar() != null) { } else if (contact.getAvatarFilename() != null) {
uri = mXmppConnectionService.getFileBackend().getAvatarUri( uri = mXmppConnectionService.getFileBackend().getAvatarUri(
contact.getAvatar()); contact.getAvatarFilename());
} }
if (drawTile(canvas, uri, left, top, right, bottom)) { if (drawTile(canvas, uri, left, top, right, bottom)) {
return true; return true;

View file

@ -3114,6 +3114,14 @@ public class XmppConnectionService extends Service {
updateConversationUi(); updateConversationUi();
updateMucRosterUi(); updateMucRosterUi();
} }
if (user.getRealJid() != null) {
Contact contact = account.getRoster().getContact(user.getRealJid());
if (contact.setAvatar(avatar)) {
syncRoster(account);
getAvatarService().clear(contact);
updateRosterUi();
}
}
} }
} }
} }

View file

@ -874,7 +874,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
attachLocationToConversation(conversation, attachment.getUri()); attachLocationToConversation(conversation, attachment.getUri());
} else if (attachment.getType() == Attachment.Type.IMAGE) { } else if (attachment.getType() == Attachment.Type.IMAGE) {
Log.d(Config.LOGTAG, "ConversationsActivity.commitAttachments() - attaching image to conversations. CHOOSE_IMAGE"); Log.d(Config.LOGTAG, "ConversationsActivity.commitAttachments() - attaching image to conversations. CHOOSE_IMAGE");
attachImageToConversation(conversation, attachment.getUri()); attachImageToConversation(conversation, attachment.getUri());
} else { } else {
Log.d(Config.LOGTAG, "ConversationsActivity.commitAttachments() - attaching file to conversations. CHOOSE_FILE/RECORD_VOICE/RECORD_VIDEO"); Log.d(Config.LOGTAG, "ConversationsActivity.commitAttachments() - attaching file to conversations. CHOOSE_FILE/RECORD_VOICE/RECORD_VIDEO");
attachFileToConversation(conversation, attachment.getUri(), attachment.getMime()); attachFileToConversation(conversation, attachment.getUri(), attachment.getMime());
@ -901,7 +901,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
switch (requestCode) { switch (requestCode) {
case ATTACHMENT_CHOICE_TAKE_PHOTO: case ATTACHMENT_CHOICE_TAKE_PHOTO:
if (pendingTakePhotoUri.clear()) { if (pendingTakePhotoUri.clear()) {
Log.d(Config.LOGTAG,"cleared pending photo uri after negative activity result"); Log.d(Config.LOGTAG, "cleared pending photo uri after negative activity result");
} }
break; break;
} }
@ -1033,7 +1033,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
Jid tcp = message.getTrueCounterpart(); Jid tcp = message.getTrueCounterpart();
Jid cp = message.getCounterpart(); Jid cp = message.getCounterpart();
if (cp != null && !cp.isBareJid()) { if (cp != null && !cp.isBareJid()) {
User userByRealJid = tcp != null ? conversation.getMucOptions().findOrCreateUserByRealJid(tcp) : null; User userByRealJid = tcp != null ? conversation.getMucOptions().findOrCreateUserByRealJid(tcp, cp) : null;
final User user = userByRealJid != null ? userByRealJid : conversation.getMucOptions().findUserByFullJid(cp); final User user = userByRealJid != null ? userByRealJid : conversation.getMucOptions().findUserByFullJid(cp);
final PopupMenu popupMenu = new PopupMenu(getActivity(), v); final PopupMenu popupMenu = new PopupMenu(getActivity(), v);
popupMenu.inflate(R.menu.muc_details_context); popupMenu.inflate(R.menu.muc_details_context);
@ -2670,7 +2670,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
setScrollPosition(scrollState, lastMessageUuid); setScrollPosition(scrollState, lastMessageUuid);
} }
if (attachments != null && attachments.size() > 0) { if (attachments != null && attachments.size() > 0) {
Log.d(Config.LOGTAG,"had attachments on restore"); Log.d(Config.LOGTAG, "had attachments on restore");
mediaPreviewAdapter.addMediaPreviews(attachments); mediaPreviewAdapter.addMediaPreviews(attachments);
toggleInputMethod(); toggleInputMethod();
} }
@ -2682,7 +2682,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
Log.e(Config.LOGTAG, "cleared pending intent with unhandled result left"); Log.e(Config.LOGTAG, "cleared pending intent with unhandled result left");
} }
if (pendingScrollState.clear()) { if (pendingScrollState.clear()) {
Log.e(Config.LOGTAG,"cleared scroll state"); Log.e(Config.LOGTAG, "cleared scroll state");
} }
if (pendingTakePhotoUri.clear()) { if (pendingTakePhotoUri.clear()) {
Log.e(Config.LOGTAG, "cleared pending photo uri"); Log.e(Config.LOGTAG, "cleared pending photo uri");