diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-02-21 19:11:38 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-02-21 19:11:38 +0100 |
commit | 485609f30cf8771b5594c951029847ee6c0b634e (patch) | |
tree | b1416b12c7dbff6fa76ad17fad713941e9285136 /src/main/java | |
parent | 5466ee4d56db3b79161556ff95cc45aa928fc168 (diff) |
refresh cached RichPreviews after 7 days
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/RichPreview.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/utils/RichPreview.java b/src/main/java/de/pixart/messenger/utils/RichPreview.java index 63835228d..cdde6baaa 100644 --- a/src/main/java/de/pixart/messenger/utils/RichPreview.java +++ b/src/main/java/de/pixart/messenger/utils/RichPreview.java @@ -21,6 +21,9 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.URI; import java.net.URISyntaxException; +import java.util.Calendar; +import java.util.Date; +import java.util.regex.Pattern; import de.pixart.messenger.Config; @@ -56,6 +59,14 @@ public class RichPreview { FileInputStream fis = null; ObjectInputStream is = null; final File file = new File(context.getCacheDir(), RICH_LINK_METADATA + "/" + filename); + if(file.exists()) { + Calendar time = Calendar.getInstance(); + time.add(Calendar.DAY_OF_YEAR, -7); + Date lastModified = new Date(file.lastModified()); + if (lastModified.before(time.getTime())) { + file.delete(); + } + } try { fis = new FileInputStream(file); InputStreamReader isr = new InputStreamReader(fis); @@ -296,4 +307,11 @@ public class RichPreview { void onError(Exception e); } + + // Pattern for recognizing a URL, based off RFC 3986 + public static final Pattern urlPattern = Pattern.compile( + "(?:^|[\\W])((ht|f)tp(s?):\\/\\/|www\\.)" + + "(([\\w\\-]+\\.){1,}?([\\w\\-.~]+\\/?)*" + + "[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*$~@!:/{};']*)", + Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); }
\ No newline at end of file |