mentions now render client side, wow
This commit is contained in:
parent
b13e72bc00
commit
daba42c857
4 changed files with 68 additions and 5 deletions
|
|
@ -15,6 +15,9 @@ class Person < ActiveRecord::Base
|
||||||
api_accessible :backbone do |t|
|
api_accessible :backbone do |t|
|
||||||
t.add :id
|
t.add :id
|
||||||
t.add :name
|
t.add :name
|
||||||
|
t.add lambda { |person|
|
||||||
|
person.diaspora_handle
|
||||||
|
}, :as => :diaspora_id
|
||||||
t.add lambda { |person|
|
t.add lambda { |person|
|
||||||
{:small => person.profile.image_url(:small),
|
{:small => person.profile.image_url(:small),
|
||||||
:medium => person.profile.image_url(:medium),
|
:medium => person.profile.image_url(:medium),
|
||||||
|
|
@ -71,7 +74,7 @@ class Person < ActiveRecord::Base
|
||||||
|
|
||||||
scope :profile_tagged_with, lambda{|tag_name| joins(:profile => :tags).where(:profile => {:tags => {:name => tag_name}}).where('profiles.searchable IS TRUE') }
|
scope :profile_tagged_with, lambda{|tag_name| joins(:profile => :tags).where(:profile => {:tags => {:name => tag_name}}).where('profiles.searchable IS TRUE') }
|
||||||
|
|
||||||
scope :who_have_reshared_a_users_posts, lambda{|user|
|
scope :who_have_reshared_a_users_posts, lambda{|user|
|
||||||
joins(:posts).where(:posts => {:root_guid => StatusMessage.guids_for_author(user.person), :type => 'Reshare'} )
|
joins(:posts).where(:posts => {:root_guid => StatusMessage.guids_for_author(user.person), :type => 'Reshare'} )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -286,7 +289,7 @@ class Person < ActiveRecord::Base
|
||||||
def self.url_batch_update(people, url)
|
def self.url_batch_update(people, url)
|
||||||
people.each do |person|
|
people.each do |person|
|
||||||
person.update_url(url)
|
person.update_url(url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# @param person [Person]
|
# @param person [Person]
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ class Post < ActiveRecord::Base
|
||||||
t.add :root
|
t.add :root
|
||||||
t.add :o_embed_cache
|
t.add :o_embed_cache
|
||||||
t.add :user_like
|
t.add :user_like
|
||||||
|
t.add :mentioned_people
|
||||||
t.add lambda { |post|
|
t.add lambda { |post|
|
||||||
if post.photos_count > 0
|
if post.photos_count > 0
|
||||||
post.photos
|
post.photos
|
||||||
|
|
@ -65,6 +66,10 @@ class Post < ActiveRecord::Base
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mentioned_people
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
# gives the last three comments on the post
|
# gives the last three comments on the post
|
||||||
def last_three_comments
|
def last_three_comments
|
||||||
return if self.comments_count == 0
|
return if self.comments_count == 0
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,44 @@
|
||||||
(function(){
|
(function(){
|
||||||
var postContentView = app.views.StreamObject.extend({
|
var postContentView = app.views.StreamObject.extend({
|
||||||
presenter : function(){
|
presenter : function(){
|
||||||
|
var model = this.model
|
||||||
return _.extend(this.defaultPresenter(), {
|
return _.extend(this.defaultPresenter(), {
|
||||||
text : metafyText(this.model.get("text"))
|
text : metafyText(model.get("text"))
|
||||||
})
|
})
|
||||||
|
|
||||||
function metafyText(text) {
|
function metafyText(text) {
|
||||||
//we want it to return at least a <p> from markdown
|
//we want it to return at least a <p> from markdown
|
||||||
text = text || ""
|
text = text || ""
|
||||||
return hashtagify(markdown.toHTML(text) || text)
|
return mentionify(
|
||||||
|
hashtagify(
|
||||||
|
markdownify(text)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function markdownify(text){
|
||||||
|
//markdown returns falsy when it performs no substitutions, apparently...
|
||||||
|
return markdown.toHTML(text) || text
|
||||||
}
|
}
|
||||||
|
|
||||||
function hashtagify(text){
|
function hashtagify(text){
|
||||||
return text.replace(/(#([\u0080-\uFFFF|\w|-]+|<3))/g, function(tagText) {
|
var utf8WordCharcters =/(#([\u0080-\uFFFF|\w|-]+|<3))/g
|
||||||
|
return text.replace(utf8WordCharcters, function(tagText) {
|
||||||
return "<a href='/tags/" + tagText.substring(1) + "' class='tag'>" + tagText + "</a>"
|
return "<a href='/tags/" + tagText.substring(1) + "' class='tag'>" + tagText + "</a>"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mentionify(text) {
|
||||||
|
var mentionRegex = /@\{([^;]+); ([^\}]+)\}/g
|
||||||
|
return text.replace(mentionRegex, function(mentionText, fullName, diasporaId) {
|
||||||
|
var personId = _.find(model.get("mentioned_people"), function(person){
|
||||||
|
return person.diaspora_id == diasporaId
|
||||||
|
}).id
|
||||||
|
|
||||||
|
return "<a href='/people/" + personId + "' class='mention'>" + fullName + "</a>"
|
||||||
|
})
|
||||||
|
return text
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,38 @@ describe("app.views.Post", function(){
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
context("changes mention markup to links", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
this.alice = factory.author({
|
||||||
|
name : "Alice Smith",
|
||||||
|
diaspora_id : "alice@example.com",
|
||||||
|
id : "555"
|
||||||
|
})
|
||||||
|
|
||||||
|
this.bob = factory.author({
|
||||||
|
name : "Bob Grimm",
|
||||||
|
diaspora_id : "bob@example.com",
|
||||||
|
id : "666"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("links to the mentioned person's page", function(){
|
||||||
|
this.statusMessage.set({mentioned_people : [this.alice]})
|
||||||
|
this.statusMessage.set({text: "sup, @{Alice Smith; alice@example.com}?"})
|
||||||
|
|
||||||
|
var view = new app.views.Post({model : this.statusMessage}).render();
|
||||||
|
expect(view.$("a:contains('Alice Smith')").attr('href')).toBe('/people/555')
|
||||||
|
})
|
||||||
|
|
||||||
|
it("matches all mentions", function(){
|
||||||
|
this.statusMessage.set({mentioned_people : [this.alice, this.bob]})
|
||||||
|
this.statusMessage.set({text: "hey there @{Alice Smith; alice@example.com} and @{Bob Grimm; bob@example.com}"})
|
||||||
|
|
||||||
|
var view = new app.views.Post({model : this.statusMessage}).render();
|
||||||
|
expect(view.$("a.mention").length).toBe(2)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
context("user not signed in", function(){
|
context("user not signed in", function(){
|
||||||
it("does not provide a Feedback view", function(){
|
it("does not provide a Feedback view", function(){
|
||||||
window.current_user = app.user(null);
|
window.current_user = app.user(null);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue