视频直播开启时发消息

dev_video
cxt 5 years ago
parent 5bd0d18607
commit 66d28a896a

@ -16,8 +16,19 @@ class LiveLinksController < ApplicationController
end
def update
render_forbidden("无权限操作") unless current_user.id == current_live.user_id || current_user.admin?
current_live.update!(on_status: params[:on_status])
tip_exception(403, "无权限操作") unless current_user.id == current_live.user_id || current_user.admin?
tip_exception("请勿重复开启") if current_live.on_status && params[:on_status].to_i == 1
ActiveRecord::Base.transaction do
current_live.update!(on_status: params[:on_status])
# 开启时发送消息,关闭直播时删除对应的消息
if params[:on_status].to_i == 1
LivePublishJob.perform_later(current_live.id)
else
current_live.tidings.destroy_all
end
end
render_ok
end

@ -321,6 +321,10 @@ module TidingDecorator
I18n.t(locale_format(parent_container_type)) % container&.exercise_name
end
def live_link_content
I18n.t(locale_format) % container&.user.try(:show_real_name)
end
def student_graduation_topic_content
I18n.t(locale_format) % container&.graduation_topic.try(:name)
end

@ -0,0 +1,27 @@
# 直播开启的消息通知
class LivePublishJob < ApplicationJob
queue_as :notify
def perform(live_id)
live = LiveLink.find_by(id: live_id)
return if live.blank? || live.course.blank?
course = live.course
attrs = %i[
user_id trigger_user_id container_id container_type parent_container_id parent_container_type
belong_container_id belong_container_type viewed tiding_type created_at updated_at
]
same_attrs = {
trigger_user_id: live.user_id, container_id: live.id, container_type: 'LiveLink',
parent_container_id: live.id, parent_container_type: 'LiveLink',
belong_container_id: live.course_id, belong_container_type: 'Course',
viewed: 0, tiding_type: 'LiveLink'
}
Tiding.bulk_insert(*attrs) do |worker|
course.students.pluck(:user_id).each do |user_id|
worker.add same_attrs.merge(user_id: user_id)
end
end
end
end

@ -2,6 +2,8 @@ class LiveLink < ApplicationRecord
belongs_to :course
belongs_to :user
has_many :tidings, as: :container, dependent: :destroy
validates :url, presence: true
validates :description, length: { maximum: 100, too_long: "不能超过100个字符" }

@ -238,3 +238,4 @@
2_end: "你提交的发布视频申请:%s审核未通过<br/><span>原因:%{reason}</span>"
PublicCourseStart_end: "你报名参与的开放课程:%s将于%s正式开课"
SubjectStartCourse_end: "您创建的开放课程:%s 已达到开课人数要求。您可以在24小时内自主开设新一期课程。如果超过24小时未开课平台将自动开课并复制您上一期的课程内容。"
LiveLink_end: "%s老师正在直播中"

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe LivePublishJob, type: :job do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save