Repository: bookwyrm-social/bookwyrm

Issue:
Images not displaying on mastodon
![Screen Shot 2020-03-27 at 10 44 07 AM](https://user-images.githubusercontent.com/1807695/77784542-ef536480-7017-11ea-8971-d1df91311f32.png)
the image loads when you click the link, and the alt text works


Discussion:

Resolving patch:
diff --git a/bookwyrm/connectors/bookwyrm_connector.py b/bookwyrm/connectors/bookwyrm_connector.py
--- a/bookwyrm/connectors/bookwyrm_connector.py
+++ b/bookwyrm/connectors/bookwyrm_connector.py
@@ -84,7 +84,7 @@ def get_cover_from_data(self, data):
         if not response.ok:
             response.raise_for_status()
 
-        image_name = str(uuid4()) + cover_url.split('.')[-1]
+        image_name = str(uuid4()) + '.' + cover_url.split('.')[-1]
         image_content = ContentFile(response.content)
         return [image_name, image_content]
 
diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py
--- a/bookwyrm/models/status.py
+++ b/bookwyrm/models/status.py
@@ -75,6 +75,16 @@ def ap_tag(self):
             ))
         return tags
 
+    @property
+    def ap_status_image(self):
+        ''' attach a book cover, if relevent '''
+        if hasattr(self, 'book'):
+            return self.book.ap_cover
+        if self.mention_books.first():
+            return self.mention_books.first().ap_cover
+        return None
+
+
     shared_mappings = [
         ActivityMapping('url', 'remote_id', lambda x: None),
         ActivityMapping('id', 'remote_id'),
@@ -100,6 +110,7 @@ def ap_tag(self):
     pure_activity_mappings = shared_mappings + [
         ActivityMapping('name', 'ap_pure_name'),
         ActivityMapping('content', 'ap_pure_content'),
+        ActivityMapping('attachment', 'ap_status_image'),
     ]
 
     activity_serializer = activitypub.Note
diff --git a/bookwyrm/views.py b/bookwyrm/views.py
--- a/bookwyrm/views.py
+++ b/bookwyrm/views.py
@@ -60,23 +60,7 @@ def home_tab(request, tab):
     except ValueError:
         page = 1
 
-    max_books = 5
-    book_count = 0
-    preset_shelves = ['reading', 'read', 'to-read']
-    suggested_books = []
-    for preset in preset_shelves:
-        limit = max_books - book_count
-        shelf = request.user.shelf_set.get(identifier=preset)
-
-        shelf_books = shelf.shelfbook_set.order_by(
-            '-updated_date'
-        ).all()[:limit]
-        shelf_preview = {
-            'name': shelf.name,
-            'books': [s.book for s in shelf_books]
-        }
-        suggested_books.append(shelf_preview)
-        book_count += len(shelf_preview['books'])
+    suggested_books = get_suggested_books(request.user)
 
     activities = get_activity_feed(request.user, tab)
 
@@ -100,6 +84,29 @@ def home_tab(request, tab):
     return TemplateResponse(request, 'feed.html', data)
 
 
+def get_suggested_books(user, max_books=5):
+    ''' helper to get a user's recent books '''
+    book_count = 0
+    preset_shelves = ['reading', 'read', 'to-read']
+    suggested_books = []
+    for preset in preset_shelves:
+        limit = max_books - book_count
+        shelf = user.shelf_set.get(identifier=preset)
+
+        shelf_books = shelf.shelfbook_set.order_by(
+            '-updated_date'
+        ).all()[:limit]
+        if not shelf_books:
+            continue
+        shelf_preview = {
+            'name': shelf.name,
+            'books': [s.book for s in shelf_books]
+        }
+        suggested_books.append(shelf_preview)
+        book_count += len(shelf_preview['books'])
+    return suggested_books
+
+
 def get_activity_feed(user, filter_level, model=models.Status):
     ''' get a filtered queryset of statuses '''
     # status updates for your follow network


Test patch: