1354 timestamp = state._last_message_at, }, |
1354 timestamp = state._last_message_at, }, |
1355 }; |
1355 }; |
1356 end |
1356 end |
1357 |
1357 |
1358 local occupants = {}; |
1358 local occupants = {}; |
1359 local occupant_sessions = {}; |
|
1360 local room_name, room_host = jid_split(room_jid); |
1359 local room_name, room_host = jid_split(room_jid); |
1361 |
1360 |
1362 if frozen.jid and frozen._affiliations then |
1361 if frozen.jid and frozen._affiliations then |
1363 room._affiliations = frozen._affiliations; |
1362 room._affiliations = frozen._affiliations; |
1364 else |
1363 else |
1373 for jid, data in pairs(state or frozen) do |
1372 for jid, data in pairs(state or frozen) do |
1374 local node, host, resource = jid_split(jid); |
1373 local node, host, resource = jid_split(jid); |
1375 if node or host:sub(1,1) ~= "_" then |
1374 if node or host:sub(1,1) ~= "_" then |
1376 if host == room_host and node == room_name and resource and type(data) == "table" then |
1375 if host == room_host and node == room_name and resource and type(data) == "table" then |
1377 -- full room jid: bare real jid and role |
1376 -- full room jid: bare real jid and role |
1378 local bare_jid = data.bare_jid; |
1377 local nick = jid; |
1379 local occupant = occupant_lib.new(bare_jid, jid); |
1378 local occupant = occupants[nick] or occupant_lib.new(data.bare_jid, nick); |
1380 occupant.jid = data.jid; |
1379 occupant.bare_jid = data.bare_jid; |
1381 occupant.role = data.role; |
1380 occupant.role = data.role; |
1382 occupants[bare_jid] = occupant; |
1381 occupant.jid = data.jid; -- Primary session JID |
1383 local sessions = occupant_sessions[bare_jid]; |
1382 occupants[nick] = occupant; |
1384 if sessions then |
1383 elseif type(data) == "table" and data.name == "presence" then |
1385 for full_jid, presence in pairs(sessions) do |
|
1386 occupant:set_session(full_jid, presence); |
|
1387 end |
|
1388 end |
|
1389 occupant_sessions[bare_jid] = nil; |
|
1390 elseif type(data) == "table" and data.name then |
|
1391 -- full user jid: presence |
1384 -- full user jid: presence |
|
1385 local nick = data.attr.from; |
|
1386 local occupant = occupants[nick] or occupant_lib.new(nil, nick); |
1392 local presence = st.deserialize(data); |
1387 local presence = st.deserialize(data); |
1393 local bare_jid = jid_bare(jid); |
1388 occupant:set_session(jid, presence); |
1394 local occupant = occupants[bare_jid]; |
1389 occupants[nick] = occupant; |
1395 local sessions = occupant_sessions[bare_jid]; |
|
1396 if occupant then |
|
1397 occupant:set_session(jid, presence); |
|
1398 elseif sessions then |
|
1399 sessions[jid] = presence; |
|
1400 else |
|
1401 occupant_sessions[bare_jid] = { |
|
1402 [jid] = presence; |
|
1403 }; |
|
1404 end |
|
1405 end |
1390 end |
1406 end |
1391 end |
1407 end |
1392 end |
1408 |
1393 |
1409 for _, occupant in pairs(occupants) do |
1394 for _, occupant in pairs(occupants) do |