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 rescue e
end end
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 end
render :partial => "response", :object => response render :partial => "response", :object => response
else else
@ -216,7 +222,7 @@ class Admin::TicketsController < OrbitAdminController
if !response.nil? if !response.nil?
response.read_by << current_user.id.to_s if !response.read_by.include?(current_user.id.to_s) response.read_by << current_user.id.to_s if !response.read_by.include?(current_user.id.to_s)
response.save 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 else
data = {"success" => false} data = {"success" => false}
end end

View File

@ -47,7 +47,11 @@ class Ticket
end end
def self.get_ticket_unread_count_for_user(user) def self.get_ticket_unread_count_for_user(user)
tqrs = TicketQueryResponse.where(:user_tags.in => [user.id.to_s], :read_by.nin => [user.id.to_s]) 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 = [] unread_tickets = []
tqrs.each do |tqr| 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" 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" placeholder: "Tag Members"
}); });
readbyFunction();
}) })
$(".reopen-back-btn").on("click",function(){ $(".reopen-back-btn").on("click",function(){
for (instance in CKEDITOR.instances) { for (instance in CKEDITOR.instances) {
@ -363,28 +363,31 @@ $(document).ready(function(){
} }
}) })
var readbyFunction = function(){
var responses_seen = $("div[data-user-tags*=" + user_id + "]:in-viewport");
$.each(responses_seen,function(){
var el = $(this),
avatar = $("div[data-scroll-id=response_" + el.data("response-id") + "]").find("img[data-avatar-id="+ user_id +"]");
if(!avatar.hasClass("read")){
$.ajax({
url : "/admin/comments/read",
dataType : "json",
type : "post",
data : {"response_id" : el.data("response-id")}
}).done(function(data){
if(data.success){
avatar.addClass("read");
notificationManager.setNotificationNumber(data.total_ticket_count);
}
})
}
})
}
var timer = null; var timer = null;
$(document).on("scroll",function(){ $(document).on("scroll",function(){
clearTimeout(timer); clearTimeout(timer);
timer = setTimeout(function(){ timer = setTimeout(readbyFunction,1000);
var responses_seen = $("div[data-user-tags*=" + user_id + "]:in-viewport");
$.each(responses_seen,function(){
var el = $(this),
avatar = $("div[data-scroll-id=response_" + el.data("response-id") + "]").find("img[data-avatar-id="+ user_id +"]");
if(!avatar.hasClass("read")){
$.ajax({
url : "/admin/comments/read",
dataType : "json",
type : "post",
data : {"response_id" : el.data("response-id")}
}).done(function(data){
if(data.success){
avatar.addClass("read");
}
})
}
})
},1000);
}) })
})(); })();
</script> </script>