This commit is contained in:
Niels Andriesse 2019-09-18 10:00:18 +10:00
parent cbada40a6e
commit a78b8a77b6
7 changed files with 17 additions and 14 deletions

View File

@ -2186,7 +2186,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
recipient.getAddress().isEmail() || recipient.getAddress().isEmail() ||
inputPanel.getQuote().isPresent() || inputPanel.getQuote().isPresent() ||
linkPreviewViewModel.hasLinkPreview() || linkPreviewViewModel.hasLinkPreview() ||
LinkPreviewUtil.isWhitelistedMediaUrl(message) || LinkPreviewUtil.isWhitelistedMediaUrl(message) || // Loki - Send GIFs as media messages
needsSplit; needsSplit;
Log.i(TAG, "isManual Selection: " + sendButton.isManualSelection()); Log.i(TAG, "isManual Selection: " + sendButton.isManualSelection());

View File

@ -95,6 +95,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
OutgoingMediaMessage message = database.getOutgoingMessage(messageId); OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
List<Attachment> attachments = new LinkedList<>(); List<Attachment> attachments = new LinkedList<>();
// Loki - For now all attachments are re-fetched by the receiver
// attachments.addAll(message.getAttachments()); // attachments.addAll(message.getAttachments());
// attachments.addAll(Stream.of(message.getLinkPreviews()).filter(p -> p.getThumbnail().isPresent()).map(p -> p.getThumbnail().get()).toList()); // attachments.addAll(Stream.of(message.getLinkPreviews()).filter(p -> p.getThumbnail().isPresent()).map(p -> p.getThumbnail().get()).toList());
attachments.addAll(Stream.of(message.getSharedContacts()).filter(c -> c.getAvatar() != null).map(c -> c.getAvatar().getAttachment()).withoutNulls().toList()); attachments.addAll(Stream.of(message.getSharedContacts()).filter(c -> c.getAvatar() != null).map(c -> c.getAvatar().getAttachment()).withoutNulls().toList());
@ -284,7 +285,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
private @NonNull List<Address> getGroupMessageRecipients(String groupId, long messageId) { private @NonNull List<Address> getGroupMessageRecipients(String groupId, long messageId) {
ArrayList<Address> result = new ArrayList<>(); ArrayList<Address> result = new ArrayList<>();
result.add(Address.fromSerialized(LokiGroupChatAPI.getPublicChatServer())); result.add(Address.fromSerialized(LokiGroupChatAPI.getPublicChatServer())); // Loki - All group messages should be directed to the Loki Public Chat for now
return result; return result;
/* /*

View File

@ -76,6 +76,7 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
OutgoingMediaMessage message = database.getOutgoingMessage(messageId); OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
List<Attachment> attachments = new LinkedList<>(); List<Attachment> attachments = new LinkedList<>();
// Loki - For now all attachments are re-fetched by the receiver
// attachments.addAll(message.getAttachments()); // attachments.addAll(message.getAttachments());
// attachments.addAll(Stream.of(message.getLinkPreviews()).filter(p -> p.getThumbnail().isPresent()).map(p -> p.getThumbnail().get()).toList()); // attachments.addAll(Stream.of(message.getLinkPreviews()).filter(p -> p.getThumbnail().isPresent()).map(p -> p.getThumbnail().get()).toList());
attachments.addAll(Stream.of(message.getSharedContacts()).filter(c -> c.getAvatar() != null).map(c -> c.getAvatar().getAttachment()).withoutNulls().toList()); attachments.addAll(Stream.of(message.getSharedContacts()).filter(c -> c.getAvatar() != null).map(c -> c.getAvatar().getAttachment()).withoutNulls().toList());

View File

@ -18,8 +18,6 @@ class LokiMessageDatabase(context: Context, helper: SQLCipherOpenHelper) : Datab
@JvmStatic val createTableCommand = "CREATE TABLE $tableName ($messageID INTEGER PRIMARY KEY, $serverID INTEGER DEFAULT 0, $friendRequestStatus INTEGER DEFAULT 0);" @JvmStatic val createTableCommand = "CREATE TABLE $tableName ($messageID INTEGER PRIMARY KEY, $serverID INTEGER DEFAULT 0, $friendRequestStatus INTEGER DEFAULT 0);"
} }
// TODO: Move the server ID stuff to LokiAPIDatabase?
fun getServerID(messageID: Long): Long? { fun getServerID(messageID: Long): Long? {
val database = databaseHelper.readableDatabase val database = databaseHelper.readableDatabase
return database.get(tableName, "${Companion.messageID} = ?", arrayOf( messageID.toString() )) { cursor -> return database.get(tableName, "${Companion.messageID} = ?", arrayOf( messageID.toString() )) { cursor ->

View File

@ -4,22 +4,24 @@ class RNG(hash: Long) {
private var seed: Long private var seed: Long
private val initial: Long private val initial: Long
private val maxInt32 = Int.MAX_VALUE.toLong()
init { init {
seed = hash % 2147483647 seed = hash % maxInt32
if (seed <= 0) { if (seed <= 0) {
seed = 2147483646 seed = maxInt32 - 1
} }
initial = seed initial = seed
} }
fun next(): Long { fun next(): Long {
val newSeed = (seed * 16807) % 2147483647 val newSeed = (seed * 16807) % maxInt32
seed = newSeed seed = newSeed
return seed return seed
} }
fun nextFloat(): Float { fun nextFloat(): Float {
return (next() - 1).toFloat() / 2147483646 return (next() - 1).toFloat() / (maxInt32 - 1)
} }
fun reset() { fun reset() {

View File

@ -109,21 +109,22 @@ public class MessageSender {
Recipient recipient = message.getRecipient(); Recipient recipient = message.getRecipient();
// Loki - Turn into a GIF message if possible
if (message.getLinkPreviews().isEmpty() && message.getAttachments().isEmpty() && LinkPreviewUtil.isWhitelistedMediaUrl(message.getBody())) { if (message.getLinkPreviews().isEmpty() && message.getAttachments().isEmpty() && LinkPreviewUtil.isWhitelistedMediaUrl(message.getBody())) {
new LinkPreviewRepository(context).fetchGIF(context, message.getBody(), attachmentOrNull -> Util.runOnMain(() -> { new LinkPreviewRepository(context).fetchGIF(context, message.getBody(), attachmentOrNull -> Util.runOnMain(() -> {
if (attachmentOrNull.isPresent()) { if (attachmentOrNull.isPresent()) {
Attachment attachment = attachmentOrNull.get(); Attachment attachment = attachmentOrNull.get();
try { try {
message.getAttachments().add(attachment); message.getAttachments().add(attachment);
long messageId = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener); long messageID = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener);
sendMediaMessage(context, recipient, forceSms, messageId, message.getExpiresIn()); sendMediaMessage(context, recipient, forceSms, messageID, message.getExpiresIn());
} catch (Exception e) { } catch (Exception e) {
// TODO: Handle // TODO: Handle
} }
} else { } else {
try { try {
long messageId = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener); long messageID = database.insertMessageOutbox(message, allocatedThreadId, forceSms, insertListener);
sendMediaMessage(context, recipient, forceSms, messageId, message.getExpiresIn()); sendMediaMessage(context, recipient, forceSms, messageID, message.getExpiresIn());
} catch (MmsException e) { } catch (MmsException e) {
// TODO: Handle // TODO: Handle
} }