fixed #239 - show contact names and pictures in muc if real jid is known

This commit is contained in:
iNPUTmice 2014-07-29 14:42:17 +02:00
parent 861af75576
commit 1521b91b27
6 changed files with 230 additions and 133 deletions

View file

@ -36,6 +36,7 @@ public class Message extends AbstractEntity {
public static String CONVERSATION = "conversationUuid"; public static String CONVERSATION = "conversationUuid";
public static String COUNTERPART = "counterpart"; public static String COUNTERPART = "counterpart";
public static String TRUE_COUNTERPART = "trueCounterpart";
public static String BODY = "body"; public static String BODY = "body";
public static String TIME_SENT = "timeSent"; public static String TIME_SENT = "timeSent";
public static String ENCRYPTION = "encryption"; public static String ENCRYPTION = "encryption";
@ -44,6 +45,7 @@ public class Message extends AbstractEntity {
protected String conversationUuid; protected String conversationUuid;
protected String counterpart; protected String counterpart;
protected String trueCounterpart;
protected String body; protected String body;
protected String encryptedBody; protected String encryptedBody;
protected long timeSent; protected long timeSent;
@ -62,21 +64,22 @@ public class Message extends AbstractEntity {
public Message(Conversation conversation, String body, int encryption) { public Message(Conversation conversation, String body, int encryption) {
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(), this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),
conversation.getContactJid(), body, System.currentTimeMillis(), encryption, conversation.getContactJid(), null, body, System.currentTimeMillis(), encryption,
Message.STATUS_UNSEND,TYPE_TEXT); Message.STATUS_UNSEND,TYPE_TEXT);
this.conversation = conversation; this.conversation = conversation;
} }
public Message(Conversation conversation, String counterpart, String body, int encryption, int status) { public Message(Conversation conversation, String counterpart, String body, int encryption, int status) {
this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),counterpart, body, System.currentTimeMillis(), encryption,status,TYPE_TEXT); this(java.util.UUID.randomUUID().toString(), conversation.getUuid(),counterpart, null, body, System.currentTimeMillis(), encryption,status,TYPE_TEXT);
this.conversation = conversation; this.conversation = conversation;
} }
public Message(String uuid, String conversationUUid, String counterpart, public Message(String uuid, String conversationUUid, String counterpart, String trueCounterpart,
String body, long timeSent, int encryption, int status, int type) { String body, long timeSent, int encryption, int status, int type) {
this.uuid = uuid; this.uuid = uuid;
this.conversationUuid = conversationUUid; this.conversationUuid = conversationUUid;
this.counterpart = counterpart; this.counterpart = counterpart;
this.trueCounterpart = trueCounterpart;
this.body = body; this.body = body;
this.timeSent = timeSent; this.timeSent = timeSent;
this.encryption = encryption; this.encryption = encryption;
@ -90,6 +93,7 @@ public class Message extends AbstractEntity {
values.put(UUID, uuid); values.put(UUID, uuid);
values.put(CONVERSATION, conversationUuid); values.put(CONVERSATION, conversationUuid);
values.put(COUNTERPART, counterpart); values.put(COUNTERPART, counterpart);
values.put(TRUE_COUNTERPART,trueCounterpart);
values.put(BODY, body); values.put(BODY, body);
values.put(TIME_SENT, timeSent); values.put(TIME_SENT, timeSent);
values.put(ENCRYPTION, encryption); values.put(ENCRYPTION, encryption);
@ -109,6 +113,24 @@ public class Message extends AbstractEntity {
public String getCounterpart() { public String getCounterpart() {
return counterpart; return counterpart;
} }
public Contact getContact() {
if (this.conversation.getMode() == Conversation.MODE_SINGLE) {
return this.conversation.getContact();
} else {
if (this.trueCounterpart == null) {
return null;
} else {
Account account = this.conversation.getAccount();
Contact contact = account.getRoster().getContact(this.trueCounterpart);
if (contact.showInRoster()) {
return contact;
} else {
return null;
}
}
}
}
public String getBody() { public String getBody() {
return body; return body;
@ -144,6 +166,7 @@ public class Message extends AbstractEntity {
return new Message(cursor.getString(cursor.getColumnIndex(UUID)), return new Message(cursor.getString(cursor.getColumnIndex(UUID)),
cursor.getString(cursor.getColumnIndex(CONVERSATION)), cursor.getString(cursor.getColumnIndex(CONVERSATION)),
cursor.getString(cursor.getColumnIndex(COUNTERPART)), cursor.getString(cursor.getColumnIndex(COUNTERPART)),
cursor.getString(cursor.getColumnIndex(TRUE_COUNTERPART)),
cursor.getString(cursor.getColumnIndex(BODY)), cursor.getString(cursor.getColumnIndex(BODY)),
cursor.getLong(cursor.getColumnIndex(TIME_SENT)), cursor.getLong(cursor.getColumnIndex(TIME_SENT)),
cursor.getInt(cursor.getColumnIndex(ENCRYPTION)), cursor.getInt(cursor.getColumnIndex(ENCRYPTION)),
@ -207,6 +230,10 @@ public class Message extends AbstractEntity {
} }
} }
public void setTrueCounterpart(String trueCounterpart) {
this.trueCounterpart = trueCounterpart;
}
public String getPresence() { public String getPresence() {
String[] counterparts = this.counterpart.split("/"); String[] counterparts = this.counterpart.split("/");
if (counterparts.length == 2) { if (counterparts.length == 2) {

View file

@ -14,11 +14,11 @@ public class MucOptions {
public static final int ERROR_NO_ERROR = 0; public static final int ERROR_NO_ERROR = 0;
public static final int ERROR_NICK_IN_USE = 1; public static final int ERROR_NICK_IN_USE = 1;
public static final int ERROR_ROOM_NOT_FOUND = 2; public static final int ERROR_ROOM_NOT_FOUND = 2;
public interface OnRenameListener { public interface OnRenameListener {
public void onRename(boolean success); public void onRename(boolean success);
} }
public class User { public class User {
public static final int ROLE_MODERATOR = 3; public static final int ROLE_MODERATOR = 3;
public static final int ROLE_NONE = 0; public static final int ROLE_NONE = 0;
@ -29,22 +29,33 @@ public class MucOptions {
public static final int AFFILIATION_MEMBER = 2; public static final int AFFILIATION_MEMBER = 2;
public static final int AFFILIATION_OUTCAST = 1; public static final int AFFILIATION_OUTCAST = 1;
public static final int AFFILIATION_NONE = 0; public static final int AFFILIATION_NONE = 0;
private int role; private int role;
private int affiliation; private int affiliation;
private String name; private String name;
private String jid;
private long pgpKeyId = 0; private long pgpKeyId = 0;
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String user) { public void setName(String user) {
this.name = user; this.name = user;
} }
public void setJid(String jid) {
this.jid = jid;
}
public String getJid() {
return this.jid;
}
public int getRole() { public int getRole() {
return this.role; return this.role;
} }
public void setRole(String role) { public void setRole(String role) {
role = role.toLowerCase(); role = role.toLowerCase();
if (role.equals("moderator")) { if (role.equals("moderator")) {
@ -57,9 +68,11 @@ public class MucOptions {
this.role = ROLE_NONE; this.role = ROLE_NONE;
} }
} }
public int getAffiliation() { public int getAffiliation() {
return this.affiliation; return this.affiliation;
} }
public void setAffiliation(String affiliation) { public void setAffiliation(String affiliation) {
if (affiliation.equalsIgnoreCase("admin")) { if (affiliation.equalsIgnoreCase("admin")) {
this.affiliation = AFFILIATION_ADMIN; this.affiliation = AFFILIATION_ADMIN;
@ -73,14 +86,16 @@ public class MucOptions {
this.affiliation = AFFILIATION_NONE; this.affiliation = AFFILIATION_NONE;
} }
} }
public void setPgpKeyId(long id) { public void setPgpKeyId(long id) {
this.pgpKeyId = id; this.pgpKeyId = id;
} }
public long getPgpKeyId() { public long getPgpKeyId() {
return this.pgpKeyId; return this.pgpKeyId;
} }
} }
private Account account; private Account account;
private List<User> users = new CopyOnWriteArrayList<User>(); private List<User> users = new CopyOnWriteArrayList<User>();
private Conversation conversation; private Conversation conversation;
@ -95,44 +110,47 @@ public class MucOptions {
public MucOptions(Account account) { public MucOptions(Account account) {
this.account = account; this.account = account;
} }
public void deleteUser(String name) { public void deleteUser(String name) {
for(int i = 0; i < users.size(); ++i) { for (int i = 0; i < users.size(); ++i) {
if (users.get(i).getName().equals(name)) { if (users.get(i).getName().equals(name)) {
users.remove(i); users.remove(i);
return; return;
} }
} }
} }
public void addUser(User user) { public void addUser(User user) {
for(int i = 0; i < users.size(); ++i) { for (int i = 0; i < users.size(); ++i) {
if (users.get(i).getName().equals(user.getName())) { if (users.get(i).getName().equals(user.getName())) {
users.set(i, user); users.set(i, user);
return; return;
} }
} }
users.add(user); users.add(user);
} }
public void processPacket(PresencePacket packet, PgpEngine pgp) { public void processPacket(PresencePacket packet, PgpEngine pgp) {
String[] fromParts = packet.getFrom().split("/"); String[] fromParts = packet.getFrom().split("/");
if (fromParts.length>=2) { if (fromParts.length >= 2) {
String name = fromParts[1]; String name = fromParts[1];
String type = packet.getAttribute("type"); String type = packet.getAttribute("type");
if (type==null) { if (type == null) {
User user = new User(); User user = new User();
Element item = packet.findChild("x","http://jabber.org/protocol/muc#user").findChild("item"); Element item = packet.findChild("x",
"http://jabber.org/protocol/muc#user")
.findChild("item");
user.setName(name); user.setName(name);
user.setAffiliation(item.getAttribute("affiliation")); user.setAffiliation(item.getAttribute("affiliation"));
user.setRole(item.getAttribute("role")); user.setRole(item.getAttribute("role"));
user.setJid(item.getAttribute("jid"));
user.setName(name); user.setName(name);
if (name.equals(this.joinnick)) { if (name.equals(this.joinnick)) {
this.isOnline = true; this.isOnline = true;
this.error = ERROR_NO_ERROR; this.error = ERROR_NO_ERROR;
self = user; self = user;
if (aboutToRename) { if (aboutToRename) {
if (renameListener!=null) { if (renameListener != null) {
renameListener.onRename(true); renameListener.onRename(true);
} }
aboutToRename = false; aboutToRename = false;
@ -141,8 +159,7 @@ public class MucOptions {
addUser(user); addUser(user);
} }
if (pgp != null) { if (pgp != null) {
Element x = packet.findChild("x", Element x = packet.findChild("x", "jabber:x:signed");
"jabber:x:signed");
if (x != null) { if (x != null) {
Element status = packet.findChild("status"); Element status = packet.findChild("status");
String msg; String msg;
@ -151,7 +168,8 @@ public class MucOptions {
} else { } else {
msg = ""; msg = "";
} }
user.setPgpKeyId(pgp.fetchKeyId(account,msg, x.getContent())); user.setPgpKeyId(pgp.fetchKeyId(account, msg,
x.getContent()));
} }
} }
} else if (type.equals("unavailable")) { } else if (type.equals("unavailable")) {
@ -160,26 +178,27 @@ public class MucOptions {
Element error = packet.findChild("error"); Element error = packet.findChild("error");
if (error.hasChild("conflict")) { if (error.hasChild("conflict")) {
if (aboutToRename) { if (aboutToRename) {
if (renameListener!=null) { if (renameListener != null) {
renameListener.onRename(false); renameListener.onRename(false);
} }
aboutToRename = false; aboutToRename = false;
this.setJoinNick(getActualNick()); this.setJoinNick(getActualNick());
} else { } else {
this.error = ERROR_NICK_IN_USE; this.error = ERROR_NICK_IN_USE;
} }
} }
} }
} }
} }
public List<User> getUsers() { public List<User> getUsers() {
return this.users; return this.users;
} }
public String getProposedNick() { public String getProposedNick() {
String[] mucParts = conversation.getContactJid().split("/"); String[] mucParts = conversation.getContactJid().split("/");
if (conversation.getBookmark() != null && conversation.getBookmark().getNick() != null) { if (conversation.getBookmark() != null
&& conversation.getBookmark().getNick() != null) {
return conversation.getBookmark().getNick(); return conversation.getBookmark().getNick();
} else { } else {
if (mucParts.length == 2) { if (mucParts.length == 2) {
@ -189,27 +208,27 @@ public class MucOptions {
} }
} }
} }
public String getActualNick() { public String getActualNick() {
if (this.self.getName()!=null) { if (this.self.getName() != null) {
return this.self.getName(); return this.self.getName();
} else { } else {
return this.getProposedNick(); return this.getProposedNick();
} }
} }
public void setJoinNick(String nick) { public void setJoinNick(String nick) {
this.joinnick = nick; this.joinnick = nick;
} }
public void setConversation(Conversation conversation) { public void setConversation(Conversation conversation) {
this.conversation = conversation; this.conversation = conversation;
} }
public boolean online() { public boolean online() {
return this.isOnline; return this.isOnline;
} }
public int getError() { public int getError() {
return this.error; return this.error;
} }
@ -217,7 +236,7 @@ public class MucOptions {
public void setOnRenameListener(OnRenameListener listener) { public void setOnRenameListener(OnRenameListener listener) {
this.renameListener = listener; this.renameListener = listener;
} }
public OnRenameListener getOnRenameListener() { public OnRenameListener getOnRenameListener() {
return this.renameListener; return this.renameListener;
} }
@ -235,7 +254,7 @@ public class MucOptions {
public void setSubject(String content) { public void setSubject(String content) {
this.subject = content; this.subject = content;
} }
public String getSubject() { public String getSubject() {
return this.subject; return this.subject;
} }
@ -243,33 +262,33 @@ public class MucOptions {
public void flagAboutToRename() { public void flagAboutToRename() {
this.aboutToRename = true; this.aboutToRename = true;
} }
public long[] getPgpKeyIds() { public long[] getPgpKeyIds() {
List<Long> ids = new ArrayList<Long>(); List<Long> ids = new ArrayList<Long>();
for(User user : getUsers()) { for (User user : getUsers()) {
if(user.getPgpKeyId()!=0) { if (user.getPgpKeyId() != 0) {
ids.add(user.getPgpKeyId()); ids.add(user.getPgpKeyId());
} }
} }
long[] primitivLongArray = new long[ids.size()]; long[] primitivLongArray = new long[ids.size()];
for(int i = 0; i < ids.size(); ++i) { for (int i = 0; i < ids.size(); ++i) {
primitivLongArray[i] = ids.get(i); primitivLongArray[i] = ids.get(i);
} }
return primitivLongArray; return primitivLongArray;
} }
public boolean pgpKeysInUse() { public boolean pgpKeysInUse() {
for(User user : getUsers()) { for (User user : getUsers()) {
if (user.getPgpKeyId()!=0) { if (user.getPgpKeyId() != 0) {
return true; return true;
} }
} }
return false; return false;
} }
public boolean everybodyHasKeys() { public boolean everybodyHasKeys() {
for(User user : getUsers()) { for (User user : getUsers()) {
if (user.getPgpKeyId()==0) { if (user.getPgpKeyId() == 0) {
return false; return false;
} }
} }
@ -277,6 +296,16 @@ public class MucOptions {
} }
public String getJoinJid() { public String getJoinJid() {
return this.conversation.getContactJid().split("/")[0]+"/"+this.joinnick; return this.conversation.getContactJid().split("/")[0] + "/"
+ this.joinnick;
}
public String getTrueCounterpart(String counterpart) {
for(User user : this.getUsers()) {
if (user.getName().equals(counterpart)) {
return user.getJid();
}
}
return null;
} }
} }

View file

@ -146,6 +146,9 @@ public class MessageParser extends AbstractParser implements
Message.ENCRYPTION_PGP, status); Message.ENCRYPTION_PGP, status);
} }
finishedMessage.setTime(getTimestamp(packet)); finishedMessage.setTime(getTimestamp(packet));
if (status == Message.STATUS_RECIEVED) {
finishedMessage.setTrueCounterpart(conversation.getMucOptions().getTrueCounterpart(counterPart));
}
return finishedMessage; return finishedMessage;
} }

View file

@ -20,15 +20,17 @@ public class DatabaseBackend extends SQLiteOpenHelper {
private static DatabaseBackend instance = null; private static DatabaseBackend instance = null;
private static final String DATABASE_NAME = "history"; private static final String DATABASE_NAME = "history";
private static final int DATABASE_VERSION = 5; private static final int DATABASE_VERSION = 6;
private static String CREATE_CONTATCS_STATEMENT = "create table " private static String CREATE_CONTATCS_STATEMENT = "create table "
+ Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, " + Contact.SERVERNAME + " TEXT, " + Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, "
+ Contact.SYSTEMNAME + " TEXT," + Contact.JID + " TEXT," + Contact.SERVERNAME + " TEXT, " + Contact.SYSTEMNAME + " TEXT,"
+ Contact.KEYS + " TEXT," + Contact.PHOTOURI + " TEXT," + Contact.JID + " TEXT," + Contact.KEYS + " TEXT,"
+ Contact.OPTIONS + " NUMBER," + Contact.SYSTEMACCOUNT + Contact.PHOTOURI + " TEXT," + Contact.OPTIONS + " NUMBER,"
+ " NUMBER, " + "FOREIGN KEY(" + Contact.ACCOUNT + ") REFERENCES " + Contact.SYSTEMACCOUNT + " NUMBER, " + "FOREIGN KEY("
+ Account.TABLENAME + "(" + Account.UUID + ") ON DELETE CASCADE, UNIQUE("+Contact.ACCOUNT+", "+Contact.JID+") ON CONFLICT REPLACE);"; + Contact.ACCOUNT + ") REFERENCES " + Account.TABLENAME + "("
+ Account.UUID + ") ON DELETE CASCADE, UNIQUE(" + Contact.ACCOUNT
+ ", " + Contact.JID + ") ON CONFLICT REPLACE);";
public DatabaseBackend(Context context) { public DatabaseBackend(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION); super(context, DATABASE_NAME, null, DATABASE_VERSION);
@ -54,8 +56,9 @@ public class DatabaseBackend extends SQLiteOpenHelper {
db.execSQL("create table " + Message.TABLENAME + "( " + Message.UUID db.execSQL("create table " + Message.TABLENAME + "( " + Message.UUID
+ " TEXT PRIMARY KEY, " + Message.CONVERSATION + " TEXT, " + " TEXT PRIMARY KEY, " + Message.CONVERSATION + " TEXT, "
+ Message.TIME_SENT + " NUMBER, " + Message.COUNTERPART + Message.TIME_SENT + " NUMBER, " + Message.COUNTERPART
+ " TEXT, " + Message.BODY + " TEXT, " + Message.ENCRYPTION + " TEXT, " + Message.TRUE_COUNTERPART + " TEXT,"
+ " NUMBER, " + Message.STATUS + " NUMBER," + Message.TYPE + Message.BODY + " TEXT, " + Message.ENCRYPTION + " NUMBER, "
+ Message.STATUS + " NUMBER," + Message.TYPE
+ " NUMBER, FOREIGN KEY(" + Message.CONVERSATION + " NUMBER, FOREIGN KEY(" + Message.CONVERSATION
+ ") REFERENCES " + Conversation.TABLENAME + "(" + ") REFERENCES " + Conversation.TABLENAME + "("
+ Conversation.UUID + ") ON DELETE CASCADE);"); + Conversation.UUID + ") ON DELETE CASCADE);");
@ -74,9 +77,14 @@ public class DatabaseBackend extends SQLiteOpenHelper {
+ Message.TYPE + " NUMBER"); + Message.TYPE + " NUMBER");
} }
if (oldVersion < 5 && newVersion >= 5) { if (oldVersion < 5 && newVersion >= 5) {
db.execSQL("DROP TABLE "+Contact.TABLENAME); db.execSQL("DROP TABLE " + Contact.TABLENAME);
db.execSQL(CREATE_CONTATCS_STATEMENT); db.execSQL(CREATE_CONTATCS_STATEMENT);
db.execSQL("UPDATE "+Account.TABLENAME+ " SET "+Account.ROSTERVERSION+" = NULL"); db.execSQL("UPDATE " + Account.TABLENAME + " SET "
+ Account.ROSTERVERSION + " = NULL");
}
if (oldVersion < 6 && newVersion >= 6) {
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN "
+ Message.TRUE_COUNTERPART + " TEXT");
} }
} }
@ -128,24 +136,27 @@ public class DatabaseBackend extends SQLiteOpenHelper {
} }
return list; return list;
} }
public CopyOnWriteArrayList<Message> getMessages(Conversation conversations, int limit) { public CopyOnWriteArrayList<Message> getMessages(
return getMessages(conversations, limit,-1); Conversation conversations, int limit) {
return getMessages(conversations, limit, -1);
} }
public CopyOnWriteArrayList<Message> getMessages(Conversation conversation, int limit, long timestamp) { public CopyOnWriteArrayList<Message> getMessages(Conversation conversation,
int limit, long timestamp) {
CopyOnWriteArrayList<Message> list = new CopyOnWriteArrayList<Message>(); CopyOnWriteArrayList<Message> list = new CopyOnWriteArrayList<Message>();
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor; Cursor cursor;
if (timestamp==-1) { if (timestamp == -1) {
String[] selectionArgs = { conversation.getUuid() }; String[] selectionArgs = { conversation.getUuid() };
cursor = db.query(Message.TABLENAME, null, Message.CONVERSATION cursor = db.query(Message.TABLENAME, null, Message.CONVERSATION
+ "=?", selectionArgs, null, null, Message.TIME_SENT + " DESC", + "=?", selectionArgs, null, null, Message.TIME_SENT
String.valueOf(limit)); + " DESC", String.valueOf(limit));
} else { } else {
String[] selectionArgs = { conversation.getUuid() , ""+timestamp}; String[] selectionArgs = { conversation.getUuid(), "" + timestamp };
cursor = db.query(Message.TABLENAME, null, Message.CONVERSATION cursor = db.query(Message.TABLENAME, null, Message.CONVERSATION
+ "=? and "+Message.TIME_SENT+"<?", selectionArgs, null, null, Message.TIME_SENT + " DESC", + "=? and " + Message.TIME_SENT + "<?", selectionArgs,
null, null, Message.TIME_SENT + " DESC",
String.valueOf(limit)); String.valueOf(limit));
} }
if (cursor.getCount() > 0) { if (cursor.getCount() > 0) {
@ -225,16 +236,16 @@ public class DatabaseBackend extends SQLiteOpenHelper {
roster.initContact(Contact.fromCursor(cursor)); roster.initContact(Contact.fromCursor(cursor));
} }
} }
public void writeRoster(Roster roster) { public void writeRoster(Roster roster) {
Account account = roster.getAccount(); Account account = roster.getAccount();
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
for(Contact contact : roster.getContacts()) { for (Contact contact : roster.getContacts()) {
if (contact.getOption(Contact.Options.IN_ROSTER)) { if (contact.getOption(Contact.Options.IN_ROSTER)) {
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 + "=?";
String[] whereArgs = {account.getUuid(), contact.getJid()}; String[] whereArgs = { account.getUuid(), contact.getJid() };
db.delete(Contact.TABLENAME, where, whereArgs); db.delete(Contact.TABLENAME, where, whereArgs);
} }
} }

View file

@ -7,6 +7,8 @@ import org.openintents.openpgp.util.OpenPgpUtils;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.MucOptions.OnRenameListener; import eu.siacs.conversations.entities.MucOptions.OnRenameListener;
@ -54,7 +56,7 @@ public class ConferenceDetailsActivity extends XmppActivity {
private List<User> users = new ArrayList<MucOptions.User>(); private List<User> users = new ArrayList<MucOptions.User>();
private OnConversationUpdate onConvChanged = new OnConversationUpdate() { private OnConversationUpdate onConvChanged = new OnConversationUpdate() {
@Override @Override
public void onConversationUpdate() { public void onConversationUpdate() {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@ -150,13 +152,14 @@ public class ConferenceDetailsActivity extends XmppActivity {
this.uuid = getIntent().getExtras().getString("uuid"); this.uuid = getIntent().getExtras().getString("uuid");
} }
if (uuid != null) { if (uuid != null) {
this.conversation = xmppConnectionService.findConversationByUuid(uuid); this.conversation = xmppConnectionService
.findConversationByUuid(uuid);
if (this.conversation != null) { if (this.conversation != null) {
populateView(); populateView();
} }
} }
} }
@Override @Override
protected void onStop() { protected void onStop() {
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
@ -164,33 +167,34 @@ public class ConferenceDetailsActivity extends XmppActivity {
} }
super.onStop(); super.onStop();
} }
protected void registerListener() { protected void registerListener() {
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
xmppConnectionService xmppConnectionService
.setOnConversationListChangedListener(this.onConvChanged); .setOnConversationListChangedListener(this.onConvChanged);
xmppConnectionService.setOnRenameListener(new OnRenameListener() { xmppConnectionService.setOnRenameListener(new OnRenameListener() {
@Override @Override
public void onRename(final boolean success) { public void onRename(final boolean success) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
populateView(); populateView();
if (success) { if (success) {
Toast.makeText(ConferenceDetailsActivity.this, Toast.makeText(
getString(R.string.your_nick_has_been_changed), ConferenceDetailsActivity.this,
Toast.LENGTH_SHORT).show(); getString(R.string.your_nick_has_been_changed),
} else { Toast.LENGTH_SHORT).show();
Toast.makeText(ConferenceDetailsActivity.this, } else {
getString(R.string.nick_in_use), Toast.makeText(ConferenceDetailsActivity.this,
Toast.LENGTH_SHORT).show(); getString(R.string.nick_in_use),
Toast.LENGTH_SHORT).show();
}
} }
} });
}); }
} });
});
} }
} }
@ -222,28 +226,42 @@ public class ConferenceDetailsActivity extends XmppActivity {
this.users.addAll(conversation.getMucOptions().getUsers()); this.users.addAll(conversation.getMucOptions().getUsers());
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
membersView.removeAllViews(); membersView.removeAllViews();
for (final User contact : conversation.getMucOptions().getUsers()) { Account account = conversation.getAccount();
View view = (View) inflater.inflate(R.layout.contact, null); for (final User user : conversation.getMucOptions().getUsers()) {
TextView displayName = (TextView) view View view = (View) inflater.inflate(R.layout.contact, membersView,
false);
TextView name = (TextView) view
.findViewById(R.id.contact_display_name); .findViewById(R.id.contact_display_name);
TextView key = (TextView) view.findViewById(R.id.key); TextView key = (TextView) view.findViewById(R.id.key);
displayName.setText(contact.getName());
TextView role = (TextView) view.findViewById(R.id.contact_jid); TextView role = (TextView) view.findViewById(R.id.contact_jid);
role.setText(getReadableRole(contact.getRole())); role.setText(getReadableRole(user.getRole()));
if (contact.getPgpKeyId() != 0) { if (user.getPgpKeyId() != 0) {
key.setVisibility(View.VISIBLE); key.setVisibility(View.VISIBLE);
key.setOnClickListener(new OnClickListener() { key.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
viewPgpKey(contact); viewPgpKey(user);
} }
}); });
key.setText(OpenPgpUtils.convertKeyIdToHex(contact key.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
.getPgpKeyId())); }
Bitmap bm;
if (user.getJid() != null) {
Contact contact = account.getRoster().getContact(user.getJid());
if (contact.showInRoster()) {
bm = contact.getImage(48, this);
name.setText(contact.getDisplayName());
} else {
bm = UIHelper.getContactPicture(user.getName(), 48, this,
false);
name.setText(user.getName());
}
} else {
bm = UIHelper
.getContactPicture(user.getName(), 48, this, false);
name.setText(user.getName());
} }
Bitmap bm = UIHelper.getContactPicture(contact.getName(), 48, this,
false);
ImageView iv = (ImageView) view.findViewById(R.id.contact_photo); ImageView iv = (ImageView) view.findViewById(R.id.contact_photo);
iv.setImageBitmap(bm); iv.setImageBitmap(bm);
membersView.addView(view); membersView.addView(view);

View file

@ -42,17 +42,12 @@ public class MessageAdapter extends ArrayAdapter<Message> {
private BitmapCache mBitmapCache = new BitmapCache(); private BitmapCache mBitmapCache = new BitmapCache();
private DisplayMetrics metrics; private DisplayMetrics metrics;
private boolean useSubject = true;
private OnContactPictureClicked mOnContactPictureClickedListener; private OnContactPictureClicked mOnContactPictureClickedListener;
public MessageAdapter(ConversationActivity activity, List<Message> messages) { public MessageAdapter(ConversationActivity activity, List<Message> messages) {
super(activity, 0, messages); super(activity, 0, messages);
this.activity = activity; this.activity = activity;
metrics = getContext().getResources().getDisplayMetrics(); metrics = getContext().getResources().getDisplayMetrics();
SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(getContext());
useSubject = preferences.getBoolean("use_subject_in_muc", true);
} }
private Bitmap getSelfBitmap() { private Bitmap getSelfBitmap() {
@ -130,7 +125,12 @@ public class MessageAdapter extends ArrayAdapter<Message> {
error = true; error = true;
default: default:
if (multiReceived) { if (multiReceived) {
info = message.getCounterpart(); Contact contact = message.getContact();
if (contact != null) {
info = contact.getDisplayName();
} else {
info = message.getCounterpart();
}
} }
break; break;
} }
@ -277,7 +277,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
switch (type) { switch (type) {
case SENT: case SENT:
view = (View) activity.getLayoutInflater().inflate( view = (View) activity.getLayoutInflater().inflate(
R.layout.message_sent, null); R.layout.message_sent, parent,false);
viewHolder.message_box = (LinearLayout) view viewHolder.message_box = (LinearLayout) view
.findViewById(R.id.message_box); .findViewById(R.id.message_box);
viewHolder.contact_picture = (ImageView) view viewHolder.contact_picture = (ImageView) view
@ -295,7 +295,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
break; break;
case RECIEVED: case RECIEVED:
view = (View) activity.getLayoutInflater().inflate( view = (View) activity.getLayoutInflater().inflate(
R.layout.message_recieved, null); R.layout.message_recieved, parent,false);
viewHolder.message_box = (LinearLayout) view viewHolder.message_box = (LinearLayout) view
.findViewById(R.id.message_box); .findViewById(R.id.message_box);
viewHolder.contact_picture = (ImageView) view viewHolder.contact_picture = (ImageView) view
@ -307,9 +307,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
viewHolder.contact_picture.setImageBitmap(mBitmapCache.get( viewHolder.contact_picture.setImageBitmap(mBitmapCache.get(
item.getConversation().getName(useSubject), item item.getConversation().getContact(), getContext()));
.getConversation().getContact(),
getContext()));
} }
viewHolder.indicator = (ImageView) view viewHolder.indicator = (ImageView) view
@ -324,15 +322,13 @@ public class MessageAdapter extends ArrayAdapter<Message> {
break; break;
case STATUS: case STATUS:
view = (View) activity.getLayoutInflater().inflate( view = (View) activity.getLayoutInflater().inflate(
R.layout.message_status, null); R.layout.message_status, parent,false);
viewHolder.contact_picture = (ImageView) view viewHolder.contact_picture = (ImageView) view
.findViewById(R.id.message_photo); .findViewById(R.id.message_photo);
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
viewHolder.contact_picture.setImageBitmap(mBitmapCache.get( viewHolder.contact_picture.setImageBitmap(mBitmapCache.get(
item.getConversation().getName(useSubject), item item.getConversation().getContact(), getContext()));
.getConversation().getContact(),
getContext()));
viewHolder.contact_picture.setAlpha(128); viewHolder.contact_picture.setAlpha(128);
viewHolder.contact_picture viewHolder.contact_picture
.setOnClickListener(new OnClickListener() { .setOnClickListener(new OnClickListener() {
@ -366,8 +362,14 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (type == RECIEVED) { if (type == RECIEVED) {
if (item.getConversation().getMode() == Conversation.MODE_MULTI) { if (item.getConversation().getMode() == Conversation.MODE_MULTI) {
viewHolder.contact_picture.setImageBitmap(mBitmapCache.get( Contact contact = item.getContact();
item.getCounterpart(), null, getContext())); if (contact != null) {
viewHolder.contact_picture.setImageBitmap(mBitmapCache.get(
contact, getContext()));
} else {
viewHolder.contact_picture.setImageBitmap(mBitmapCache.get(
item.getCounterpart(), getContext()));
}
viewHolder.contact_picture viewHolder.contact_picture
.setOnClickListener(new OnClickListener() { .setOnClickListener(new OnClickListener() {
@ -453,20 +455,27 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} }
private class BitmapCache { private class BitmapCache {
private HashMap<String, Bitmap> bitmaps = new HashMap<String, Bitmap>(); private HashMap<String, Bitmap> contactBitmaps = new HashMap<String, Bitmap>();
private HashMap<String, Bitmap> unknownBitmaps = new HashMap<String, Bitmap>();
public Bitmap get(String name, Contact contact, Context context) { public Bitmap get(Contact contact, Context context) {
if (bitmaps.containsKey(name)) { if (contactBitmaps.containsKey(contact.getJid())) {
return bitmaps.get(name); return contactBitmaps.get(contact.getJid());
} else { } else {
Bitmap bm; Bitmap bm = UIHelper.getContactPicture(contact, 48, context,
if (contact != null) { false);
bm = UIHelper contactBitmaps.put(contact.getJid(), bm);
.getContactPicture(contact, 48, context, false); return bm;
} else { }
bm = UIHelper.getContactPicture(name, 48, context, false); }
}
bitmaps.put(name, bm); public Bitmap get(String name, Context context) {
if (unknownBitmaps.containsKey(name)) {
return unknownBitmaps.get(name);
} else {
Bitmap bm = UIHelper
.getContactPicture(name, 48, context, false);
unknownBitmaps.put(name, bm);
return bm; return bm;
} }
} }