From 2a5753cb32dd184d66ee28d38881c9135f8526c4 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 21 Feb 2018 23:52:11 +0300 Subject: server: send attachments to telegram as photos --- .../java/com/juick/formatters/PlainTextFormatter.java | 15 ++------------- .../src/main/java/com/juick/util/MessageUtils.java | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 13 deletions(-) (limited to 'juick-core/src/main/java/com/juick') diff --git a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java index 5625fad6..c7e79265 100644 --- a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java +++ b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java @@ -50,19 +50,8 @@ public class PlainTextFormatter { sb.append(StringUtils.defaultString(jmsg.getText())); } sb.append("\n"); - if (StringUtils.isNotEmpty(jmsg.getAttachmentType())) { - // FIXME: attachment does not serialized to xml - if (jmsg.getAttachment() == null) { - if (jmsg.getRid() > 0) { - sb.append(String.format("http://i.juick.com/photos-1024/%d-%d.%s", jmsg.getMid(), - jmsg.getRid(), jmsg.getAttachmentType())); - } else { - sb.append(String.format("http://i.juick.com/photos-1024/%d.%s", jmsg.getMid(), - jmsg.getAttachmentType())); - } - } else { - sb.append(jmsg.getAttachment().getMedium().getUrl()); - } + if (!markdown && StringUtils.isNotEmpty(jmsg.getAttachmentType())) { + sb.append(MessageUtils.attachmentUrl(jmsg)); } return sb.toString(); } diff --git a/juick-core/src/main/java/com/juick/util/MessageUtils.java b/juick-core/src/main/java/com/juick/util/MessageUtils.java index 97d55b09..f17737db 100644 --- a/juick-core/src/main/java/com/juick/util/MessageUtils.java +++ b/juick-core/src/main/java/com/juick/util/MessageUtils.java @@ -197,4 +197,21 @@ public class MessageUtils { return s.replace("_", "\\_").replace("*", "\\*") .replace("`", "\\`"); } + public static String attachmentUrl(final Message jmsg) { + if (StringUtils.isEmpty(jmsg.getAttachmentType())) { + return StringUtils.EMPTY; + } + // FIXME: attachment does not serialized to xml + if (jmsg.getAttachment() == null) { + if (jmsg.getRid() > 0) { + return String.format("http://i.juick.com/photos-1024/%d-%d.%s", jmsg.getMid(), + jmsg.getRid(), jmsg.getAttachmentType()); + } else { + return String.format("http://i.juick.com/photos-1024/%d.%s", jmsg.getMid(), + jmsg.getAttachmentType()); + } + } else { + return jmsg.getAttachment().getMedium().getUrl(); + } + } } -- cgit v1.2.3