From 42fea1a588866902ca3daf6c4eeaeea5bc1f3227 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Thu, 25 Feb 2021 12:47:27 +0100 Subject: [PATCH] fix missing deck card links / always show links if available in message Signed-off-by: Marcel Hibbe --- CHANGELOG.md | 3 ++ .../talk/jobs/NotificationWorker.java | 2 +- .../talk/models/json/chat/ChatMessage.java | 2 +- .../talk/models/json/chat/ChatUtils.java | 43 ---------------- .../talk/models/json/chat/ChatUtils.kt | 49 +++++++++++++++++++ 5 files changed, 54 insertions(+), 45 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/talk/models/json/chat/ChatUtils.java create mode 100644 app/src/main/java/com/nextcloud/talk/models/json/chat/ChatUtils.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 2beeb6040..2aac0a8b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Types of changes can be: Added/Changed/Deprecated/Removed/Fixed/Security ## [Unreleased] +### Added +### Fixed +- show links for deck-cards ## [11.0.0] - 2021-02-23 ### Added diff --git a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java index 909b1ccd8..240915f61 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java @@ -210,7 +210,7 @@ public class NotificationWorker extends Worker { if (notification.getMessageRichParameters() != null && notification.getMessageRichParameters().size() > 0) { - decryptedPushMessage.setText(ChatUtils.getParsedMessage(notification.getMessageRich(), + decryptedPushMessage.setText(ChatUtils.Companion.getParsedMessage(notification.getMessageRich(), notification.getMessageRichParameters())); } else { decryptedPushMessage.setText(notification.getMessage()); diff --git a/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java b/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java index 0bd9bd525..b1cfb3470 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java @@ -155,7 +155,7 @@ public class ChatMessage implements IMessage, MessageContentType, MessageContent @Override public String getText() { - return ChatUtils.getParsedMessage(getMessage(), getMessageParameters()); + return ChatUtils.Companion.getParsedMessage(getMessage(), getMessageParameters()); } public String getLastMessageDisplayText() { diff --git a/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatUtils.java b/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatUtils.java deleted file mode 100644 index 92d7b2f05..000000000 --- a/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatUtils.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017-2018 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.models.json.chat; - -import java.util.HashMap; - -public class ChatUtils { - - public static String getParsedMessage(String message, HashMap> messageParameters) { - if (messageParameters != null && messageParameters.size() > 0) { - for (String key : messageParameters.keySet()) { - HashMap individualHashMap = messageParameters.get(key); - if (individualHashMap.get("type").equals("user") || individualHashMap.get("type").equals("guest") || individualHashMap.get("type").equals("call")) { - message = message.replaceAll("\\{" + key + "\\}", "@" + - messageParameters.get(key).get("name")); - } else if (individualHashMap.get("type").equals("file")) { - message = message.replaceAll("\\{" + key + "\\}", messageParameters.get(key).get("name")); - } - } - } - - - return message; - } -} diff --git a/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatUtils.kt b/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatUtils.kt new file mode 100644 index 000000000..24ee28e11 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatUtils.kt @@ -0,0 +1,49 @@ +/* + * Nextcloud Talk application + * + * @author Mario Danic + * Copyright (C) 2017-2018 Mario Danic + * @author Marcel Hibbe + * Copyright (C) 2021 Marcel Hibbe + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.nextcloud.talk.models.json.chat + +class ChatUtils { + companion object { + fun getParsedMessage(message: String?, messageParameters: HashMap>?): + String? { + var resultMessage = message + if (messageParameters != null && messageParameters.size > 0) { + for (key in messageParameters.keys) { + val individualHashMap = messageParameters[key] + val type = individualHashMap?.get("type") + if (type == "user" || type == "guest" || type == "call") { + resultMessage = resultMessage?.replace("{$key}", "@" + individualHashMap["name"]) + } else if (individualHashMap?.containsKey("link") == true) { + resultMessage = if (type == "file") { + resultMessage?.replace("{$key}", individualHashMap["name"].toString()) + } else { + individualHashMap["link"].toString() + } + } + } + } + return resultMessage + } + } +} +