Skip to content

Commit 4d52252

Browse files
committed
Fix the delivery date of forwarded messages should be the server time #1591 + Return an error instead of ok if the message for forwarding was not found
1 parent 1cd1745 commit 4d52252

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

turms-service/src/main/java/im/turms/service/domain/message/access/servicerequest/controller/MessageServiceController.java

-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ public ClientRequestHandler handleCreateMessageRequest() {
142142
clientRequest.userId(),
143143
clientRequest.clientIp(),
144144
request.getMessageId(),
145-
isGroupMessage,
146-
false,
147145
targetId);
148146
} else {
149147
List<byte[]> records = null;

turms-service/src/main/java/im/turms/service/domain/message/service/MessageService.java

+12-15
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ public class MessageService extends BaseService {
127127

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

130+
private static final Mono<MessageAndRecipientIds> ERROR_NOT_MESSAGE_RECIPIENT_OR_SENDER_TO_FORWARD_MESSAGE =
131+
Mono.error(ResponseException.get(NOT_MESSAGE_RECIPIENT_OR_SENDER_TO_FORWARD_MESSAGE));
132+
130133
private static final Method GET_MESSAGES_TO_DELETE_METHOD;
131134

132135
private final MessageRepository messageRepository;
@@ -1260,32 +1263,32 @@ public Mono<MessageAndRecipientIds> authAndCloneAndSaveMessage(
12601263
@NotNull Long requesterId,
12611264
@Nullable byte[] requesterIp,
12621265
@NotNull Long referenceId,
1263-
@NotNull Boolean isGroupMessage,
1264-
@NotNull Boolean isSystemMessage,
12651266
@NotNull Long targetId) {
12661267
return queryMessage(referenceId).flatMap(message -> isMessageRecipientOrSender(requesterId,
12671268
message.getIsGroupMessage(),
12681269
message.getTargetId(),
12691270
message.getSenderId()).flatMap(isMessageRecipientOrSender -> {
12701271
if (!isMessageRecipientOrSender) {
1271-
return Mono.error(ResponseException
1272-
.get(NOT_MESSAGE_RECIPIENT_OR_SENDER_TO_FORWARD_MESSAGE));
1272+
return ERROR_NOT_MESSAGE_RECIPIENT_OR_SENDER_TO_FORWARD_MESSAGE;
12731273
}
12741274
return authAndSaveMessage(queryRecipientIds,
12751275
null,
12761276
node.nextLargeGapId(ServiceType.MESSAGE),
12771277
requesterId,
12781278
requesterIp,
12791279
targetId,
1280-
isGroupMessage,
1281-
isSystemMessage,
1280+
message.getIsGroupMessage(),
1281+
message.getIsSystemMessage(),
12821282
message.getText(),
12831283
message.getRecords(),
12841284
message.getBurnAfter(),
1285-
message.getDeliveryDate(),
1285+
null,
12861286
referenceId,
12871287
null);
1288-
}));
1288+
}))
1289+
// We should not tell the client that the message was not found.
1290+
// Otherwise, the user can check if any message exists or not.
1291+
.switchIfEmpty(ERROR_NOT_MESSAGE_RECIPIENT_OR_SENDER_TO_FORWARD_MESSAGE);
12891292
}
12901293

12911294
public Mono<MessageAndRecipientIds> cloneAndSaveMessage(
@@ -1429,13 +1432,7 @@ private Mono<Void> saveAndSendMessage0(
14291432
deliveryDate,
14301433
null,
14311434
preMessageId)
1432-
: authAndCloneAndSaveMessage(send,
1433-
senderId,
1434-
senderIp,
1435-
referenceId,
1436-
isGroupMessage,
1437-
isSystemMessage,
1438-
targetId);
1435+
: authAndCloneAndSaveMessage(send, senderId, senderIp, referenceId, targetId);
14391436
} else {
14401437
saveMono = referenceId == null
14411438
? saveMessage(send,

0 commit comments

Comments
 (0)