5bf44536 |
class WsRosterController < WebsocketRails::BaseController |
b27f285a |
require 'xmpp4r/roster'
require 'xmpp4r/vcard' |
ff94bdbf |
|
b27f285a |
def initialize
super
@storages = [:contacts, :clients, :rosters]
end
def initialize_storage
@storages.each do |storage| |
93083165 |
connection_store[storage] = [] |
b27f285a |
end |
ff94bdbf |
end
|
70fc03c1 |
def connect |
b27f285a |
initialize_storage()
clients = Token.fing_user_accounts_having_to_token(session[:token])
clients.each do |credentials|
begin
client = Signin.try_login(credentials["jid"], credentials["pass"])
client.send(Jabber::Presence.new.set_type(:available)) |
333715b4 |
|
93083165 |
connection_store[:clients] << client
connection_store[:rosters] << Jabber::Roster::Helper.new(client) |
b27f285a |
rescue Signin::LoginError
trigger_failure msg: credentials["jid"]
end
end |
70fc03c1 |
end
|
ff94bdbf |
##
# Vrat vsetkych priatelov v rosteri |
b27f285a |
def get_contacts
all_contacts = []
|
93083165 |
connection_store[:rosters].each do |roster| |
b27f285a |
roster.wait_for_roster
roster.get_roster()
roster.items.each do |jid, contact|
all_contacts << {
jid: jid.to_s
}
end
end
trigger_success contacts: all_contacts |
ff94bdbf |
end
|
b27f285a |
def disconnect |
93083165 |
if connection_store[:clients]
connection_store[:clients].each do |client| |
b27f285a |
client.send(Jabber::Presence.new.set_type(:unavailable))
end
end |
ff94bdbf |
|
b27f285a |
@storages.each do |storage|
connection_store.delete(storage)
end |
ff94bdbf |
end |
70fc03c1 |
|
b27f285a |
##
# Pridaj noveho priatela do zoznamu
def add_friend(data) |
70fc03c1 |
|
23f7b7b2 |
end |
ff94bdbf |
end |