got rid of copyonwrite array list for messages
This commit is contained in:
parent
e8bf75d79b
commit
a201f9e53f
|
@ -1,8 +1,8 @@
|
||||||
package eu.siacs.conversations.entities;
|
package eu.siacs.conversations.entities;
|
||||||
|
|
||||||
import java.security.interfaces.DSAPublicKey;
|
import java.security.interfaces.DSAPublicKey;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -57,7 +57,7 @@ public class Conversation extends AbstractEntity {
|
||||||
|
|
||||||
private String nextPresence;
|
private String nextPresence;
|
||||||
|
|
||||||
private transient CopyOnWriteArrayList<Message> messages = null;
|
private transient ArrayList<Message> messages = new ArrayList<Message>();
|
||||||
private transient Account account = null;
|
private transient Account account = null;
|
||||||
|
|
||||||
private transient SessionImpl otrSession;
|
private transient SessionImpl otrSession;
|
||||||
|
@ -104,17 +104,6 @@ public class Conversation extends AbstractEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Message> getMessages() {
|
public List<Message> getMessages() {
|
||||||
if (messages == null) {
|
|
||||||
this.messages = new CopyOnWriteArrayList<Message>(); // prevent null
|
|
||||||
// pointer
|
|
||||||
}
|
|
||||||
|
|
||||||
// populate with Conversation (this)
|
|
||||||
|
|
||||||
for (Message msg : messages) {
|
|
||||||
msg.setConversation(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +154,7 @@ public class Conversation extends AbstractEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessages(CopyOnWriteArrayList<Message> msgs) {
|
public void setMessages(ArrayList<Message> msgs) {
|
||||||
this.messages = msgs;
|
this.messages = msgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,4 +496,17 @@ public class Conversation extends AbstractEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void add(Message message) {
|
||||||
|
message.setConversation(this);
|
||||||
|
synchronized (this.messages) {
|
||||||
|
this.messages.add(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAll(int index, List<Message> messages) {
|
||||||
|
synchronized (this.messages) {
|
||||||
|
this.messages.addAll(index, messages);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -469,7 +469,7 @@ public class MessageParser extends AbstractParser implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Conversation conversation = message.getConversation();
|
Conversation conversation = message.getConversation();
|
||||||
conversation.getMessages().add(message);
|
conversation.add(message);
|
||||||
if (packet.getType() != MessagePacket.TYPE_ERROR) {
|
if (packet.getType() != MessagePacket.TYPE_ERROR) {
|
||||||
if (message.getEncryption() == Message.ENCRYPTION_NONE
|
if (message.getEncryption() == Message.ENCRYPTION_NONE
|
||||||
|| mXmppConnectionService.saveEncryptedMessages()) {
|
|| mXmppConnectionService.saveEncryptedMessages()) {
|
||||||
|
|
|
@ -152,14 +152,14 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CopyOnWriteArrayList<Message> getMessages(
|
public ArrayList<Message> getMessages(
|
||||||
Conversation conversations, int limit) {
|
Conversation conversations, int limit) {
|
||||||
return getMessages(conversations, limit, -1);
|
return getMessages(conversations, limit, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CopyOnWriteArrayList<Message> getMessages(Conversation conversation,
|
public ArrayList<Message> getMessages(Conversation conversation,
|
||||||
int limit, long timestamp) {
|
int limit, long timestamp) {
|
||||||
CopyOnWriteArrayList<Message> list = new CopyOnWriteArrayList<Message>();
|
ArrayList<Message> list = new ArrayList<Message>();
|
||||||
SQLiteDatabase db = this.getReadableDatabase();
|
SQLiteDatabase db = this.getReadableDatabase();
|
||||||
Cursor cursor;
|
Cursor cursor;
|
||||||
if (timestamp == -1) {
|
if (timestamp == -1) {
|
||||||
|
@ -178,7 +178,9 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
if (cursor.getCount() > 0) {
|
if (cursor.getCount() > 0) {
|
||||||
cursor.moveToLast();
|
cursor.moveToLast();
|
||||||
do {
|
do {
|
||||||
list.add(Message.fromCursor(cursor));
|
Message message = Message.fromCursor(cursor);
|
||||||
|
message.setConversation(conversation);
|
||||||
|
list.add(message);
|
||||||
} while (cursor.moveToPrevious());
|
} while (cursor.moveToPrevious());
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
|
|
@ -307,7 +307,7 @@ public class JingleConnection implements Downloadable {
|
||||||
if (supportedFile) {
|
if (supportedFile) {
|
||||||
long size = Long.parseLong(fileSize.getContent());
|
long size = Long.parseLong(fileSize.getContent());
|
||||||
message.setBody(Long.toString(size));
|
message.setBody(Long.toString(size));
|
||||||
conversation.getMessages().add(message);
|
conversation.add(message);
|
||||||
mXmppConnectionService.updateConversationUi();
|
mXmppConnectionService.updateConversationUi();
|
||||||
if (size <= this.mJingleConnectionManager
|
if (size <= this.mJingleConnectionManager
|
||||||
.getAutoAcceptFileSize()) {
|
.getAutoAcceptFileSize()) {
|
||||||
|
@ -634,6 +634,7 @@ public class JingleConnection implements Downloadable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendFallbackToIbb() {
|
private void sendFallbackToIbb() {
|
||||||
|
Log.d(Config.LOGTAG,"sending fallback to ibb");
|
||||||
JinglePacket packet = this.bootstrapPacket("transport-replace");
|
JinglePacket packet = this.bootstrapPacket("transport-replace");
|
||||||
Content content = new Content(this.contentCreator, this.contentName);
|
Content content = new Content(this.contentCreator, this.contentName);
|
||||||
this.transportId = this.mJingleConnectionManager.nextRandomId();
|
this.transportId = this.mJingleConnectionManager.nextRandomId();
|
||||||
|
@ -645,6 +646,7 @@ public class JingleConnection implements Downloadable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean receiveFallbackToIbb(JinglePacket packet) {
|
private boolean receiveFallbackToIbb(JinglePacket packet) {
|
||||||
|
Log.d(Config.LOGTAG,"receiving fallack to ibb");
|
||||||
String receivedBlockSize = packet.getJingleContent().ibbTransport()
|
String receivedBlockSize = packet.getJingleContent().ibbTransport()
|
||||||
.getAttribute("block-size");
|
.getAttribute("block-size");
|
||||||
if (receivedBlockSize != null) {
|
if (receivedBlockSize != null) {
|
||||||
|
|
Loading…
Reference in New Issue