From 24bcc13e345768ea0e601d5b76a011a32493747e Mon Sep 17 00:00:00 2001
From: ialokim <ialokim@mailbox.org>
Date: Sun, 27 Aug 2023 21:48:07 +0200
Subject: [PATCH] show RSS icon for re-blogged posts from RSS feeds

---
 .../briar/desktop/blog/BlogPostView.kt        | 62 +++++++++++++++----
 .../briar/desktop/contact/ProfileCircle.kt    | 27 +++++++-
 2 files changed, 77 insertions(+), 12 deletions(-)

diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/BlogPostView.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/BlogPostView.kt
index ecbaf9658d..ca402d880a 100644
--- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/BlogPostView.kt
+++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/blog/BlogPostView.kt
@@ -62,6 +62,7 @@ import org.briarproject.briar.api.blog.MessageType
 import org.briarproject.briar.api.identity.AuthorInfo
 import org.briarproject.briar.api.identity.AuthorInfo.Status.OURSELVES
 import org.briarproject.briar.desktop.contact.ProfileCircle
+import org.briarproject.briar.desktop.contact.ProfileCircleRss
 import org.briarproject.briar.desktop.theme.Blue500
 import org.briarproject.briar.desktop.ui.AuthorView
 import org.briarproject.briar.desktop.ui.HorizontalDivider
@@ -87,14 +88,14 @@ fun main() = preview {
         )
         BlogPostView(post, {}, {})
         val commentPost = getRandomBlogCommentItem(
-            post = post,
+            parent = post,
             comment = "This is a comment on that first blog post.\n\nIt has two lines as well.",
             time = System.currentTimeMillis() - 500_000
         )
         BlogPostView(commentPost, {}, {})
         BlogPostView(
             getRandomBlogCommentItem(
-                post = commentPost,
+                parent = commentPost,
                 comment = "This is a second comment on that first blog post. It has only one line, but a long one.",
                 time = System.currentTimeMillis()
             ),
@@ -175,11 +176,19 @@ private fun BlogPostViewHeader(
             if (item is BlogCommentItem) {
                 val postHeader = item.postHeader
                 // This isn't clickable, because item.type is WRAPPED_POST, so not easy to get the GroupId of the blog
-                AuthorView(
-                    author = postHeader.author,
-                    authorInfo = postHeader.authorInfo,
-                    timestamp = postHeader.timestamp,
-                )
+                if (postHeader.isRssFeed) {
+                    // todo: currently only re-blogged RSS feeds are supported
+                    RssAuthorView(
+                        name = postHeader.author.name,
+                        timestamp = postHeader.timestamp,
+                    )
+                } else {
+                    AuthorView(
+                        author = postHeader.author,
+                        authorInfo = postHeader.authorInfo,
+                        timestamp = postHeader.timestamp,
+                    )
+                }
             }
         }
         if (onItemRepeat != null) IconButton(onClick = { onItemRepeat(item) }) {
@@ -251,6 +260,37 @@ private fun RepeatAuthorView(
     }
 }
 
+@Composable
+private fun RssAuthorView(
+    name: String,
+    timestamp: Long,
+) {
+    Row(
+        horizontalArrangement = spacedBy(8.dp),
+        verticalAlignment = CenterVertically,
+    ) {
+        Row(
+            modifier = Modifier.weight(1f),
+            horizontalArrangement = spacedBy(8.dp),
+            verticalAlignment = CenterVertically,
+        ) {
+            ProfileCircleRss(27.dp)
+            Text(
+                modifier = Modifier.weight(1f, fill = false),
+                text = name,
+                maxLines = 1,
+                overflow = TextOverflow.Ellipsis,
+            )
+        }
+        Text(
+            text = getFormattedTimestamp(timestamp),
+            textAlign = TextAlign.End,
+            style = MaterialTheme.typography.caption,
+            maxLines = 1,
+        )
+    }
+}
+
 internal fun getRandomBlogPostItem(text: String, time: Long) = BlogPostItem(
     header = BlogPostHeader(
         MessageType.POST,
@@ -284,12 +324,12 @@ private fun BlogCommentView(header: BlogCommentHeader, modifier: Modifier = Modi
     }
 }
 
-internal fun getRandomBlogCommentItem(post: BlogPost, comment: String?, time: Long) = BlogCommentItem(
+internal fun getRandomBlogCommentItem(parent: BlogPost, comment: String?, time: Long) = BlogCommentItem(
     header = BlogCommentHeader(
         MessageType.COMMENT,
         GroupId(getRandomId()),
         comment,
-        if (post is BlogCommentItem) post.header else post.postHeader,
+        parent.header,
         MessageId(getRandomId()),
         time,
         System.currentTimeMillis(),
@@ -297,8 +337,8 @@ internal fun getRandomBlogCommentItem(post: BlogPost, comment: String?, time: Lo
         AuthorInfo(AuthorInfo.Status.values().filter { it != AuthorInfo.Status.NONE }.random()),
         Random.nextBoolean(),
     ),
-    postHeader = post.postHeader,
-    text = comment,
+    postHeader = parent.postHeader,
+    text = parent.text,
 )
 
 internal fun getRandomBlogPost(text: String, time: Long): BlogPost {
diff --git a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/contact/ProfileCircle.kt b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/contact/ProfileCircle.kt
index 13732ba0cb..7c8233a993 100644
--- a/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/contact/ProfileCircle.kt
+++ b/briar-desktop/src/main/kotlin/org/briarproject/briar/desktop/contact/ProfileCircle.kt
@@ -1,6 +1,6 @@
 /*
  * Briar Desktop
- * Copyright (C) 2021-2022 The Briar Project
+ * Copyright (C) 2021-2023 The Briar Project
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
@@ -20,15 +20,20 @@ package org.briarproject.briar.desktop.contact
 
 import androidx.compose.foundation.Canvas
 import androidx.compose.foundation.Image
+import androidx.compose.foundation.background
 import androidx.compose.foundation.border
 import androidx.compose.foundation.layout.Spacer
 import androidx.compose.foundation.layout.size
 import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.material.Icon
 import androidx.compose.material.MaterialTheme
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.RssFeed
 import androidx.compose.runtime.Composable
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.draw.clip
 import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.graphics.ImageBitmap
 import androidx.compose.ui.layout.ContentScale
 import androidx.compose.ui.unit.Dp
@@ -49,6 +54,8 @@ fun main() = preview {
     ProfileCircle(90.dp, bytes)
 
     ProfileCircle(90.dp)
+
+    ProfileCircleRss(90.dp)
 }
 
 /**
@@ -131,3 +138,21 @@ fun ProfileCircle(size: Dp, modifier: Modifier = Modifier) {
         drawLine(color, Offset(center, center), Offset(size * 0.7f, size * 0.7f), width)
     }
 }
+
+/**
+ * Display an RSS avatar for RSS feeds.
+ *
+ * @param size the size of the circle.
+ */
+@Composable
+fun ProfileCircleRss(size: Dp) {
+    val modifier = Modifier.size(size).clip(CircleShape)
+        .border(1.dp, MaterialTheme.colors.outline, CircleShape)
+        .background(Color(0xfffc9403))
+    Icon(
+        imageVector = Icons.Default.RssFeed,
+        contentDescription = null,
+        tint = Color.White,
+        modifier = modifier,
+    )
+}
-- 
GitLab