Skip to content

Commit

Permalink
'#1923: Handle WA quote of a template message (type 32).
Browse files Browse the repository at this point in the history
  • Loading branch information
wladimirleite committed Jan 3, 2024
1 parent 9226877 commit 942b28b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static iped.parsers.whatsapp.Message.MessageType.STICKER_MESSAGE;
import static iped.parsers.whatsapp.Message.MessageType.SUBJECT_CHANGED;
import static iped.parsers.whatsapp.Message.MessageType.TEMPLATE_MESSAGE;
import static iped.parsers.whatsapp.Message.MessageType.TEMPLATE_QUOTE;
import static iped.parsers.whatsapp.Message.MessageType.TEXT_MESSAGE;
import static iped.parsers.whatsapp.Message.MessageType.UNAVAILABLE_VIDEO_CALL;
import static iped.parsers.whatsapp.Message.MessageType.UNAVAILABLE_VOICE_CALL;
Expand Down Expand Up @@ -639,6 +640,9 @@ protected Message.MessageType decodeMessageType(int messageType, int status, Int
case 28:
result = TEMPLATE_MESSAGE;
break;
case 32:
result = TEMPLATE_QUOTE;
break;
case 36:
result = EPHEMERAL_DURATION_CHANGED;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public void setSortId(long sortId) {
}

public static enum MessageType {
TEXT_MESSAGE, IMAGE_MESSAGE, AUDIO_MESSAGE, VIDEO_MESSAGE, UNKNOWN_MEDIA_MESSAGE, CONTACT_MESSAGE, LOCATION_MESSAGE, SHARE_LOCATION_MESSAGE, VOICE_CALL, VIDEO_CALL, APP_MESSAGE, GIF_MESSAGE, BLOCKED_CONTACT, UNBLOCKED_CONTACT, BUSINESS_CHAT, BUSINESS_TO_STANDARD, MESSAGES_ENCRYPTED, MESSAGES_NOW_ENCRYPTED, ENCRYPTION_KEY_CHANGED, MISSED_VOICE_CALL, MISSED_VIDEO_CALL, DELETED_MESSAGE, DELETED_BY_ADMIN, DELETED_BY_SENDER, GROUP_CREATED, USER_JOINED_GROUP, USER_JOINED_GROUP_FROM_LINK, USERS_JOINED_GROUP, USER_LEFT_GROUP, USER_REMOVED_FROM_GROUP, URL_MESSAGE, GROUP_ICON_CHANGED, GROUP_ICON_DELETED, GROUP_DESCRIPTION_CHANGED, SUBJECT_CHANGED, YOU_ADMIN, WAITING_MESSAGE, STICKER_MESSAGE, REFUSED_VIDEO_CALL, REFUSED_VOICE_CALL, UNAVAILABLE_VIDEO_CALL, UNAVAILABLE_VOICE_CALL, UNKNOWN_VOICE_CALL, UNKNOWN_VIDEO_CALL, VIEW_ONCE_IMAGE_MESSAGE, VIEW_ONCE_VIDEO_MESSAGE, CALL_MESSAGE, BUSINESS_META_SECURE_SERVICE, GROUP_INVITE, TEMPLATE_MESSAGE, POLL_MESSAGE, EPHEMERAL_DURATION_CHANGED, EPHEMERAL_ENABLED, EPHEMERAL_SAVE, GROUP_ONLY_ADMINS_CAN_SEND, GROUP_ALL_MEMBERS_CAN_SEND, UNKNOWN_MESSAGE
TEXT_MESSAGE, IMAGE_MESSAGE, AUDIO_MESSAGE, VIDEO_MESSAGE, UNKNOWN_MEDIA_MESSAGE, CONTACT_MESSAGE, LOCATION_MESSAGE, SHARE_LOCATION_MESSAGE, VOICE_CALL, VIDEO_CALL, APP_MESSAGE, GIF_MESSAGE, BLOCKED_CONTACT, UNBLOCKED_CONTACT, BUSINESS_CHAT, BUSINESS_TO_STANDARD, MESSAGES_ENCRYPTED, MESSAGES_NOW_ENCRYPTED, ENCRYPTION_KEY_CHANGED, MISSED_VOICE_CALL, MISSED_VIDEO_CALL, DELETED_MESSAGE, DELETED_BY_ADMIN, DELETED_BY_SENDER, GROUP_CREATED, USER_JOINED_GROUP, USER_JOINED_GROUP_FROM_LINK, USERS_JOINED_GROUP, USER_LEFT_GROUP, USER_REMOVED_FROM_GROUP, URL_MESSAGE, GROUP_ICON_CHANGED, GROUP_ICON_DELETED, GROUP_DESCRIPTION_CHANGED, SUBJECT_CHANGED, YOU_ADMIN, WAITING_MESSAGE, STICKER_MESSAGE, REFUSED_VIDEO_CALL, REFUSED_VOICE_CALL, UNAVAILABLE_VIDEO_CALL, UNAVAILABLE_VOICE_CALL, UNKNOWN_VOICE_CALL, UNKNOWN_VIDEO_CALL, VIEW_ONCE_IMAGE_MESSAGE, VIEW_ONCE_VIDEO_MESSAGE, CALL_MESSAGE, BUSINESS_META_SECURE_SERVICE, GROUP_INVITE, TEMPLATE_MESSAGE, TEMPLATE_QUOTE, POLL_MESSAGE, EPHEMERAL_DURATION_CHANGED, EPHEMERAL_ENABLED, EPHEMERAL_SAVE, GROUP_ONLY_ADMINS_CAN_SEND, GROUP_ALL_MEMBERS_CAN_SEND, UNKNOWN_MESSAGE
}

public static enum MessageStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,12 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
out.println("<div class=\"attachImg\" style=\"width:33px;height:33px;display:table-cell\" title=\"Doc\"></div>");
}
break;
case TEMPLATE_MESSAGE:
out.print("<div class=\"" + quoteClass + "\" " + quoteClick
+ "><div style=\"display:table-cell;\"><span class=\"quote_user\">" + quoteUser
+ "</span><br><span class=\"quote_msg\">" + formatTemplate(messageQuote)
+ "</span></div>");
break;
default:
out.print("<div class=\""+quoteClass+"\" "+quoteClick+"><div style=\"display:table-cell;\"><span class=\"quote_user\">"+quoteUser+
"</span><br><span class=\"quote_msg\">"+ format(dataQuote) + "</span></div>");
Expand All @@ -639,10 +645,11 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean

switch (message.getMessageType()) {
case TEXT_MESSAGE:
case TEMPLATE_QUOTE:
if (message.getData() != null && !message.getData().isBlank()) {
out.print(format(message.getData()) + "<br>"); //$NON-NLS-1$
}
// Some (rare) text messages have thumbs
// Some textual messages may have thumbs
printThumb(out, message);
break;
case UNKNOWN_MEDIA_MESSAGE:
Expand Down Expand Up @@ -694,26 +701,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean
break;
case TEMPLATE_MESSAGE:
printThumb(out, message);
if (message.getData() != null && !message.getData().isBlank()) {
out.println(format(message.getData()) + "<br>");
}
MessageTemplate t = message.getMessageTemplate();
if (t != null) {
String content = t.getContent();
if (content != null && !content.isBlank()) {
out.println(format(content) + "<br>");
}
for (MessageTemplate.Button button : t.getButtons()) {
String text = button.getText();
if (text != null && !text.isBlank()) {
out.println("<b>[" + format(text) + "]</b><br>");
}
String extra = button.getExtra();
if (extra != null && !extra.isBlank() && !extra.equals(text)) {
out.println(format(extra) + "<br>");
}
}
}
out.println(formatTemplate(message));
break;
case POLL_MESSAGE:
printThumb(out, message);
Expand Down Expand Up @@ -1020,6 +1008,31 @@ private void printThumb(PrintWriter out, Message message) {
}
}

private String formatTemplate(Message message) {
StringBuilder sb = new StringBuilder();
if (message.getData() != null && !message.getData().isBlank()) {
sb.append(format(message.getData())).append("<br>");
}
MessageTemplate t = message.getMessageTemplate();
if (t != null) {
String content = t.getContent();
if (content != null && !content.isBlank()) {
sb.append(format(content)).append("<br>");
}
for (MessageTemplate.Button button : t.getButtons()) {
String text = button.getText();
if (text != null && !text.isBlank()) {
sb.append("<b>[").append(format(text)).append("]</b><br>");
}
String extra = button.getExtra();
if (extra != null && !extra.isBlank() && !extra.equals(text)) {
sb.append(format(extra)).append("<br>");
}
}
}
return sb.toString();
}

private String getBestContactName(Message message, WAContactsDirectory contactsDirectory, WAAccount account) {
return getBestContactName(message.isFromMe(), message.getRemoteResource(), contactsDirectory, account);
}
Expand Down

0 comments on commit 942b28b

Please sign in to comment.