Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SocketController < WebsocketRails::BaseController
- def addMessage
- c = Chat.find(message[:chat_id])
- msg = Message.new
- msg.message = message[:message]
- msg.chat_id = message[:chat_id]
- msg.user_id = message[:user]
- msg.save(validate: false)
- o = c.order
- new_message = {:message => message[:message], :date => (DateTime.now.utc - 3.hours).strftime("%d/%m/%y %H:%M") }
- if msg.user.class != Guide
- data = { :alert => "Enviou uma mensagem", sound: "default", type: "chat", order: c.order.id, chat: c.id}
- pushQ = Parse::Push.new(data)
- query = Parse::Query.new(Parse::Protocol::CLASS_INSTALLATION).eq('customer_id', c.order.guide.id)
- pushQ.where = query.where
- pushQ.save
- o = c.order
- o.user.notifications.where(:chat_id => c.id.to_s).destroy_all
- n = Notification.new
- n.user = o.guide
- n.name = o.user.name
- n.message = data[:alert]
- n.order_id = o.id.to_s
- n.chat_id = c.id.to_s
- n.picture_url = o.user.picture.url(:original)
- n.save
- WebsocketRails["#{c.id.to_s}guide"].trigger :new_message, new_message
- DucityMailer.chat_notification_notify(u.guide)
- else
- data = { :alert => "Enviou uma mensagem", sound: "default", type: "chat", order: c.order.id, chat: c.id}
- puts "**********1"
- pushQ = Parse::Push.new(data)
- query = Parse::Query.new(Parse::Protocol::CLASS_INSTALLATION).eq('customer_id', c.order.user.id)
- pushQ.where = query.where
- pushQ.save
- puts "**********2"
- o = c.order
- o.user.notifications.where(:chat_id => c.id.to_s).destroy_all
- n = Notification.new
- puts "**********3"
- n.user = o.user
- n.name = o.guide.name
- n.message = data[:alert]
- puts "**********4"
- n.order_id = o.id.to_s
- n.chat_id = c.id.to_s
- puts "**********5"
- n.picture_url = o.guide.picture.url(:original)
- n.save
- puts "**********6"
- WebsocketRails["#{c.id.to_s}"].trigger :new_message, new_message
- puts "**********7"
- end
- end
- def addMessageGuide
- puts "******************"
- puts "******************"
- puts "******************"
- puts "******************"
- puts "******************"
- puts "******************"
- puts "******************"
- puts "******************"
- puts "******************"
- puts "******************"
- puts "******************" + message.to_s
- c = Chat.find(message[:chat_id])
- msg = Message.new
- msg.message = message[:message]
- msg.chat = c
- msg.user = User.find(message[:user])
- msg.save(validate: false)
- o = c.order
- if msg.user.class != Guide
- data = { :alert => (msg.user.name + " enviou uma mensagem"), sound: "default", type: "chat", order: c.order.id, chat: c.id}
- pushQ = Parse::Push.new(data)
- query = Parse::Query.new(Parse::Protocol::CLASS_INSTALLATION).eq('customer_id', c.order.guide.id)
- pushQ.where = query.where
- pushQ.save
- o = c.order
- o.user.notifications.where(:chat_id => c.id.to_s).destroy_all
- n = Notification.new
- n.user = o.guide
- n.name = o.user.name
- n.message = data[:alert]
- n.order_id = o.id.to_s
- n.chat_id = c.id.to_s
- n.picture_url = o.user.picture.url(:original)
- n.save
- else
- data = { :alert => (msg.user.name + " enviou uma mensagem"), sound: "default", type: "chat", order: c.order.id, chat: c.id}
- pushQ = Parse::Push.new(data)
- query = Parse::Query.new(Parse::Protocol::CLASS_INSTALLATION).eq('customer_id', c.order.user.id)
- pushQ.where = query.where
- pushQ.save
- o = c.order
- o.user.notifications.where(:chat_id => c.id.to_s).destroy_all
- n = Notification.new
- n.user = o.user
- n.name = o.guide.name
- n.message = data[:alert]
- n.order_id = o.id.to_s
- n.chat_id = c.id.to_s
- n.picture_url = o.guide.picture.url(:original)
- n.save
- end
- end
- def addMessage2
- puts "******@*********"
- puts "***************"
- puts "***************"
- puts "***************"
- puts "***********@****"
- puts "***************" + message.to_s
- puts "***************" + message[:data].to_s
- if !message[:data].nil?
- m = message[:data]
- else
- m = message
- end
- # puts "***********@****"
- # puts "***************" + m.to_s
- puts "***************" + m["chat_id"].to_s
- m["chat_id"] = m["chat_id"].to_s.gsub(m["user"].to_s, "")
- id = (m["chat_id"].to_s).gsub(m["user"].to_s, "")
- c = Chat.find(id)
- puts "***************" + c.id
- msg = Message.new
- msg.message = m["message"]
- puts "***************" + msg.message
- msg.chat = c
- msg.isProvider = true
- msg.user = User.find(m["user"].to_s)
- msg.save
- new_message = {:message => msg.message, :date => (DateTime.now.utc - 2.hours).strftime("%d/%m/%y %H:%M") }
- id = (c.user_id.to_s + c.provider_id.to_s).gsub(msg.user.id.to_s, "")
- WebsocketRails["#{c.id.to_s}#{id}"].trigger :new_message, new_message
- # Thread.new do
- # data = { :alert => {:title => msg.user.name, body: msg.message}, sound: "default", :chat_id => c.id.to_s}
- data = {:chat_id => c.id.to_s, :alert => (msg.user.name + " enviou uma mensagem " ), sound: "default"}
- pushQ = Parse::Push.new(data)
- query = Parse::Query.new(Parse::Protocol::CLASS_INSTALLATION).eq('customer_id ', id)
- pushQ.where = query.where
- pushQ.save
- puts "@@@*******!!!********" + msg.user.to_s
- puts "********"
- puts "@@@*******!!!*******----*" + msg.user.to_s
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement