very much unoptimized search functionality
This commit is contained in:
parent
4bbbf86f76
commit
35020702fb
|
@ -48,7 +48,7 @@ public class PgpEngine {
|
|||
public void encrypt(final Message message, final UiCallback<Message> callback) {
|
||||
Intent params = new Intent();
|
||||
params.setAction(OpenPgpApi.ACTION_ENCRYPT);
|
||||
final Conversation conversation = message.getConversation();
|
||||
final Conversation conversation = (Conversation) message.getConversation();
|
||||
if (conversation.getMode() == Conversation.MODE_SINGLE) {
|
||||
long[] keys = {
|
||||
conversation.getContact().getPgpKeyId(),
|
||||
|
|
|
@ -1307,7 +1307,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
|
|||
if (message.getType() == Message.TYPE_PRIVATE) {
|
||||
success = buildHeader(axolotlMessage, message.getTrueCounterpart());
|
||||
} else {
|
||||
success = buildHeader(axolotlMessage, message.getConversation());
|
||||
success = buildHeader(axolotlMessage, (Conversation) message.getConversation());
|
||||
}
|
||||
return success ? axolotlMessage : null;
|
||||
}
|
||||
|
|
|
@ -30,15 +30,12 @@ import rocks.xmpp.addr.Jid;
|
|||
import static eu.siacs.conversations.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";
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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 eu.siacs.conversations.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();
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* 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 eu.siacs.conversations.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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message next() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message prev() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidInSession() {
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -90,7 +90,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;
|
||||
|
@ -105,15 +105,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(),
|
||||
|
@ -136,7 +136,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,
|
||||
|
@ -275,7 +275,7 @@ public class Message extends AbstractEntity {
|
|||
return conversationUuid;
|
||||
}
|
||||
|
||||
public Conversation getConversation() {
|
||||
public Conversational getConversation() {
|
||||
return this.conversation;
|
||||
}
|
||||
|
||||
|
@ -508,30 +508,40 @@ public class Message extends AbstractEntity {
|
|||
}
|
||||
|
||||
public Message next() {
|
||||
synchronized (this.conversation.messages) {
|
||||
if (this.conversation instanceof Conversation) {
|
||||
final Conversation conversation = (Conversation) this.conversation;
|
||||
synchronized (conversation.messages) {
|
||||
if (this.mNextMessage == null) {
|
||||
int index = this.conversation.messages.indexOf(this);
|
||||
if (index < 0 || index >= this.conversation.messages.size() - 1) {
|
||||
int index = conversation.messages.indexOf(this);
|
||||
if (index < 0 || index >= conversation.messages.size() - 1) {
|
||||
this.mNextMessage = null;
|
||||
} else {
|
||||
this.mNextMessage = this.conversation.messages.get(index + 1);
|
||||
this.mNextMessage = conversation.messages.get(index + 1);
|
||||
}
|
||||
}
|
||||
return this.mNextMessage;
|
||||
}
|
||||
} else {
|
||||
throw new AssertionError("Calling next should be disabled for stubs");
|
||||
}
|
||||
}
|
||||
|
||||
public Message prev() {
|
||||
synchronized (this.conversation.messages) {
|
||||
if (this.conversation instanceof Conversation) {
|
||||
final Conversation conversation = (Conversation) this.conversation;
|
||||
synchronized (conversation.messages) {
|
||||
if (this.mPreviousMessage == null) {
|
||||
int index = this.conversation.messages.indexOf(this);
|
||||
if (index <= 0 || index > this.conversation.messages.size()) {
|
||||
int index = conversation.messages.indexOf(this);
|
||||
if (index <= 0 || index > conversation.messages.size()) {
|
||||
this.mPreviousMessage = null;
|
||||
} else {
|
||||
this.mPreviousMessage = this.conversation.messages.get(index - 1);
|
||||
this.mPreviousMessage = conversation.messages.get(index - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.mPreviousMessage;
|
||||
} else {
|
||||
throw new AssertionError("Calling prev should be disabled for stubs");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -599,7 +609,8 @@ public class Message extends AbstractEntity {
|
|||
return this.counterparts;
|
||||
}
|
||||
|
||||
public static class MergeSeparator {}
|
||||
public static class MergeSeparator {
|
||||
}
|
||||
|
||||
public SpannableStringBuilder getMergedBody() {
|
||||
SpannableStringBuilder body = new SpannableStringBuilder(this.body.trim());
|
||||
|
@ -858,6 +869,8 @@ public class Message extends AbstractEntity {
|
|||
}
|
||||
|
||||
private int getNextEncryption() {
|
||||
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;
|
||||
|
@ -865,6 +878,9 @@ public class Message extends AbstractEntity {
|
|||
return iterator.getEncryption();
|
||||
}
|
||||
return conversation.getNextEncryption();
|
||||
} else {
|
||||
throw new AssertionError("This should never be called since isInValidSession should be disabled for stubs");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValidInSession() {
|
||||
|
|
|
@ -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 eu.siacs.conversations.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;
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ public class MessageGenerator extends AbstractGenerator {
|
|||
}
|
||||
|
||||
private MessagePacket preparePacket(Message message) {
|
||||
Conversation conversation = message.getConversation();
|
||||
Conversation conversation = (Conversation) message.getConversation();
|
||||
Account account = conversation.getAccount();
|
||||
MessagePacket packet = new MessagePacket();
|
||||
final boolean isWithSelf = conversation.getContact().isSelf();
|
||||
|
|
|
@ -674,8 +674,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
return getMessages(conversations, limit, -1);
|
||||
}
|
||||
|
||||
public ArrayList<Message> getMessages(Conversation conversation, int limit,
|
||||
long timestamp) {
|
||||
public ArrayList<Message> getMessages(Conversation conversation, int limit, long timestamp) {
|
||||
ArrayList<Message> list = new ArrayList<>();
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
Cursor cursor;
|
||||
|
@ -705,18 +704,22 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
return list;
|
||||
}
|
||||
|
||||
public Cursor getMessageSearchCursor(String term) {
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
String SQL = "SELECT "+Message.TABLENAME+".*,"+Conversation.TABLENAME+'.'+Conversation.CONTACTJID+','+Conversation.TABLENAME+'.'+Conversation.ACCOUNT+','+Conversation.TABLENAME+'.'+Conversation.MODE+" FROM "+Message.TABLENAME +" join "+Conversation.TABLENAME+" on "+Message.TABLENAME+'.'+Message.CONVERSATION+'='+Conversation.TABLENAME+'.'+Conversation.UUID+" where "+Message.BODY +" LIKE ? limit 200";
|
||||
return db.rawQuery(SQL,new String[]{'%'+term+'%'});
|
||||
}
|
||||
|
||||
public Iterable<Message> getMessagesIterable(final Conversation conversation) {
|
||||
return new Iterable<Message>() {
|
||||
@Override
|
||||
public Iterator<Message> iterator() {
|
||||
return () -> {
|
||||
class MessageIterator implements Iterator<Message> {
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
String[] selectionArgs = {conversation.getUuid()};
|
||||
Cursor cursor = db.query(Message.TABLENAME, null, Message.CONVERSATION
|
||||
private SQLiteDatabase db = getReadableDatabase();
|
||||
private String[] selectionArgs = {conversation.getUuid()};
|
||||
private Cursor cursor = db.query(Message.TABLENAME, null, Message.CONVERSATION
|
||||
+ "=?", selectionArgs, null, null, Message.TIME_SENT
|
||||
+ " ASC", null);
|
||||
|
||||
public MessageIterator() {
|
||||
private MessageIterator() {
|
||||
cursor.moveToFirst();
|
||||
}
|
||||
|
||||
|
@ -738,7 +741,6 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
}
|
||||
}
|
||||
return new MessageIterator();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import eu.siacs.conversations.entities.Account;
|
|||
import eu.siacs.conversations.entities.Bookmark;
|
||||
import eu.siacs.conversations.entities.Contact;
|
||||
import eu.siacs.conversations.entities.Conversation;
|
||||
import eu.siacs.conversations.entities.Conversational;
|
||||
import eu.siacs.conversations.entities.ListItem;
|
||||
import eu.siacs.conversations.entities.Message;
|
||||
import eu.siacs.conversations.entities.MucOptions;
|
||||
|
@ -388,20 +389,21 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
|||
}
|
||||
|
||||
public Bitmap get(Message message, int size, boolean cachedOnly) {
|
||||
final Conversation conversation = message.getConversation();
|
||||
final Conversational conversation = message.getConversation();
|
||||
if (message.getType() == Message.TYPE_STATUS && message.getCounterparts() != null && message.getCounterparts().size() > 1) {
|
||||
return get(message.getCounterparts(), size, cachedOnly);
|
||||
} else if (message.getStatus() == Message.STATUS_RECEIVED) {
|
||||
Contact c = message.getContact();
|
||||
if (c != null && (c.getProfilePhoto() != null || c.getAvatar() != null)) {
|
||||
return get(c, size, cachedOnly);
|
||||
} else if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
||||
} else if (conversation instanceof Conversation && message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
||||
final Jid trueCounterpart = message.getTrueCounterpart();
|
||||
final MucOptions mucOptions = ((Conversation) conversation).getMucOptions();
|
||||
MucOptions.User user;
|
||||
if (trueCounterpart != null) {
|
||||
user = conversation.getMucOptions().findUserByRealJid(trueCounterpart);
|
||||
user = mucOptions.findUserByRealJid(trueCounterpart);
|
||||
} else {
|
||||
user = conversation.getMucOptions().findUserByFullJid(message.getCounterpart());
|
||||
user = mucOptions.findUserByFullJid(message.getCounterpart());
|
||||
}
|
||||
if (user != null) {
|
||||
return getImpl(user, size, cachedOnly);
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* 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 eu.siacs.conversations.services;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.entities.Account;
|
||||
import eu.siacs.conversations.entities.Conversation;
|
||||
import eu.siacs.conversations.entities.Conversational;
|
||||
import eu.siacs.conversations.entities.IndividualMessage;
|
||||
import eu.siacs.conversations.entities.Message;
|
||||
import eu.siacs.conversations.entities.StubConversation;
|
||||
import eu.siacs.conversations.ui.interfaces.OnSearchResultsAvailable;
|
||||
import eu.siacs.conversations.utils.Cancellable;
|
||||
import eu.siacs.conversations.utils.ReplacingSerialSingleThreadExecutor;
|
||||
import rocks.xmpp.addr.Jid;
|
||||
|
||||
public class MessageSearchTask implements Runnable, Cancellable {
|
||||
|
||||
private static final ReplacingSerialSingleThreadExecutor EXECUTOR = new ReplacingSerialSingleThreadExecutor(MessageSearchTask.class.getName());
|
||||
|
||||
private final XmppConnectionService xmppConnectionService;
|
||||
private final String term;
|
||||
private final OnSearchResultsAvailable onSearchResultsAvailable;
|
||||
|
||||
private boolean isCancelled = false;
|
||||
|
||||
private MessageSearchTask(XmppConnectionService xmppConnectionService, String term, OnSearchResultsAvailable onSearchResultsAvailable) {
|
||||
this.xmppConnectionService = xmppConnectionService;
|
||||
this.term = term;
|
||||
this.onSearchResultsAvailable = onSearchResultsAvailable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
this.isCancelled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long startTimestamp = SystemClock.elapsedRealtime();
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
final HashMap<String,Conversational> conversationCache = new HashMap<>();
|
||||
final List<Message> result = new ArrayList<>();
|
||||
cursor = xmppConnectionService.databaseBackend.getMessageSearchCursor(term);
|
||||
while(cursor.moveToNext()) {
|
||||
final String conversationUuid = cursor.getString(cursor.getColumnIndex(Message.CONVERSATION));
|
||||
Conversational conversation;
|
||||
if (conversationCache.containsKey(conversationUuid)) {
|
||||
conversation = conversationCache.get(conversationUuid);
|
||||
} else {
|
||||
String accountUuid = cursor.getString(cursor.getColumnIndex(Conversation.ACCOUNT));
|
||||
String contactJid = cursor.getString(cursor.getColumnIndex(Conversation.CONTACTJID));
|
||||
int mode = cursor.getInt(cursor.getColumnIndex(Conversation.MODE));
|
||||
conversation = findOrGenerateStub(conversationUuid, accountUuid, contactJid, mode);
|
||||
conversationCache.put(conversationUuid, conversation);
|
||||
}
|
||||
Message message = IndividualMessage.fromCursor(cursor, conversation);
|
||||
result.add(message);
|
||||
}
|
||||
long stopTimestamp = SystemClock.elapsedRealtime();
|
||||
Log.d(Config.LOGTAG,"found "+result.size()+" messages in "+(stopTimestamp - startTimestamp)+"ms");
|
||||
onSearchResultsAvailable.onSearchResultsAvailable(term, result);
|
||||
} catch (Exception e) {
|
||||
Log.d(Config.LOGTAG,"exception while searching ",e);
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Conversational findOrGenerateStub(String conversationUuid, String accountUuid, String contactJid, int mode) throws Exception {
|
||||
Conversation conversation = xmppConnectionService.findConversationByUuid(conversationUuid);
|
||||
if (conversation != null) {
|
||||
return conversation;
|
||||
}
|
||||
Account account = xmppConnectionService.findAccountByUuid(accountUuid);
|
||||
Jid jid = Jid.of(contactJid);
|
||||
if (account != null && jid != null) {
|
||||
return new StubConversation(account, conversationUuid, jid.asBareJid(), mode);
|
||||
}
|
||||
throw new Exception("Unable to generate stub for "+contactJid);
|
||||
}
|
||||
|
||||
private void executeInBackground() {
|
||||
EXECUTOR.execute(this);
|
||||
}
|
||||
|
||||
public static void search(XmppConnectionService xmppConnectionService, String term, OnSearchResultsAvailable onSearchResultsAvailable) {
|
||||
new MessageSearchTask(xmppConnectionService, term, onSearchResultsAvailable).executeInBackground();
|
||||
}
|
||||
}
|
|
@ -42,6 +42,7 @@ import eu.siacs.conversations.R;
|
|||
import eu.siacs.conversations.entities.Account;
|
||||
import eu.siacs.conversations.entities.Contact;
|
||||
import eu.siacs.conversations.entities.Conversation;
|
||||
import eu.siacs.conversations.entities.Conversational;
|
||||
import eu.siacs.conversations.entities.Message;
|
||||
import eu.siacs.conversations.persistance.FileBackend;
|
||||
import eu.siacs.conversations.ui.ConversationsActivity;
|
||||
|
@ -77,11 +78,12 @@ public class NotificationService {
|
|||
}
|
||||
|
||||
public boolean notify(final Message message) {
|
||||
final Conversation conversation = (Conversation) message.getConversation();
|
||||
return message.getStatus() == Message.STATUS_RECEIVED
|
||||
&& notificationsEnabled()
|
||||
&& !message.getConversation().isMuted()
|
||||
&& (message.getConversation().alwaysNotify() || wasHighlightedOrPrivate(message))
|
||||
&& (!message.getConversation().isWithStranger() || notificationsFromStrangers())
|
||||
&& !conversation.isMuted()
|
||||
&& (conversation.alwaysNotify() || wasHighlightedOrPrivate(message))
|
||||
&& (!conversation.isWithStranger() || notificationsFromStrangers())
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -112,7 +114,7 @@ public class NotificationService {
|
|||
public void pushFromBacklog(final Message message) {
|
||||
if (notify(message)) {
|
||||
synchronized (notifications) {
|
||||
getBacklogMessageCounter(message.getConversation()).incrementAndGet();
|
||||
getBacklogMessageCounter((Conversation) message.getConversation()).incrementAndGet();
|
||||
pushToStack(message);
|
||||
}
|
||||
}
|
||||
|
@ -239,7 +241,7 @@ public class NotificationService {
|
|||
if (messages != null && messages.size() > 0) {
|
||||
Message last = messages.get(messages.size() - 1);
|
||||
if (last.getStatus() != Message.STATUS_RECEIVED) {
|
||||
if (mXmppConnectionService.markRead(last.getConversation(), false)) {
|
||||
if (mXmppConnectionService.markRead((Conversation) last.getConversation(), false)) {
|
||||
mXmppConnectionService.updateConversationUi();
|
||||
}
|
||||
}
|
||||
|
@ -337,7 +339,7 @@ public class NotificationService {
|
|||
Conversation conversation = null;
|
||||
for (final ArrayList<Message> messages : notifications.values()) {
|
||||
if (messages.size() > 0) {
|
||||
conversation = messages.get(0).getConversation();
|
||||
conversation = (Conversation) messages.get(0).getConversation();
|
||||
final String name = conversation.getName().toString();
|
||||
SpannableString styledString;
|
||||
if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
|
||||
|
@ -376,7 +378,7 @@ public class NotificationService {
|
|||
private Builder buildSingleConversations(final ArrayList<Message> messages) {
|
||||
final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
|
||||
if (messages.size() >= 1) {
|
||||
final Conversation conversation = messages.get(0).getConversation();
|
||||
final Conversation conversation = (Conversation) messages.get(0).getConversation();
|
||||
final UnreadConversation.Builder mUnreadBuilder = new UnreadConversation.Builder(conversation.getName().toString());
|
||||
mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService()
|
||||
.get(conversation, getPixel(64)));
|
||||
|
@ -510,7 +512,7 @@ public class NotificationService {
|
|||
private void modifyForTextOnly(final Builder builder, final UnreadConversation.Builder uBuilder, final ArrayList<Message> messages) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
NotificationCompat.MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle(mXmppConnectionService.getString(R.string.me));
|
||||
Conversation conversation = messages.get(0).getConversation();
|
||||
final Conversation conversation = (Conversation) messages.get(0).getConversation();
|
||||
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
||||
messagingStyle.setConversationTitle(conversation.getName());
|
||||
}
|
||||
|
@ -632,7 +634,7 @@ public class NotificationService {
|
|||
return (actionId * NOTIFICATION_ID_MULTIPLIER) + (uuid.hashCode() % NOTIFICATION_ID_MULTIPLIER);
|
||||
}
|
||||
|
||||
private int generateRequestCode(Conversation conversation, int actionId) {
|
||||
private int generateRequestCode(Conversational conversation, int actionId) {
|
||||
return generateRequestCode(conversation.getUuid(), actionId);
|
||||
}
|
||||
|
||||
|
@ -640,7 +642,7 @@ public class NotificationService {
|
|||
return createContentIntent(message.getConversationUuid(), message.getUuid());
|
||||
}
|
||||
|
||||
private PendingIntent createContentIntent(final Conversation conversation) {
|
||||
private PendingIntent createContentIntent(final Conversational conversation) {
|
||||
return createContentIntent(conversation.getUuid(), null);
|
||||
}
|
||||
|
||||
|
@ -692,13 +694,18 @@ public class NotificationService {
|
|||
}
|
||||
|
||||
private boolean wasHighlightedOrPrivate(final Message message) {
|
||||
final String nick = message.getConversation().getMucOptions().getActualNick();
|
||||
if (message.getConversation() instanceof Conversation) {
|
||||
Conversation conversation = (Conversation) message.getConversation();
|
||||
final String nick = conversation.getMucOptions().getActualNick();
|
||||
final Pattern highlight = generateNickHighlightPattern(nick);
|
||||
if (message.getBody() == null || nick == null) {
|
||||
return false;
|
||||
}
|
||||
final Matcher m = highlight.matcher(message.getBody());
|
||||
return (m.find() || message.getType() == Message.TYPE_PRIVATE);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Pattern generateNickHighlightPattern(final String nick) {
|
||||
|
|
|
@ -98,6 +98,7 @@ import eu.siacs.conversations.persistance.DatabaseBackend;
|
|||
import eu.siacs.conversations.persistance.FileBackend;
|
||||
import eu.siacs.conversations.ui.SettingsActivity;
|
||||
import eu.siacs.conversations.ui.UiCallback;
|
||||
import eu.siacs.conversations.ui.interfaces.OnSearchResultsAvailable;
|
||||
import eu.siacs.conversations.utils.ConversationsFileObserver;
|
||||
import eu.siacs.conversations.utils.CryptoHelper;
|
||||
import eu.siacs.conversations.utils.ExceptionHelper;
|
||||
|
@ -534,6 +535,10 @@ public class XmppConnectionService extends Service {
|
|||
return find(getConversations(), account, jid);
|
||||
}
|
||||
|
||||
public void search(String term, OnSearchResultsAvailable onSearchResultsAvailable) {
|
||||
MessageSearchTask.search(this, term, onSearchResultsAvailable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
final String action = intent == null ? null : intent.getAction();
|
||||
|
@ -781,7 +786,7 @@ public class XmppConnectionService extends Service {
|
|||
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
|
||||
sendMessage(message);
|
||||
if (dismissAfterReply) {
|
||||
markRead(message.getConversation(), true);
|
||||
markRead((Conversation) message.getConversation(), true);
|
||||
} else {
|
||||
mNotificationService.pushFromDirectReply(message);
|
||||
}
|
||||
|
@ -1142,7 +1147,7 @@ public class XmppConnectionService extends Service {
|
|||
databaseBackend.updateAccount(account);
|
||||
mNotificationService.updateErrorNotification();
|
||||
}
|
||||
final Conversation conversation = message.getConversation();
|
||||
final Conversation conversation = (Conversation) message.getConversation();
|
||||
account.deactivateGracePeriod();
|
||||
MessagePacket packet = null;
|
||||
final boolean addToConversation = (conversation.getMode() != Conversation.MODE_MULTI
|
||||
|
@ -3242,6 +3247,15 @@ public class XmppConnectionService extends Service {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Account findAccountByUuid(final String uuid) {
|
||||
for(Account account : this.accounts) {
|
||||
if (account.getUuid().equals(uuid)) {
|
||||
return account;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Conversation findConversationByUuid(String uuid) {
|
||||
for (Conversation conversation : getConversations()) {
|
||||
if (conversation.getUuid().equals(uuid)) {
|
||||
|
@ -3528,7 +3542,9 @@ public class XmppConnectionService extends Service {
|
|||
markMessage(msg, Message.STATUS_WAITING);
|
||||
this.resendMessage(msg, false);
|
||||
}
|
||||
message.getConversation().sort();
|
||||
if (message.getConversation() instanceof Conversation) {
|
||||
((Conversation) message.getConversation()).sort();
|
||||
}
|
||||
updateConversationUi();
|
||||
}
|
||||
|
||||
|
|
|
@ -705,7 +705,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
|||
message.setEdited(message.getUuid());
|
||||
message.setUuid(UUID.randomUUID().toString());
|
||||
}
|
||||
switch (message.getConversation().getNextEncryption()) {
|
||||
switch (conversation.getNextEncryption()) {
|
||||
case Message.ENCRYPTION_PGP:
|
||||
sendPgpMessage(message);
|
||||
break;
|
||||
|
@ -932,11 +932,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
|||
messageListAdapter.setOnContactPictureClicked(message -> {
|
||||
final boolean received = message.getStatus() <= Message.STATUS_RECEIVED;
|
||||
if (received) {
|
||||
if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
||||
if (message.getConversation() instanceof Conversation && message.getConversation().getMode() == Conversation.MODE_MULTI) {
|
||||
Jid user = message.getCounterpart();
|
||||
if (user != null && !user.isBareJid()) {
|
||||
final MucOptions mucOptions = message.getConversation().getMucOptions();
|
||||
if (mucOptions.participating() || message.getConversation().getNextCounterpart() != null) {
|
||||
final MucOptions mucOptions = ((Conversation) message.getConversation()).getMucOptions();
|
||||
if (mucOptions.participating() || ((Conversation) message.getConversation()).getNextCounterpart() != null) {
|
||||
if (!mucOptions.isUserInRoom(user)) {
|
||||
Toast.makeText(getActivity(), activity.getString(R.string.user_has_left_conference, user.getResource()), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
@ -1079,7 +1079,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
|||
}
|
||||
if (relevantForCorrection.getType() == Message.TYPE_TEXT
|
||||
&& relevantForCorrection.isLastCorrectableMessage()
|
||||
&& (m.getConversation().getMucOptions().nonanonymous() || m.getConversation().getMode() == Conversation.MODE_SINGLE)) {
|
||||
&& m.getConversation() instanceof Conversation
|
||||
&& (((Conversation) m.getConversation()).getMucOptions().nonanonymous() || m.getConversation().getMode() == Conversation.MODE_SINGLE)) {
|
||||
correctMessage.setVisible(true);
|
||||
}
|
||||
if ((m.isFileOrImage() && !deleted && !receiving) || (m.getType() == Message.TYPE_TEXT && !m.treatAsDownloadable())) {
|
||||
|
@ -1628,9 +1629,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
|
|||
|
||||
private void resendMessage(final Message message) {
|
||||
if (message.isFileOrImage()) {
|
||||
if (!(message.getConversation() instanceof Conversation)) {
|
||||
return;
|
||||
}
|
||||
final Conversation conversation = (Conversation) message.getConversation();
|
||||
DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
|
||||
if (file.exists()) {
|
||||
final Conversation conversation = message.getConversation();
|
||||
final XmppConnection xmppConnection = conversation.getAccount().getXmppConnection();
|
||||
if (!message.hasFileOnRemoteHost()
|
||||
&& xmppConnection != null
|
||||
|
|
|
@ -47,13 +47,14 @@ import eu.siacs.conversations.R;
|
|||
import eu.siacs.conversations.databinding.ActivitySearchBinding;
|
||||
import eu.siacs.conversations.entities.Message;
|
||||
import eu.siacs.conversations.ui.adapter.MessageAdapter;
|
||||
import eu.siacs.conversations.ui.interfaces.OnSearchResultsAvailable;
|
||||
import eu.siacs.conversations.ui.util.Color;
|
||||
import eu.siacs.conversations.ui.util.Drawable;
|
||||
|
||||
import static eu.siacs.conversations.ui.util.SoftKeyboardUtils.hideSoftKeyboard;
|
||||
import static eu.siacs.conversations.ui.util.SoftKeyboardUtils.showKeyboard;
|
||||
|
||||
public class SearchActivity extends XmppActivity implements TextWatcher {
|
||||
public class SearchActivity extends XmppActivity implements TextWatcher, OnSearchResultsAvailable {
|
||||
|
||||
private ActivitySearchBinding binding;
|
||||
private MessageAdapter messageListAdapter;
|
||||
|
@ -122,7 +123,23 @@ public class SearchActivity extends XmppActivity implements TextWatcher {
|
|||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
Log.d(Config.LOGTAG,"searching for "+s);
|
||||
String term = s.toString().trim();
|
||||
if (term.length() > 0) {
|
||||
xmppConnectionService.search(s.toString().trim(), this);
|
||||
} else {
|
||||
this.messages.clear();
|
||||
messageListAdapter.notifyDataSetChanged();
|
||||
changeBackground(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchResultsAvailable(String term, List<Message> messages) {
|
||||
this.messages.clear();
|
||||
this.messages.addAll(messages);
|
||||
runOnUiThread(() -> {
|
||||
messageListAdapter.notifyDataSetChanged();
|
||||
changeBackground(true, messages.size() > 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,11 +87,12 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
|
|||
} else {
|
||||
resId = R.string.shared_file_with_x;
|
||||
}
|
||||
replaceToast(getString(resId, message.getConversation().getName()));
|
||||
Conversation conversation = (Conversation) message.getConversation();
|
||||
replaceToast(getString(resId, conversation.getName()));
|
||||
if (mReturnToPrevious) {
|
||||
finish();
|
||||
} else {
|
||||
switchToConversation(message.getConversation());
|
||||
switchToConversation(conversation);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -58,6 +58,7 @@ import eu.siacs.conversations.R;
|
|||
import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
|
||||
import eu.siacs.conversations.entities.Account;
|
||||
import eu.siacs.conversations.entities.Conversation;
|
||||
import eu.siacs.conversations.entities.Conversational;
|
||||
import eu.siacs.conversations.entities.DownloadableFile;
|
||||
import eu.siacs.conversations.entities.Message;
|
||||
import eu.siacs.conversations.entities.Message.FileParams;
|
||||
|
@ -530,12 +531,15 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
|
|||
}
|
||||
}
|
||||
if (message.getConversation().getMode() == Conversation.MODE_MULTI && message.getStatus() == Message.STATUS_RECEIVED) {
|
||||
Pattern pattern = NotificationService.generateNickHighlightPattern(message.getConversation().getMucOptions().getActualNick());
|
||||
if (message.getConversation() instanceof Conversation) {
|
||||
final Conversation conversation = (Conversation) message.getConversation();
|
||||
Pattern pattern = NotificationService.generateNickHighlightPattern(conversation.getMucOptions().getActualNick());
|
||||
Matcher matcher = pattern.matcher(body);
|
||||
while (matcher.find()) {
|
||||
body.setSpan(new StyleSpan(Typeface.BOLD), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
Matcher matcher = Emoticons.generatePattern(body).matcher(body);
|
||||
while (matcher.find()) {
|
||||
if (matcher.start() < matcher.end()) {
|
||||
|
@ -649,7 +653,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
|
|||
final Message message = getItem(position);
|
||||
final boolean omemoEncryption = message.getEncryption() == Message.ENCRYPTION_AXOLOTL;
|
||||
final boolean isInValidSession = message.isValidInSession() && (!omemoEncryption || message.isTrusted());
|
||||
final Conversation conversation = message.getConversation();
|
||||
final Conversational conversation = message.getConversation();
|
||||
final Account account = conversation.getAccount();
|
||||
final int type = getItemViewType(position);
|
||||
ViewHolder viewHolder;
|
||||
|
@ -727,7 +731,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
|
|||
viewHolder.status_message.setVisibility(View.GONE);
|
||||
viewHolder.contact_picture.setVisibility(View.GONE);
|
||||
viewHolder.load_more_messages.setVisibility(View.VISIBLE);
|
||||
viewHolder.load_more_messages.setOnClickListener(v -> loadMoreMessages(message.getConversation()));
|
||||
viewHolder.load_more_messages.setOnClickListener(v -> loadMoreMessages((Conversation) message.getConversation()));
|
||||
} else {
|
||||
viewHolder.status_message.setVisibility(View.VISIBLE);
|
||||
viewHolder.load_more_messages.setVisibility(View.GONE);
|
||||
|
@ -794,7 +798,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
|
|||
}
|
||||
} else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
|
||||
if (account.isPgpDecryptionServiceConnected()) {
|
||||
if (!account.hasPendingPgpIntent(conversation)) {
|
||||
if (conversation instanceof Conversation && !account.hasPendingPgpIntent((Conversation) conversation)) {
|
||||
displayInfoMessage(viewHolder, activity.getString(R.string.message_decrypting), darkBackground);
|
||||
} else {
|
||||
displayInfoMessage(viewHolder, activity.getString(R.string.pgp_message), darkBackground);
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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 eu.siacs.conversations.ui.interfaces;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import eu.siacs.conversations.entities.Message;
|
||||
|
||||
public interface OnSearchResultsAvailable {
|
||||
|
||||
void onSearchResultsAvailable(String term, List<Message> messages);
|
||||
|
||||
}
|
34
src/main/java/eu/siacs/conversations/utils/Cancellable.java
Normal file
34
src/main/java/eu/siacs/conversations/utils/Cancellable.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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 eu.siacs.conversations.utils;
|
||||
|
||||
public interface Cancellable {
|
||||
void cancel();
|
||||
}
|
|
@ -11,6 +11,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
import eu.siacs.conversations.entities.Contact;
|
||||
import eu.siacs.conversations.entities.Conversation;
|
||||
import eu.siacs.conversations.entities.Conversational;
|
||||
import eu.siacs.conversations.entities.Message;
|
||||
|
||||
public class GeoHelper {
|
||||
|
@ -38,11 +39,11 @@ public class GeoHelper {
|
|||
} catch (NumberFormatException nfe) {
|
||||
return intents;
|
||||
}
|
||||
final Conversation conversation = message.getConversation();
|
||||
final Conversational conversation = message.getConversation();
|
||||
String label;
|
||||
if (conversation.getMode() == Conversation.MODE_SINGLE && message.getStatus() == Message.STATUS_RECEIVED) {
|
||||
if (conversation instanceof Conversation && conversation.getMode() == Conversation.MODE_SINGLE && message.getStatus() == Message.STATUS_RECEIVED) {
|
||||
try {
|
||||
label = "(" + URLEncoder.encode(message.getConversation().getName().toString(), "UTF-8") + ")";
|
||||
label = "(" + URLEncoder.encode(((Conversation)conversation).getName().toString(), "UTF-8") + ")";
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
label = "";
|
||||
}
|
||||
|
|
|
@ -2,6 +2,10 @@ package eu.siacs.conversations.utils;
|
|||
|
||||
public class ReplacingSerialSingleThreadExecutor extends SerialSingleThreadExecutor {
|
||||
|
||||
public ReplacingSerialSingleThreadExecutor(String name) {
|
||||
super(name, false);
|
||||
}
|
||||
|
||||
public ReplacingSerialSingleThreadExecutor(boolean prepareLooper) {
|
||||
super(ReplacingSerialSingleThreadExecutor.class.getName(), prepareLooper);
|
||||
}
|
||||
|
@ -9,6 +13,9 @@ public class ReplacingSerialSingleThreadExecutor extends SerialSingleThreadExecu
|
|||
@Override
|
||||
public synchronized void execute(final Runnable r) {
|
||||
tasks.clear();
|
||||
if (active != null && active instanceof Cancellable) {
|
||||
((Cancellable) active).cancel();
|
||||
}
|
||||
super.execute(r);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ public class SerialSingleThreadExecutor implements Executor {
|
|||
|
||||
private final Executor executor = Executors.newSingleThreadExecutor();
|
||||
final ArrayDeque<Runnable> tasks = new ArrayDeque<>();
|
||||
private Runnable active;
|
||||
protected Runnable active;
|
||||
private final String name;
|
||||
|
||||
public SerialSingleThreadExecutor(String name) {
|
||||
|
|
|
@ -21,6 +21,7 @@ import eu.siacs.conversations.R;
|
|||
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
||||
import eu.siacs.conversations.entities.Contact;
|
||||
import eu.siacs.conversations.entities.Conversation;
|
||||
import eu.siacs.conversations.entities.Conversational;
|
||||
import eu.siacs.conversations.entities.ListItem;
|
||||
import eu.siacs.conversations.entities.Message;
|
||||
import eu.siacs.conversations.entities.MucOptions;
|
||||
|
@ -448,7 +449,7 @@ public class UIHelper {
|
|||
}
|
||||
|
||||
public static String getMessageDisplayName(final Message message) {
|
||||
final Conversation conversation = message.getConversation();
|
||||
final Conversational conversation = message.getConversation();
|
||||
if (message.getStatus() == Message.STATUS_RECEIVED) {
|
||||
final Contact contact = message.getContact();
|
||||
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
||||
|
@ -461,8 +462,8 @@ public class UIHelper {
|
|||
return contact != null ? contact.getDisplayName() : "";
|
||||
}
|
||||
} else {
|
||||
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
||||
return conversation.getMucOptions().getSelf().getName();
|
||||
if (conversation instanceof Conversation && conversation.getMode() == Conversation.MODE_MULTI) {
|
||||
return ((Conversation) conversation).getMucOptions().getSelf().getName();
|
||||
} else {
|
||||
final Jid jid = conversation.getAccount().getJid();
|
||||
return jid.getLocal() != null ? jid.getLocal() : Jid.ofDomain(jid.getDomain()).toString();
|
||||
|
|
|
@ -261,7 +261,7 @@ public class JingleConnection implements Transferable {
|
|||
|
||||
public void init(final Message message) {
|
||||
if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
|
||||
Conversation conversation = message.getConversation();
|
||||
Conversation conversation = (Conversation) message.getConversation();
|
||||
conversation.getAccount().getAxolotlService().prepareKeyTransportMessage(conversation, new OnMessageCreatedCallback() {
|
||||
@Override
|
||||
public void run(XmppAxolotlMessage xmppAxolotlMessage) {
|
||||
|
|
|
@ -46,6 +46,8 @@
|
|||
android:layout_height="match_parent"
|
||||
android:background="?attr/activity_background_search"
|
||||
android:divider="@android:color/transparent"
|
||||
android:dividerHeight="0dp"/>
|
||||
android:dividerHeight="0dp"
|
||||
android:listSelector="@android:color/transparent"
|
||||
android:stackFromBottom="true"/>
|
||||
</LinearLayout>
|
||||
</layout>
|
Loading…
Reference in a new issue