forked from Qortal/qortal
Fixed build issues due to merge.
This commit is contained in:
parent
597fbce9b0
commit
d22e97ffc8
@ -134,12 +134,7 @@ public class ChatResource {
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
|
||||
ChatTransactionData chatTransactionData = (ChatTransactionData) repository.getTransactionRepository().fromSignature(signature);
|
||||
if (chatTransactionData == null) {
|
||||
throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.INVALID_CRITERIA, "Message not found");
|
||||
}
|
||||
|
||||
return repository.getChatRepository().toChatMessage(chatTransactionData);
|
||||
return repository.getChatRepository().getChatMessageBySignature(signature);
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
}
|
||||
|
@ -1954,7 +1954,7 @@ public class Controller extends Thread {
|
||||
boolean reverse = (direction == Direction.BACKWARDS);
|
||||
|
||||
List<ChatMessage> chatMessages = repository.getChatRepository().getMessagesMatchingCriteria(
|
||||
before, after, null, null, numberRequested, 0, reverse);
|
||||
before, after, null, null, null, null, null, numberRequested, 0, reverse);
|
||||
|
||||
Message chatMessagesMessage = new ChatMessagesMessage(chatMessages);
|
||||
chatMessagesMessage.setId(message.getId());
|
||||
@ -2012,7 +2012,7 @@ public class Controller extends Thread {
|
||||
|
||||
// Get all recent messages from repository
|
||||
List<ChatMessage> ourChatMessages = repository.getChatRepository().getMessagesMatchingCriteria(
|
||||
null, after, null, null, null, 0, true);
|
||||
null, after, null, null, null, null, null, null, 0, true);
|
||||
|
||||
for (ChatMessage chatMessage : ourChatMessages) {
|
||||
// Skip if the sender already has this one
|
||||
|
@ -1233,7 +1233,7 @@ public class Network {
|
||||
|
||||
// Get all recent messages from repository
|
||||
List<ChatMessage> ourChatMessages = repository.getChatRepository().getMessagesMatchingCriteria(
|
||||
null, after, null, null, null, 0, true);
|
||||
null, after, null, null, null, null, null, null, 0, true);
|
||||
|
||||
List<byte[]> signatures = new ArrayList<>();
|
||||
for (ChatMessage chatMessage : ourChatMessages) {
|
||||
|
@ -14,11 +14,15 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.qortal.naming.Name.MAX_NAME_SIZE;
|
||||
import static org.qortal.transform.Transformer.SIGNATURE_LENGTH;
|
||||
|
||||
public class ChatMessagesMessage extends Message {
|
||||
|
||||
private List<ChatMessage> chatMessages;
|
||||
|
||||
private static final int CHAT_REFERENCE_LENGTH = SIGNATURE_LENGTH;
|
||||
|
||||
|
||||
public ChatMessagesMessage(List<ChatMessage> chatMessages) {
|
||||
super(MessageType.CHAT_MESSAGES);
|
||||
|
||||
@ -44,6 +48,14 @@ public class ChatMessagesMessage extends Message {
|
||||
|
||||
Serialization.serializeSizedStringV2(bytes, chatMessage.getRecipientName());
|
||||
|
||||
// Include chat reference if it's not null
|
||||
if (chatMessage.getChatReference() != null) {
|
||||
bytes.write((byte) 1);
|
||||
bytes.write(chatMessage.getChatReference());
|
||||
} else {
|
||||
bytes.write((byte) 0);
|
||||
}
|
||||
|
||||
bytes.write(Ints.toByteArray(chatMessage.getData().length));
|
||||
bytes.write(chatMessage.getData());
|
||||
|
||||
@ -81,7 +93,7 @@ public class ChatMessagesMessage extends Message {
|
||||
|
||||
int txGroupId = bytes.getInt();
|
||||
|
||||
byte[] reference = new byte[Transformer.SIGNATURE_LENGTH];
|
||||
byte[] reference = new byte[SIGNATURE_LENGTH];
|
||||
bytes.get(reference);
|
||||
|
||||
byte[] senderPublicKey = new byte[Transformer.PUBLIC_KEY_LENGTH];
|
||||
@ -95,6 +107,14 @@ public class ChatMessagesMessage extends Message {
|
||||
|
||||
String recipientName = Serialization.deserializeSizedStringV2(bytes, MAX_NAME_SIZE);
|
||||
|
||||
byte[] chatReference = null;
|
||||
boolean hasChatReference = bytes.get() != 0;
|
||||
|
||||
if (hasChatReference) {
|
||||
chatReference = new byte[CHAT_REFERENCE_LENGTH];
|
||||
bytes.get(chatReference);
|
||||
}
|
||||
|
||||
int dataLength = bytes.getInt();
|
||||
byte[] data = new byte[dataLength];
|
||||
bytes.get(data);
|
||||
@ -103,11 +123,11 @@ public class ChatMessagesMessage extends Message {
|
||||
|
||||
boolean isEncrypted = bytes.getInt() == 1;
|
||||
|
||||
byte[] signature = new byte[Transformer.SIGNATURE_LENGTH];
|
||||
byte[] signature = new byte[SIGNATURE_LENGTH];
|
||||
bytes.get(signature);
|
||||
|
||||
ChatMessage chatMessage = new ChatMessage(timestamp, txGroupId, reference, senderPublicKey,
|
||||
sender, senderName, recipient, recipientName, data, isText, isEncrypted, signature);
|
||||
sender, senderName, recipient, recipientName, chatReference, data, isText, isEncrypted, signature);
|
||||
chatMessages.add(chatMessage);
|
||||
}
|
||||
|
||||
|
@ -262,7 +262,7 @@ public class HSQLDBChatRepository implements ChatRepository {
|
||||
|
||||
sql.append("SELECT created_when, tx_group_id, reference, creator, sender, recipient, "
|
||||
// TODO: + "SenderNames.name, RecipientNames.name, "
|
||||
+ "data, is_text, is_encrypted, signature "
|
||||
+ "chat_reference, data, is_text, is_encrypted, signature "
|
||||
+ "FROM ChatMessages WHERE signature = ?");
|
||||
// TODO: + "LEFT OUTER JOIN Names AS SenderNames ON SenderNames.owner = sender "
|
||||
// TODO: + "LEFT OUTER JOIN Names AS RecipientNames ON RecipientNames.owner = recipient ");
|
||||
@ -279,13 +279,14 @@ public class HSQLDBChatRepository implements ChatRepository {
|
||||
String senderName = resultSet.getString(6); // TOOD
|
||||
String recipient = resultSet.getString(7);
|
||||
String recipientName = resultSet.getString(8); // TODO
|
||||
byte[] data = resultSet.getBytes(9);
|
||||
boolean isText = resultSet.getBoolean(10);
|
||||
boolean isEncrypted = resultSet.getBoolean(11);
|
||||
byte[] signatureResult = resultSet.getBytes(12);
|
||||
byte[] chatReference = resultSet.getBytes(9);
|
||||
byte[] data = resultSet.getBytes(10);
|
||||
boolean isText = resultSet.getBoolean(11);
|
||||
boolean isEncrypted = resultSet.getBoolean(12);
|
||||
byte[] signatureResult = resultSet.getBytes(13);
|
||||
|
||||
ChatMessage chatMessage = new ChatMessage(timestamp, groupId, reference, senderPublicKey, sender,
|
||||
senderName, recipient, recipientName, data, isText, isEncrypted, signatureResult);
|
||||
senderName, recipient, recipientName, chatReference, data, isText, isEncrypted, signatureResult);
|
||||
|
||||
return chatMessage;
|
||||
} catch (SQLException e) {
|
||||
|
@ -37,6 +37,9 @@ public class ChatMessageTests extends Common {
|
||||
long timestamp = NTP.getTime();
|
||||
int txGroupId = 1;
|
||||
|
||||
byte[] chatReference = new byte[64];
|
||||
new Random().nextBytes(chatReference);
|
||||
|
||||
byte[] messageData = new byte[80];
|
||||
new Random().nextBytes(messageData);
|
||||
|
||||
@ -45,7 +48,7 @@ public class ChatMessageTests extends Common {
|
||||
|
||||
ChatMessage aliceMessage = new ChatMessage(timestamp, txGroupId, alice.getLastReference(),
|
||||
alice.getPublicKey(), alice.getAddress(), "alice", bob.getAddress(), "bob",
|
||||
messageData, true, true, signature);
|
||||
chatReference, messageData, true, true, signature);
|
||||
|
||||
// Serialize
|
||||
ChatMessagesMessage chatMessagesMessage = new ChatMessagesMessage(Arrays.asList(aliceMessage));
|
||||
|
Loading…
Reference in New Issue
Block a user