Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = 'com.flexcodelabs'
version = '0.0.64'
version = '0.0.65'
description = 'Flextuma App'

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public record WhatsAppConversationDTO(
String fromNumber,
String contactName,
String lastMessageContent,
/** WhatsApp message type ("text", "image", "sticker", ...) of the last message. The
* frontend uses this to render a type icon + label when {@code lastMessageContent} is
* null (a media message with no caption). */
String lastMessageType,
LocalDateTime lastMessageAt,
long unreadCount) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ public WhatsAppInboxMessage markAsRead(UUID id) {

private static final int CONVERSATION_SCAN_LIMIT = 2000;

/** A media message with no caption has null content; fall back to a type label for the preview. */
private String displayContent(WhatsAppInboxMessage message) {
/** Null when a media message has no caption; the frontend then renders a type icon + label
* from {@code lastMessageType} instead of this text. */
private String previewContent(WhatsAppInboxMessage message) {
String content = message.getContent();
return content != null && !content.isBlank() ? content : "[" + message.getMessageType() + "]";
return content != null && !content.isBlank() ? content : null;
}

// findAllPaginated below is called on `this`, which bypasses the Spring proxy that backs
Expand All @@ -123,7 +124,8 @@ public Pagination<WhatsAppConversationDTO> listConversations(int page, int pageS
.phoneNumberId(message.getConfig().getPhoneNumberId())
.fromNumber(message.getFromNumber())
.contactName(message.getContactName())
.lastMessageContent(displayContent(message))
.lastMessageContent(previewContent(message))
.lastMessageType(message.getMessageType())
.lastMessageAt(message.getReceivedAt())
.build());
}
Expand All @@ -137,6 +139,7 @@ public Pagination<WhatsAppConversationDTO> listConversations(int page, int pageS
.fromNumber(summary.fromNumber())
.contactName(summary.contactName())
.lastMessageContent(summary.lastMessageContent())
.lastMessageType(summary.lastMessageType())
.lastMessageAt(summary.lastMessageAt())
.unreadCount(unreadCounts.getOrDefault(entry.getKey(), 0L))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void listConversations_shouldGroupByConfigAndFromNumber_andCountUnread() {
}

@Test
void listConversations_shouldFallBackToTypeLabel_whenMediaMessageHasNoCaption() {
void listConversations_shouldExposeTypeAndNullContent_whenMediaMessageHasNoCaption() {
WhatsAppWebhookConfig config = new WhatsAppWebhookConfig();
config.setId(UUID.randomUUID());

Expand All @@ -126,7 +126,8 @@ void listConversations_shouldFallBackToTypeLabel_whenMediaMessageHasNoCaption()

Pagination<WhatsAppConversationDTO> result = service.listConversations(0, 25);

assertEquals("[image]", result.getData().get(0).lastMessageContent());
assertEquals(null, result.getData().get(0).lastMessageContent());
assertEquals("image", result.getData().get(0).lastMessageType());
}

@Test
Expand Down