mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 13:14:29 +08:00
refactor [fixes SCI-825]
This commit is contained in:
parent
439cd0cd89
commit
9bb1bb3f9b
2 changed files with 7 additions and 4 deletions
|
@ -55,6 +55,8 @@ module StepsActions
|
|||
checklists
|
||||
end
|
||||
|
||||
# used for step update action it traverse through the input params and
|
||||
# generates notifications
|
||||
def update_annotation_notification(step,
|
||||
old_description,
|
||||
new_checklists,
|
||||
|
@ -139,6 +141,7 @@ module StepsActions
|
|||
))
|
||||
end
|
||||
|
||||
# temporary data containers
|
||||
PreviouseChecklistItem = Struct.new(:id, :text)
|
||||
PreviouseChecklist = Struct.new(:id, :name, :items) do
|
||||
def initialize(id, name, items = [])
|
||||
|
|
|
@ -64,24 +64,24 @@ module ApplicationHelper
|
|||
new_text = options.fetch(:new_text) { :new_text_must_be_present }
|
||||
old_text = options[:old_text] || ''
|
||||
sa_user = /\[\@(.*?)~([0-9a-zA-Z]+)\]/
|
||||
|
||||
# fetch user ids from the previouse text
|
||||
old_user_ids = []
|
||||
old_text.gsub(sa_user) do |el|
|
||||
match = el.match(sa_user)
|
||||
old_user_ids << match[2].base62_decode
|
||||
end
|
||||
|
||||
# fetch user ids from the new text
|
||||
new_user_ids = []
|
||||
new_text.gsub(sa_user) do |el|
|
||||
match = el.match(sa_user)
|
||||
new_user_ids << match[2].base62_decode
|
||||
end
|
||||
|
||||
# check if the user has been already mentioned
|
||||
annotated_users = []
|
||||
new_user_ids.each do |el|
|
||||
annotated_users << el unless old_user_ids.include?(el)
|
||||
end
|
||||
|
||||
# restrict the list of ids and generate notification
|
||||
annotated_users.uniq.each do |user_id|
|
||||
target_user = User.find_by_id(user_id)
|
||||
next unless target_user
|
||||
|
|
Loading…
Add table
Reference in a new issue