aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-27 23:52:08 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-27 23:52:08 +0200
commit5a1105d37a87eaf1c369d9f8d9b7e67d6a0e1cd4 (patch)
treef3ca7e213d3adbfcbb929e10a6b35a2eb6f789e4
parent39194d6e1b4a5ebaabdc1afc7ffbdc6eede68aca (diff)
display avatar in groups
-rw-r--r--src/main/java/de/pixart/messenger/entities/MucOptions.java4
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java12
-rw-r--r--src/main/java/de/pixart/messenger/services/AvatarService.java15
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java90
4 files changed, 59 insertions, 62 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java
index 255eecc79..a6968b66f 100644
--- a/src/main/java/de/pixart/messenger/entities/MucOptions.java
+++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java
@@ -390,6 +390,10 @@ public class MucOptions {
this.features.addAll(features);
}
+ public String getAvatar() {
+ return account.getRoster().getContact(conversation.getJid()).getAvatar();
+ }
+
private void updateFormData(Data form) {
this.form = form;
}
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index d936af86f..6bb63dfd0 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -697,9 +697,7 @@ public class FileBackend {
avatar.width = options.outWidth;
avatar.type = options.outMimeType;
return avatar;
- } catch (IOException e) {
- return null;
- } catch (NoSuchAlgorithmException e) {
+ } catch (NoSuchAlgorithmException | IOException e) {
return null;
} finally {
close(is);
@@ -711,14 +709,13 @@ public class FileBackend {
return file.exists();
}
- public boolean save(Avatar avatar) {
+ public boolean save(final Avatar avatar) {
File file;
if (isAvatarCached(avatar)) {
file = new File(getAvatarPath(avatar.getFilename()));
avatar.size = file.length();
} else {
- String filename = getAvatarPath(avatar.getFilename());
- file = new File(filename + ".tmp");
+ file = new File(mXmppConnectionService.getCacheDir().getAbsolutePath() + "/" + UUID.randomUUID().toString());
file.getParentFile().mkdirs();
OutputStream os = null;
try {
@@ -733,6 +730,7 @@ public class FileBackend {
mDigestOutputStream.close();
String sha1sum = CryptoHelper.bytesToHex(digest.digest());
if (sha1sum.equals(avatar.sha1sum)) {
+ String filename = getAvatarPath(avatar.getFilename());
file.renameTo(new File(filename));
} else {
Log.d(Config.LOGTAG, "sha1sum mismatch for " + avatar.owner);
@@ -749,7 +747,7 @@ public class FileBackend {
return true;
}
- public String getAvatarPath(String avatar) {
+ private String getAvatarPath(String avatar) {
return mXmppConnectionService.getFilesDir().getAbsolutePath() + "/avatars/" + avatar;
}
diff --git a/src/main/java/de/pixart/messenger/services/AvatarService.java b/src/main/java/de/pixart/messenger/services/AvatarService.java
index d6cc3712c..f38102866 100644
--- a/src/main/java/de/pixart/messenger/services/AvatarService.java
+++ b/src/main/java/de/pixart/messenger/services/AvatarService.java
@@ -274,12 +274,15 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
if (bitmap != null || cachedOnly) {
return bitmap;
}
- final List<MucOptions.User> users = mucOptions.getUsersRelevantForNameAndAvatar();
- if (users.size() == 0) {
- Conversation c = mucOptions.getConversation();
- bitmap = getImpl(c.getName().toString(), c.getJid().asBareJid().toString(), size);
- } else {
- bitmap = getImpl(users, size);
+ bitmap = mXmppConnectionService.getFileBackend().getAvatar(mucOptions.getAvatar(), size);
+ if (bitmap == null) {
+ final List<MucOptions.User> users = mucOptions.getUsersRelevantForNameAndAvatar();
+ if (users.size() == 0) {
+ Conversation c = mucOptions.getConversation();
+ bitmap = getImpl(c.getName().toString(), c.getJid().asBareJid().toString(), size);
+ } else {
+ bitmap = getImpl(users, size);
+ }
}
this.mXmppConnectionService.getBitmapCache().put(KEY, bitmap);
return bitmap;
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 98c02a7b5..d0240251c 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -1761,10 +1761,10 @@ public class XmppConnectionService extends Service {
public List<Conversation> findAllConferencesWith(Contact contact) {
ArrayList<Conversation> results = new ArrayList<>();
- for (Conversation conversation : conversations) {
- if (conversation.getMode() == Conversation.MODE_MULTI
- && conversation.getMucOptions().isContactInRoom(contact)) {
- results.add(conversation);
+ for (final Conversation c : conversations) {
+ if (c.getMode() == Conversation.MODE_MULTI
+ && (c.getJid().asBareJid().equals(c.getJid().asBareJid()) || c.getMucOptions().isContactInRoom(contact))) {
+ results.add(c);
}
}
return results;
@@ -3190,57 +3190,49 @@ public class XmppConnectionService extends Service {
private void fetchAvatarPep(Account account, final Avatar avatar, final UiCallback<Avatar> callback) {
IqPacket packet = this.mIqGenerator.retrievePepAvatar(avatar);
- sendIqPacket(account, packet, new OnIqPacketReceived() {
-
- @Override
- public void onIqPacketReceived(Account account, IqPacket result) {
- synchronized (mInProgressAvatarFetches) {
- mInProgressAvatarFetches.remove(generateFetchKey(account, avatar));
- }
- final String ERROR = account.getJid().asBareJid()
- + ": fetching avatar for " + avatar.owner + " failed ";
- if (result.getType() == IqPacket.TYPE.RESULT) {
- avatar.image = mIqParser.avatarData(result);
- if (avatar.image != null) {
- if (getFileBackend().save(avatar)) {
- if (account.getJid().asBareJid().equals(avatar.owner)) {
- if (account.setAvatar(avatar.getFilename())) {
- databaseBackend.updateAccount(account);
- }
- getAvatarService().clear(account);
- updateConversationUi();
- updateAccountUi();
- } else {
- Contact contact = account.getRoster()
- .getContact(avatar.owner);
- contact.setAvatar(avatar);
- getAvatarService().clear(contact);
- updateConversationUi();
- updateRosterUi();
- }
- if (callback != null) {
- callback.success(avatar);
+ sendIqPacket(account, packet, (a, result) -> {
+ synchronized (mInProgressAvatarFetches) {
+ mInProgressAvatarFetches.remove(generateFetchKey(a, avatar));
+ }
+ final String ERROR = a.getJid().asBareJid() + ": fetching avatar for " + avatar.owner + " failed ";
+ if (result.getType() == IqPacket.TYPE.RESULT) {
+ avatar.image = mIqParser.avatarData(result);
+ if (avatar.image != null) {
+ if (getFileBackend().save(avatar)) {
+ if (a.getJid().asBareJid().equals(avatar.owner)) {
+ if (a.setAvatar(avatar.getFilename())) {
+ databaseBackend.updateAccount(a);
}
- Log.d(Config.LOGTAG, account.getJid().asBareJid()
- + ": successfully fetched pep avatar for " + avatar.owner);
- return;
+ getAvatarService().clear(a);
+ updateConversationUi();
+ updateAccountUi();
+ } else {
+ Contact contact = a.getRoster().getContact(avatar.owner);
+ contact.setAvatar(avatar);
+ getAvatarService().clear(contact);
+ updateConversationUi();
+ updateRosterUi();
}
- } else {
-
- Log.d(Config.LOGTAG, ERROR + "(parsing error)");
+ if (callback != null) {
+ callback.success(avatar);
+ }
+ Log.d(Config.LOGTAG, a.getJid().asBareJid()
+ + ": successfully fetched pep avatar for " + avatar.owner);
+ return;
}
} else {
- Element error = result.findChild("error");
- if (error == null) {
- Log.d(Config.LOGTAG, ERROR + "(server error)");
- } else {
- Log.d(Config.LOGTAG, ERROR + error.toString());
- }
+ Log.d(Config.LOGTAG, ERROR + "(parsing error)");
}
- if (callback != null) {
- callback.error(0, null);
+ } else {
+ Element error = result.findChild("error");
+ if (error == null) {
+ Log.d(Config.LOGTAG, ERROR + "(server error)");
+ } else {
+ Log.d(Config.LOGTAG, ERROR + error.toString());
}
-
+ }
+ if (callback != null) {
+ callback.error(0, null);
}
});
}