Quick Messages Plugin

@Rodelio_Lagahit @Roxelle Ok this issue should be fixed now. You can use Quick Messages and Topic List Previews together safely now.

What was happening was that both Quick Messages and Topic List Previews were overriding the excerpt and include_excerpt methods used in the Listable Topic (or Topic List Item) serializer. So I just moved Quick Messages over to a new method message_excerpt so the two would not conflict.

def message_excerpt
  if object.archetype == Archetype.private_message
     cooked = Post.where(topic_id: object.id, post_number: object.highest_post_number).pluck('cooked')
     excerpt = PrettyText.excerpt(cooked[0], 200, keep_emoji_images: true)
     excerpt.gsub!(/(\[image\])/, "<i class='fa fa-picture-o'></i>") if excerpt
     excerpt
  else
     return false
  end
end

def include_message_excerpt?
  !!message_excerpt
end

https://github.com/angusmcleod/discourse-quick-messages/commit/2a71ff7c83f253edeea1d43224b1ef6c779cf836

Btw, notice that, like in Topic List Previews, I’m stripping out the [image] text which acts as a placeholder for an image in a excerpt.

excerpt.gsub!(/(\[image\])/, "<i class='fa fa-picture-o'></i>") if excerpt

This was originally a request for Topic List Previews, and I also think that having ‘[image]’ placeholders in excerpts looks a little…unpolished. I’m experimenting here with putting the Font Awesome icon fa-picture-o in its place so that there is still a placeholder for images in excerpts. If message only contains an image some kind of placeholder is necessary, otherwise the excerpt will show up blank. Any feedback or ideas on that are welcome.

6 Likes