aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/entities
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-30 23:38:29 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-30 23:38:29 +0200
commitce2ba629bd91897f74e2d1dee38f90671b0f28f8 (patch)
tree678491f31abef9c735e9bada9ba20204c5cd1c2f /src/main/java/de/pixart/messenger/entities
parent032fbad95ce7384de922d7c3c9ac53303ab11732 (diff)
very much unoptimized search functionality
Diffstat (limited to 'src/main/java/de/pixart/messenger/entities')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java5
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversational.java47
-rw-r--r--src/main/java/de/pixart/messenger/entities/IndividualMessage.java106
-rw-r--r--src/main/java/de/pixart/messenger/entities/Message.java67
-rw-r--r--src/main/java/de/pixart/messenger/entities/StubConversation.java73
5 files changed, 268 insertions, 30 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java
index d2d081a90..3aaa89529 100644
--- a/src/main/java/de/pixart/messenger/entities/Conversation.java
+++ b/src/main/java/de/pixart/messenger/entities/Conversation.java
@@ -36,15 +36,12 @@ import rocks.xmpp.addr.Jid;
import static de.pixart.messenger.entities.Bookmark.printableValue;
-public class Conversation extends AbstractEntity implements Blockable, Comparable<Conversation> {
+public class Conversation extends AbstractEntity implements Blockable, Comparable<Conversation>, Conversational {
public static final String TABLENAME = "conversations";
public static final int STATUS_AVAILABLE = 0;
public static final int STATUS_ARCHIVED = 1;
- public static final int MODE_MULTI = 1;
- public static final int MODE_SINGLE = 0;
-
public static final String NAME = "name";
public static final String ACCOUNT = "accountUuid";
public static final String CONTACT = "contactUuid";
diff --git a/src/main/java/de/pixart/messenger/entities/Conversational.java b/src/main/java/de/pixart/messenger/entities/Conversational.java
new file mode 100644
index 000000000..27482e195
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/entities/Conversational.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2018, Daniel Gultsch All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.pixart.messenger.entities;
+
+import rocks.xmpp.addr.Jid;
+
+public interface Conversational {
+
+ int MODE_MULTI = 1;
+ int MODE_SINGLE = 0;
+
+ Account getAccount();
+
+ Contact getContact();
+
+ Jid getJid();
+
+ int getMode();
+
+ String getUuid();
+} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/entities/IndividualMessage.java b/src/main/java/de/pixart/messenger/entities/IndividualMessage.java
new file mode 100644
index 000000000..7a1030fef
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/entities/IndividualMessage.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2018, Daniel Gultsch All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.pixart.messenger.entities;
+
+import android.database.Cursor;
+
+import java.util.Set;
+
+import rocks.xmpp.addr.Jid;
+
+public class IndividualMessage extends Message {
+
+
+ private IndividualMessage(Conversational conversation, String uuid, String conversationUUid, Jid counterpart, Jid trueCounterpart, String body, long timeSent, int encryption, int status, int type, boolean carbon, String remoteMsgId, String relativeFilePath, String serverMsgId, String fingerprint, boolean read, String edited, boolean oob, String errorMessage, Set<ReadByMarker> readByMarkers, boolean markable) {
+ super(conversation, uuid, conversationUUid, counterpart, trueCounterpart, body, timeSent, encryption, status, type, carbon, remoteMsgId, relativeFilePath, serverMsgId, fingerprint, read, edited, oob, errorMessage, readByMarkers, markable);
+ }
+
+ public static Message fromCursor(Cursor cursor, Conversational conversation) {
+ Jid jid;
+ try {
+ String value = cursor.getString(cursor.getColumnIndex(COUNTERPART));
+ if (value != null) {
+ jid = Jid.of(value);
+ } else {
+ jid = null;
+ }
+ } catch (IllegalArgumentException e) {
+ jid = null;
+ } catch (IllegalStateException e) {
+ return null; // message too long?
+ }
+ Jid trueCounterpart;
+ try {
+ String value = cursor.getString(cursor.getColumnIndex(TRUE_COUNTERPART));
+ if (value != null) {
+ trueCounterpart = Jid.of(value);
+ } else {
+ trueCounterpart = null;
+ }
+ } catch (IllegalArgumentException e) {
+ trueCounterpart = null;
+ }
+ return new IndividualMessage(conversation,
+ cursor.getString(cursor.getColumnIndex(UUID)),
+ cursor.getString(cursor.getColumnIndex(CONVERSATION)),
+ jid,
+ trueCounterpart,
+ cursor.getString(cursor.getColumnIndex(BODY)),
+ cursor.getLong(cursor.getColumnIndex(TIME_SENT)),
+ cursor.getInt(cursor.getColumnIndex(ENCRYPTION)),
+ cursor.getInt(cursor.getColumnIndex(STATUS)),
+ cursor.getInt(cursor.getColumnIndex(TYPE)),
+ cursor.getInt(cursor.getColumnIndex(CARBON)) > 0,
+ cursor.getString(cursor.getColumnIndex(REMOTE_MSG_ID)),
+ cursor.getString(cursor.getColumnIndex(RELATIVE_FILE_PATH)),
+ cursor.getString(cursor.getColumnIndex(SERVER_MSG_ID)),
+ cursor.getString(cursor.getColumnIndex(FINGERPRINT)),
+ cursor.getInt(cursor.getColumnIndex(READ)) > 0,
+ cursor.getString(cursor.getColumnIndex(EDITED)),
+ cursor.getInt(cursor.getColumnIndex(OOB)) > 0,
+ cursor.getString(cursor.getColumnIndex(ERROR_MESSAGE)),
+ ReadByMarker.fromJsonString(cursor.getString(cursor.getColumnIndex(READ_BY_MARKERS))),
+ cursor.getInt(cursor.getColumnIndex(MARKABLE)) > 0);
+ }
+
+ @Override
+ public Message next() {
+ return null;
+ }
+
+ @Override
+ public Message prev() {
+ return null;
+ }
+
+ @Override
+ public boolean isValidInSession() {
+ return true;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java
index 5df54861f..605fa0001 100644
--- a/src/main/java/de/pixart/messenger/entities/Message.java
+++ b/src/main/java/de/pixart/messenger/entities/Message.java
@@ -92,7 +92,7 @@ public class Message extends AbstractEntity {
protected boolean read = true;
protected String remoteMsgId = null;
protected String serverMsgId = null;
- private final Conversation conversation;
+ private final Conversational conversation;
protected Transferable transferable = null;
private Message mNextMessage = null;
private Message mPreviousMessage = null;
@@ -108,15 +108,15 @@ public class Message extends AbstractEntity {
private List<MucOptions.User> counterparts;
private WeakReference<MucOptions.User> user;
- private Message(Conversation conversation) {
+ private Message(Conversational conversation) {
this.conversation = conversation;
}
- public Message(Conversation conversation, String body, int encryption) {
+ public Message(Conversational conversation, String body, int encryption) {
this(conversation, body, encryption, STATUS_UNSEND);
}
- public Message(Conversation conversation, String body, int encryption, int status) {
+ public Message(Conversational conversation, String body, int encryption, int status) {
this(conversation, java.util.UUID.randomUUID().toString(),
conversation.getUuid(),
conversation.getJid() == null ? null : conversation.getJid().asBareJid(),
@@ -139,7 +139,7 @@ public class Message extends AbstractEntity {
false);
}
- private Message(final Conversation conversation, final String uuid, final String conversationUUid, final Jid counterpart,
+ protected Message(final Conversational conversation, final String uuid, final String conversationUUid, final Jid counterpart,
final Jid trueCounterpart, final String body, final long timeSent,
final int encryption, final int status, final int type, final boolean carbon,
final String remoteMsgId, final String relativeFilePath,
@@ -278,7 +278,7 @@ public class Message extends AbstractEntity {
return conversationUuid;
}
- public Conversation getConversation() {
+ public Conversational getConversation() {
return this.conversation;
}
@@ -514,30 +514,40 @@ public class Message extends AbstractEntity {
}
public Message next() {
- synchronized (this.conversation.messages) {
- if (this.mNextMessage == null) {
- int index = this.conversation.messages.indexOf(this);
- if (index < 0 || index >= this.conversation.messages.size() - 1) {
- this.mNextMessage = null;
- } else {
- this.mNextMessage = this.conversation.messages.get(index + 1);
+ if (this.conversation instanceof Conversation) {
+ final Conversation conversation = (Conversation) this.conversation;
+ synchronized (conversation.messages) {
+ if (this.mNextMessage == null) {
+ int index = conversation.messages.indexOf(this);
+ if (index < 0 || index >= conversation.messages.size() - 1) {
+ this.mNextMessage = null;
+ } else {
+ this.mNextMessage = conversation.messages.get(index + 1);
+ }
}
+ return this.mNextMessage;
}
- return this.mNextMessage;
+ } else {
+ throw new AssertionError("Calling next should be disabled for stubs");
}
}
public Message prev() {
- synchronized (this.conversation.messages) {
- if (this.mPreviousMessage == null) {
- int index = this.conversation.messages.indexOf(this);
- if (index <= 0 || index > this.conversation.messages.size()) {
- this.mPreviousMessage = null;
- } else {
- this.mPreviousMessage = this.conversation.messages.get(index - 1);
+ if (this.conversation instanceof Conversation) {
+ final Conversation conversation = (Conversation) this.conversation;
+ synchronized (conversation.messages) {
+ if (this.mPreviousMessage == null) {
+ int index = conversation.messages.indexOf(this);
+ if (index <= 0 || index > conversation.messages.size()) {
+ this.mPreviousMessage = null;
+ } else {
+ this.mPreviousMessage = conversation.messages.get(index - 1);
+ }
}
}
return this.mPreviousMessage;
+ } else {
+ throw new AssertionError("Calling prev should be disabled for stubs");
}
}
@@ -893,13 +903,18 @@ public class Message extends AbstractEntity {
}
private int getNextEncryption() {
- for (Message iterator = this.next(); iterator != null; iterator = iterator.next()) {
- if (iterator.isCarbon() || iterator.getStatus() == STATUS_RECEIVED) {
- continue;
+ if (this.conversation instanceof Conversation) {
+ Conversation conversation = (Conversation) this.conversation;
+ for (Message iterator = this.next(); iterator != null; iterator = iterator.next()) {
+ if (iterator.isCarbon() || iterator.getStatus() == STATUS_RECEIVED) {
+ continue;
+ }
+ return iterator.getEncryption();
}
- return iterator.getEncryption();
+ return conversation.getNextEncryption();
+ } else {
+ throw new AssertionError("This should never be called since isInValidSession should be disabled for stubs");
}
- return conversation.getNextEncryption();
}
public boolean isValidInSession() {
diff --git a/src/main/java/de/pixart/messenger/entities/StubConversation.java b/src/main/java/de/pixart/messenger/entities/StubConversation.java
new file mode 100644
index 000000000..75f17812e
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/entities/StubConversation.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2018, Daniel Gultsch All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package de.pixart.messenger.entities;
+
+import rocks.xmpp.addr.Jid;
+
+
+public class StubConversation implements Conversational {
+
+ private final Account account;
+ private final String uuid;
+ private final Jid jid;
+ private final int mode;
+
+ public StubConversation(Account account, String uuid, Jid jid, int mode) {
+ this.account = account;
+ this.uuid = uuid;
+ this.jid = jid;
+ this.mode = mode;
+ }
+
+ @Override
+ public Account getAccount() {
+ return account;
+ }
+
+ @Override
+ public Contact getContact() {
+ return account.getRoster().getContact(jid);
+ }
+
+ @Override
+ public Jid getJid() {
+ return jid;
+ }
+
+ @Override
+ public int getMode() {
+ return mode;
+ }
+
+ @Override
+ public String getUuid() {
+ return uuid;
+ }
+} \ No newline at end of file