TO_REGEXP = /^to:\s+/i REPLY_REGEXP = /^inreplyto:\s+/i ATTACH_REGEXP = /^attach:\s+/i URL_REGEXP = %r{\Ahttps?://\S+\Z} MENTION_REGEXP = /\A@\w+@\S+\Z/ HASHTAG_REGEXP = /\A#\w+\Z/ # COMMENT_REGEXP = /^$/ next when TO_REGEXP line.sub(TO_REGEXP, '').split(/\s+/).each do |word| case word when 'public' to += ['https://www.w3.org/ns/activitystreams#Public', FOLLOWERS_URL] when MENTION_REGEXP to << actor(word) when URL_REGEXP to << word end end when REPLY_REGEXP inReplyTo = line.sub(REPLY_REGEXP, '') when ATTACH_REGEXP url, description = line.sub(ATTACH_REGEXP, '').split(/\s+/, 2) attachment << { 'type' => 'Document', 'mediaType' => media_type(url), 'url' => url, 'name' => description } else # create links # single quotes in html invalidate digest, reason unknown line.split(/\s+/).each do |word| word = word.gsub('

', '').gsub('

', '') case word when HASHTAG_REGEXP tag_url = File.join('https://social.pdp8.info', 'tags', word.sub('#', '')) tag << { 'type' => 'Hashtag', 'href' => tag_url, 'name' => word } when MENTION_REGEXP actor = actor(word) tag << { 'type' => 'Mention', 'href' => actor, 'name' => word } end end 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(' ')}" } object['inReplyTo'] = inReplyTo unless inReplyTo.empty? object['attachment'] = attachment unless attachment.empty? object['tag'] = tag unless tag.empty? # p to # jj object create_activity 'Create', object, to 200 end