summaryrefslogtreecommitdiff
path: root/send.rb
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2023-07-24 02:46:05 +0200
committerpdp8 <pdp8@pdp8.info>2023-07-24 02:46:05 +0200
commita509c55faca368709044133199f71fb862b1e605 (patch)
tree9c53d06a4f26e6ccf8635278b8eb56c4a62403f3 /send.rb
parent3c38f81b8a145778d4329c6be4c91baa00ca0d48 (diff)
html output removed
Diffstat (limited to 'send.rb')
-rw-r--r--send.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/send.rb b/send.rb
new file mode 100644
index 0000000..91d3e9b
--- /dev/null
+++ b/send.rb
@@ -0,0 +1,79 @@
+post '/' do # TODO
+ protected!
+
+ recipients = public
+ recipients << params[:to]
+
+ # content = []
+ tag = []
+ params[:content].lines.each do |line|
+ # line.chomp!
+ tags = line.split(/\s+/).grep(/^#\w+$/)
+ tags.each do |name|
+ tag_url = File.join(TAGS[:url], name.sub('#', ''))
+ tag << {
+ 'type' => 'Hashtag',
+ 'href' => tag_url,
+ 'name' => name
+ }
+ end
+
+ mentions = line.split(/\s+/).grep(/^@\w+@\S+$/)
+ mentions.each do |mention|
+ actor = actor(mention)
+ tag << {
+ 'type' => 'Mention',
+ 'href' => actor,
+ 'name' => mention
+ }
+ end
+ # content << line
+ end
+
+ attachment = []
+ extensions = {
+ image: %w[jpeg png],
+ audio: %w[flac wav mp3 ogg],
+ video: %w[mp4 webm]
+ }
+ params[:media].each do |_media|
+ ext = File.extname(line).sub('.', '')
+ media_type = extensions.select { |_k, v| v.include? ext }.keys[0].to_s + '/' + ext
+ attachment << {
+ 'type' => 'Document',
+ 'mediaType' => media_type,
+ 'url' => line
+ }
+ end
+
+ object = {
+ 'type' => 'Note',
+ 'attributedTo' => ACTOR,
+ 'inReplyTo' => params[:inReplyTo],
+ 'content' => "<p>\n#{content.join("\n<br>")}\n</p>",
+ 'attachment' => attachment,
+ 'tag' => tag,
+ 'to' => recipients
+ }
+
+ activity = outbox 'Create', object, recipients, true
+ activity['object']['tag'].each do |tag|
+ next unless tag['type'] == 'Hashtag'
+
+ tag_path = File.join(TAGS_DIR, tag['name'].sub('#', '')) + '.json'
+ next if File.exist? tag_path
+
+ File.open(tag_path, 'w+') do |f|
+ tag_collection = {
+ '@context' => 'https://www.w3.org/ns/activitystreams',
+ 'id' => tag['href'],
+ 'type' => 'OrderedCollection',
+ 'totalItems' => 0,
+ 'orderedItems' => []
+ }
+ f.puts tag_collection.to_json
+ end
+ # update_collection tag_path, activity['object']['id']
+ end
+ redirect(params['anchor'] || '/inbox')
+end