forked from berserker/microblog
Add conversation model, <ostatus:conversation /> (#3016)
* Add <ostatus:conversation /> tag to Atom input/output Only uses ref attribute (not href) because href would be the alternate link that's always included also. Creates new conversation for every non-reply status. Carries over conversation for every reply. Keeps remote URIs verbatim, generates local URIs on the fly like the rest of them. * Fix conversation migration * More spec coverage for status before_create * Prevent n+1 query when generating Atom with the new conversations * Improve code style * Remove redundant local variablelocal
parent
b5a9c6b3d2
commit
5abdc77c80
11 changed files with 143 additions and 9 deletions
@ -0,0 +1,20 @@ |
||||
# frozen_string_literal: true |
||||
# == Schema Information |
||||
# |
||||
# Table name: conversations |
||||
# |
||||
# id :integer not null, primary key |
||||
# uri :string |
||||
# created_at :datetime not null |
||||
# updated_at :datetime not null |
||||
# |
||||
|
||||
class Conversation < ApplicationRecord |
||||
validates :uri, uniqueness: true |
||||
|
||||
has_many :statuses |
||||
|
||||
def local? |
||||
uri.nil? |
||||
end |
||||
end |
@ -0,0 +1,10 @@ |
||||
class CreateConversations < ActiveRecord::Migration[5.0] |
||||
def change |
||||
create_table :conversations, id: :bigserial do |t| |
||||
t.string :uri, null: true, default: nil |
||||
t.timestamps |
||||
end |
||||
|
||||
add_index :conversations, :uri, unique: true |
||||
end |
||||
end |
@ -0,0 +1,6 @@ |
||||
class AddConversationIdToStatuses < ActiveRecord::Migration[5.0] |
||||
def change |
||||
add_column :statuses, :conversation_id, :bigint, null: true, default: nil |
||||
add_index :statuses, :conversation_id |
||||
end |
||||
end |
@ -0,0 +1,2 @@ |
||||
Fabricator(:conversation) do |
||||
end |
@ -0,0 +1,13 @@ |
||||
require 'rails_helper' |
||||
|
||||
RSpec.describe Conversation, type: :model do |
||||
describe '#local?' do |
||||
it 'returns true when URI is nil' do |
||||
expect(Fabricate(:conversation).local?).to be true |
||||
end |
||||
|
||||
it 'returns false when URI is not nil' do |
||||
expect(Fabricate(:conversation, uri: 'abc').local?).to be false |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue