Add configurable default room bookmarks for new users
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
83e418cdee
commit
705bd63b42
26
app/jobs/xmpp_set_default_bookmarks_job.rb
Normal file
26
app/jobs/xmpp_set_default_bookmarks_job.rb
Normal file
@ -0,0 +1,26 @@
|
||||
class XmppSetDefaultBookmarksJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(user)
|
||||
return unless Setting.xmpp_default_rooms.any?
|
||||
@user = user
|
||||
ejabberd = EjabberdApiClient.new
|
||||
ejabberd.private_set user, storage_content
|
||||
end
|
||||
|
||||
def storage_content
|
||||
bookmarks = ""
|
||||
Setting.xmpp_default_rooms.each do |r|
|
||||
bookmarks << conference_element(
|
||||
jid: r[/<(.+)>/, 1], name: r[/^(.+)\s/, 1], nick: @user.cn,
|
||||
autojoin: Setting.xmpp_autojoin_default_rooms
|
||||
)
|
||||
end
|
||||
|
||||
"<storage xmlns='storage:bookmarks'>#{bookmarks}</storage>"
|
||||
end
|
||||
|
||||
def conference_element(jid:, name:, autojoin: false, nick:)
|
||||
"<conference jid='#{jid}' name='#{name}' autojoin='#{autojoin.to_s}'><nick>#{nick}</nick></conference>"
|
||||
end
|
||||
end
|
@ -17,6 +17,13 @@ class Setting < RailsSettings::Base
|
||||
account accounts donations mail webmaster support
|
||||
]
|
||||
|
||||
#
|
||||
# XMPP
|
||||
#
|
||||
|
||||
field :xmpp_default_rooms, type: :array, default: []
|
||||
field :xmpp_autojoin_default_rooms, type: :boolean, default: false
|
||||
|
||||
#
|
||||
# Sentry
|
||||
#
|
||||
|
@ -10,7 +10,7 @@ class EjabberdApiClient
|
||||
if res.status != 200
|
||||
Rails.logger.error "[ejabberd] API request failed:"
|
||||
Rails.logger.error res.body
|
||||
#TODO add some kind of exception tracking/notifications
|
||||
#TODO Send custom event to Sentry
|
||||
end
|
||||
end
|
||||
|
||||
@ -21,4 +21,9 @@ class EjabberdApiClient
|
||||
def send_message(payload)
|
||||
post "send_message", payload
|
||||
end
|
||||
|
||||
def private_set(user, content)
|
||||
payload = { user: user.cn, host: user.ou, element: content }
|
||||
post "private_set", payload
|
||||
end
|
||||
end
|
||||
|
@ -7,24 +7,43 @@
|
||||
title: "Enable ejabberd integration",
|
||||
description: "ejabberd configuration present and features enabled"
|
||||
) %>
|
||||
<% if Setting.ejabberd_enabled? %>
|
||||
<%= render FormElements::FieldsetComponent.new(title: "API URL") do %>
|
||||
<%= f.text_field :ejabberd_api_url,
|
||||
value: Setting.ejabberd_api_url,
|
||||
class: "w-full", disabled: true %>
|
||||
<% end %>
|
||||
<%= render FormElements::FieldsetComponent.new(title: "Admin URL") do %>
|
||||
<%= f.text_field :ejabberd_admin_url,
|
||||
value: Setting.ejabberd_admin_url,
|
||||
class: "w-full", disabled: true %>
|
||||
<% end %>
|
||||
<%= render FormElements::FieldsetComponent.new(
|
||||
title: "Contact roster name",
|
||||
description: "Used when exchanging contacts after signup from invitation"
|
||||
) do %>
|
||||
<%= f.text_field :ejabberd_buddy_roster,
|
||||
value: Setting.ejabberd_buddy_roster,
|
||||
class: "w-full" %>
|
||||
<% end %>
|
||||
<% if Setting.ejabberd_enabled? %>
|
||||
<%= render FormElements::FieldsetComponent.new(title: "API URL") do %>
|
||||
<%= f.text_field :ejabberd_api_url,
|
||||
value: Setting.ejabberd_api_url,
|
||||
class: "w-full", disabled: true %>
|
||||
<% end %>
|
||||
<%= render FormElements::FieldsetComponent.new(title: "Admin URL") do %>
|
||||
<%= f.text_field :ejabberd_admin_url,
|
||||
value: Setting.ejabberd_admin_url,
|
||||
class: "w-full", disabled: true %>
|
||||
<% end %>
|
||||
</ul>
|
||||
<h3 class="mt-8">User default settings</h3>
|
||||
<ul role="list">
|
||||
<%= render FormElements::FieldsetComponent.new(
|
||||
title: "Default rooms",
|
||||
description: "Add these default rooms to new users' bookmarks"
|
||||
) do %>
|
||||
<%= f.text_area :xmpp_default_rooms,
|
||||
value: Setting.xmpp_default_rooms.join("\n"),
|
||||
placeholder: "Welcome <welcome@kosmos.chat>\nKosmos <kosmos@kosmos.chat>",
|
||||
class: "h-24 w-full" %>
|
||||
<% end %>
|
||||
<%= render FormElements::FieldsetToggleComponent.new(
|
||||
form: f,
|
||||
attribute: :xmpp_autojoin_default_rooms,
|
||||
enabled: Setting.xmpp_autojoin_default_rooms?,
|
||||
title: "Auto-join default rooms",
|
||||
description: "Automatically join above default rooms in chat clients"
|
||||
) %>
|
||||
<%= render FormElements::FieldsetComponent.new(
|
||||
title: "Contact roster name",
|
||||
description: "Used when exchanging contacts after signup from invitation"
|
||||
) do %>
|
||||
<%= f.text_field :ejabberd_buddy_roster,
|
||||
value: Setting.ejabberd_buddy_roster,
|
||||
class: "w-full" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
Loading…
x
Reference in New Issue
Block a user