summaryrefslogtreecommitdiff
path: root/create.rb
diff options
context:
space:
mode:
Diffstat (limited to 'create.rb')
-rw-r--r--create.rb47
1 files changed, 26 insertions, 21 deletions
diff --git a/create.rb b/create.rb
index 40bfbb8..371f8f8 100644
--- a/create.rb
+++ b/create.rb
@@ -1,5 +1,4 @@
TO_REGEXP = /^to:\s+/i
-CC_REGEXP = /^cc:\s+/i
REPLY_REGEXP = /^inreplyto:\s+/i
ATTACH_REGEXP = /^attach:\s+/i
URL_REGEXP = %r{\Ahttps?://\S+\Z}
@@ -23,11 +22,25 @@ post '/create' do
line.sub(TO_REGEXP, '').split(/\s+/).each do |word|
case word
when 'public'
- to += ['https://www.w3.org/ns/activitystreams#Public', FOLLOWERS_URL]
+ to << 'https://www.w3.org/ns/activitystreams#Public'
+ to << FOLLOWERS_URL
when MENTION_REGEXP
- to << actor(word)
+ href = actor(word)
+ m = {
+ 'type' => 'Mention',
+ 'href' => href,
+ 'name' => word
+ }
+ to << href unless to.include? href
+ tag << m unless tag.include? m
when URL_REGEXP
- to << word
+ m = {
+ 'type' => 'Mention',
+ 'href' => word,
+ 'name' => mention(word)
+ }
+ to << word unless to.include? word
+ tag << m unless tag.include? m
end
end
when REPLY_REGEXP
@@ -40,8 +53,8 @@ post '/create' do
'url' => url,
'name' => description
}
- when "\n"
- "<p>\n"
+ when ''
+ content << '<p>'
else # create links
content << line.split(/\s+/).collect do |word|
case word
@@ -55,36 +68,28 @@ post '/create' do
"<a href=\"#{tag_url}\">#{word}</a>"
when MENTION_REGEXP
actor = actor(word)
- tag << {
+ m = {
'type' => 'Mention',
'href' => actor,
'name' => word
}
- to << actor
+ tag << m unless tag.include? m
+ to << actor unless to.include? actor
"<a href=\"#{actor}\">#{word}</a>"
+ when URL_REGEXP
+ "<a href=\"#{word}\">#{word}</a>"
else
word
end
end.join(' ')
- # content << line
end
end
- # https://docs.joinmastodon.org/spec/activitypub/#Mention
- if to.size == 1 # mastodon DM
- m = {
- 'type' => 'Mention',
- 'href' => to[0],
- 'name' => mention(to[0])
- }
- tag << m unless tag.include? m
- end
-
object = {
'to' => to,
'type' => 'Note',
'attributedTo' => ACTOR,
- 'content' => "#{content.join(' ')}"
+ 'content' => "#{content.join('')}"
}
object['inReplyTo'] = inReplyTo unless inReplyTo.empty?
object['attachment'] = attachment unless attachment.empty?
@@ -92,7 +97,7 @@ post '/create' do
# p to
jj object
- # create_activity 'Create', object, to
+ create_activity 'Create', object, to
200
end