mirror of
https://github.com/kikobar/mastodon.git
synced 2024-12-25 07:14:21 +00:00
Add service for posting statuses (normal and replies), mention regex to
fetch webfinger information of mentioned accounts
This commit is contained in:
parent
8da8387afe
commit
79609d6270
|
@ -14,6 +14,8 @@ class Account < ActiveRecord::Base
|
||||||
has_many :following, through: :active_relationships, source: :target_account
|
has_many :following, through: :active_relationships, source: :target_account
|
||||||
has_many :followers, through: :passive_relationships, source: :account
|
has_many :followers, through: :passive_relationships, source: :account
|
||||||
|
|
||||||
|
MENTION_RE = /(?:^|\W)@([a-z0-9_]+(?:@[a-z0-9\.\-]+)?)/i
|
||||||
|
|
||||||
def follow!(other_account)
|
def follow!(other_account)
|
||||||
self.active_relationships.first_or_create!(target_account: other_account)
|
self.active_relationships.first_or_create!(target_account: other_account)
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,6 +51,17 @@ class Status < ActiveRecord::Base
|
||||||
m << thread.account if reply?
|
m << thread.account if reply?
|
||||||
m << reblog.account if reblog?
|
m << reblog.account if reblog?
|
||||||
|
|
||||||
|
unless reblog?
|
||||||
|
self.text.scan(Account::MENTION_RE).each do |match|
|
||||||
|
uri = match.first
|
||||||
|
username = uri.split('@').first
|
||||||
|
domain = uri.split('@').size == 2 ? uri.split('@').last : nil
|
||||||
|
account = Account.find_by(username: username, domain: domain)
|
||||||
|
|
||||||
|
m << account unless account.nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
m
|
m
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
19
app/services/post_status_service.rb
Normal file
19
app/services/post_status_service.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
class PostStatusService < BaseService
|
||||||
|
def call(account, text, in_reply_to = nil)
|
||||||
|
status = account.statuses.create!(text: text, thread: in_reply_to)
|
||||||
|
|
||||||
|
status.text.scan(Account::MENTION_RE).each do |match|
|
||||||
|
next if match.first.split('@').size == 1
|
||||||
|
username, domain = match.first.split('@')
|
||||||
|
local_account = Account.find_by(username: username, domain: domain)
|
||||||
|
next unless local_account.nil?
|
||||||
|
follow_remote_account_service.("acct:#{match.first}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def follow_remote_account_service
|
||||||
|
@follow_remote_account_service ||= FollowRemoteAccountService.new
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue