Skip to content
This repository has been archived by the owner on Nov 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #220 from mallowlabs/id/220
Browse files Browse the repository at this point in the history
add quoted text push
  • Loading branch information
mzp committed May 18, 2015
2 parents 4dcce2e + ec97c99 commit 5c21880
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
9 changes: 8 additions & 1 deletion app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ def to_hash
}
end

def html_body(room)
def html_body(room = nil)
AsakusaSatellite::Filter.process self, room || self.room
end

def inner_text
doc = REXML::Document.new(html_body || '')
doc.delete_element('//style')
doc.delete_element('//script')
REXML::XPath.match(doc, "//text()").join(" ").strip
end

def prev(offset)
return [] if offset <= 0
Message.where(:room_id => self.room_id, :_id.lt => self._id).order_by(:_id.desc).limit(offset).to_a.reverse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ def unregister(device); end
def send_message(device_tokens, room, message); end

def alert(message)
not_attached = message.attachments.empty?
body = not_attached ? message.body : message.attachments[0].filename
body = ''
body = message.attachments[0].filename unless message.attachments.empty?
body = message.inner_text if body.blank?
body = message.body if body.blank?
strip("#{message.user.name} / #{body}", PAYLOAD_SIZE_LIMIT)
end

Expand Down
27 changes: 27 additions & 0 deletions spec/models/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,33 @@
end
end

describe "inner_text" do
context 'simple' do
before {
@message = Message.new
allow(@message).to receive(:html_body).and_return('<div class="body">text</div>')
}
subject { @message }
its(:inner_text) { should == "text" }
end
context 'not html' do
before {
@message = Message.new
allow(@message).to receive(:html_body).and_return('text')
}
subject { @message }
its(:inner_text) { should == "text" }
end
context 'html with style' do
before {
@message = Message.new
allow(@message).to receive(:html_body).and_return('<div><style>html{color:red;}</style> <div>text</div></div>')
}
subject { @message }
its(:inner_text) { should == "text" }
end
end

describe "添付ファイル" do
before {
expect(Setting).to receive(:[]).with(:attachment_max_size).and_return("1")
Expand Down

0 comments on commit 5c21880

Please sign in to comment.