Skip to content

Commit

Permalink
Fix the delivery date of forwarded messages should be the server time #…
Browse files Browse the repository at this point in the history
…1591 + Return an error instead of ok if the message for forwarding was not found
  • Loading branch information
JamesChenX committed Dec 12, 2024
1 parent 1cd1745 commit 4d52252
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ public ClientRequestHandler handleCreateMessageRequest() {
clientRequest.userId(),
clientRequest.clientIp(),
request.getMessageId(),
isGroupMessage,
false,
targetId);
} else {
List<byte[]> records = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ public class MessageService extends BaseService {

private static final Logger LOGGER = LoggerFactory.getLogger(MessageService.class);

private static final Mono<MessageAndRecipientIds> ERROR_NOT_MESSAGE_RECIPIENT_OR_SENDER_TO_FORWARD_MESSAGE =
Mono.error(ResponseException.get(NOT_MESSAGE_RECIPIENT_OR_SENDER_TO_FORWARD_MESSAGE));

private static final Method GET_MESSAGES_TO_DELETE_METHOD;

private final MessageRepository messageRepository;
Expand Down Expand Up @@ -1260,32 +1263,32 @@ public Mono<MessageAndRecipientIds> authAndCloneAndSaveMessage(
@NotNull Long requesterId,
@Nullable byte[] requesterIp,
@NotNull Long referenceId,
@NotNull Boolean isGroupMessage,
@NotNull Boolean isSystemMessage,
@NotNull Long targetId) {
return queryMessage(referenceId).flatMap(message -> isMessageRecipientOrSender(requesterId,
message.getIsGroupMessage(),
message.getTargetId(),
message.getSenderId()).flatMap(isMessageRecipientOrSender -> {
if (!isMessageRecipientOrSender) {
return Mono.error(ResponseException
.get(NOT_MESSAGE_RECIPIENT_OR_SENDER_TO_FORWARD_MESSAGE));
return ERROR_NOT_MESSAGE_RECIPIENT_OR_SENDER_TO_FORWARD_MESSAGE;
}
return authAndSaveMessage(queryRecipientIds,
null,
node.nextLargeGapId(ServiceType.MESSAGE),
requesterId,
requesterIp,
targetId,
isGroupMessage,
isSystemMessage,
message.getIsGroupMessage(),
message.getIsSystemMessage(),
message.getText(),
message.getRecords(),
message.getBurnAfter(),
message.getDeliveryDate(),
null,
referenceId,
null);
}));
}))
// We should not tell the client that the message was not found.
// Otherwise, the user can check if any message exists or not.
.switchIfEmpty(ERROR_NOT_MESSAGE_RECIPIENT_OR_SENDER_TO_FORWARD_MESSAGE);
}

public Mono<MessageAndRecipientIds> cloneAndSaveMessage(
Expand Down Expand Up @@ -1429,13 +1432,7 @@ private Mono<Void> saveAndSendMessage0(
deliveryDate,
null,
preMessageId)
: authAndCloneAndSaveMessage(send,
senderId,
senderIp,
referenceId,
isGroupMessage,
isSystemMessage,
targetId);
: authAndCloneAndSaveMessage(send, senderId, senderIp, referenceId, targetId);
} else {
saveMono = referenceId == null
? saveMessage(send,
Expand Down

0 comments on commit 4d52252

Please sign in to comment.