changes for sockets

This commit is contained in:
Harry Bomrah 2015-10-17 03:07:52 +08:00
parent 9636c57aa8
commit a87df693bf
3 changed files with 35 additions and 22 deletions

View File

@ -204,6 +204,12 @@ class Admin::TicketsController < OrbitAdminController
rescue e
end
end
url = "/admin/tickets/#{tq.ticket.id.to_s}#response_#{response.id.to_s}"
Fiber.new{
params[:user_tags].each do |user_id|
WebsocketRails["tag_notifications_for_#{user_id}".to_sym].trigger(:new_notification_recieved, {"ticket_link" => "<a href='#{url}'>#{tq.ticket.subject}</a>", "total_ticket_count" => Ticket.get_ticket_unread_count_for_user(user_id), "blink_message" => "#{current_user.name} tagged you!"})
end
}.resume
end
render :partial => "response", :object => response
else
@ -216,7 +222,7 @@ class Admin::TicketsController < OrbitAdminController
if !response.nil?
response.read_by << current_user.id.to_s if !response.read_by.include?(current_user.id.to_s)
response.save
data = {"success" => true, "user_id" => current_user.id.to_s}
data = {"success" => true, "user_id" => current_user.id.to_s, "total_ticket_count" => Ticket.get_ticket_unread_count_for_user(current_user)}
else
data = {"success" => false}
end

View File

@ -47,7 +47,11 @@ class Ticket
end
def self.get_ticket_unread_count_for_user(user)
if user.instance_of?(User)
tqrs = TicketQueryResponse.where(:user_tags.in => [user.id.to_s], :read_by.nin => [user.id.to_s])
elsif user.instance_of?(String)
tqrs = TicketQueryResponse.where(:user_tags.in => [user], :read_by.nin => [user])
end
unread_tickets = []
tqrs.each do |tqr|
unread_tickets << tqr.ticket_query.ticket if !tqr.ticket_query.nil? && !tqr.ticket_query.ticket.nil? && tqr.ticket_query.ticket.status != "closed"

View File

@ -261,7 +261,7 @@ $(document).ready(function(){
},
placeholder: "Tag Members"
});
readbyFunction();
})
$(".reopen-back-btn").on("click",function(){
for (instance in CKEDITOR.instances) {
@ -363,10 +363,7 @@ $(document).ready(function(){
}
})
var timer = null;
$(document).on("scroll",function(){
clearTimeout(timer);
timer = setTimeout(function(){
var readbyFunction = function(){
var responses_seen = $("div[data-user-tags*=" + user_id + "]:in-viewport");
$.each(responses_seen,function(){
var el = $(this),
@ -380,11 +377,17 @@ $(document).ready(function(){
}).done(function(data){
if(data.success){
avatar.addClass("read");
notificationManager.setNotificationNumber(data.total_ticket_count);
}
})
}
})
},1000);
}
var timer = null;
$(document).on("scroll",function(){
clearTimeout(timer);
timer = setTimeout(readbyFunction,1000);
})
})();
</script>