Skip to content

Commit

Permalink
fix #403 - Implement server-side login Jitsi Meet Polls
Browse files Browse the repository at this point in the history
  • Loading branch information
deleolajide committed Mar 18, 2022
1 parent 398afbe commit 41ee42d
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.html
Expand Up @@ -55,6 +55,7 @@ <h1>
<li>Fixed <a href="https://github.com/igniterealtime/openfire-pade-plugin/pull/399">Issue #399 - Regression: Administrative Messages not working</a></li>
<li>Fixed <a href="https://github.com/igniterealtime/openfire-pade-plugin/pull/401">Issue #401 - Change shortcut used for Shared Mouse Pointer</a></li>
<li>Fixed <a href="https://github.com/igniterealtime/openfire-pade-plugin/pull/402">Issue #402 - Support Participants Pane</a></li>
<li>Fixed <a href="https://github.com/igniterealtime/openfire-pade-plugin/pull/403">Issue #403 - Implement server-side login Jitsi Meet Polls</a></li>
<li>Fixed <a href="https://github.com/igniterealtime/openfire-pade-plugin/pull/404">Issue #404 - Use local store as fallback for Credentials API</a></li>
<li>Fixed <a href="https://github.com/igniterealtime/openfire-pade-plugin/pull/405">Issue #405 - Update web-push framework</a></li>

Expand Down
94 changes: 94 additions & 0 deletions src/java/org/jivesoftware/openfire/plugin/ofmeet/OfMeetPlugin.java
Expand Up @@ -98,6 +98,7 @@

import org.jboss.netty.channel.ExceptionEvent;
import org.json.JSONObject;
import org.json.JSONArray;
import org.jitsi.util.OSUtils;
import de.mxro.process.*;
import javax.xml.bind.DatatypeConverter;
Expand Down Expand Up @@ -1049,6 +1050,35 @@ else if (!"ofgasi".equals(roomName) && !"ofmeet".equals(roomName)) {

if (props != null)
{
// Send Meeting Polls

JSONObject pollsMsg = new JSONObject();
pollsMsg.put("type", "old-polls");

JSONArray polls = new JSONArray();

for (String key : props.keySet())
{
if (key.startsWith("jitsi.meet.polls.")) {
JSONObject poll = new JSONObject(props.get(key));
polls.put(poll);
}
}

pollsMsg.put("polls", polls);

Message pollMsg = new Message();
pollMsg.setFrom(roomJID);
pollMsg.setTo(user);
Element pollJson = pollMsg.addChildElement("json-message", "http://jitsi.org/jitmeet");
pollJson.setText(pollsMsg.toString());
XMPPServer.getInstance().getRoutingTable().routePacket(user, pollMsg, true);

Log.debug("occupantJoined polls\n" + pollsMsg);


// Send all properties

JSONObject jsonMsg = new JSONObject();
jsonMsg.put("action", "push-room-properties");

Expand Down Expand Up @@ -1165,7 +1195,71 @@ public void nicknameChanged(JID roomJID, JID user, String oldNickname, String ne
@Override
public void messageReceived(JID roomJID, JID user, String nickname, Message message)
{
String roomName = roomJID.getNode();
String serviceName = roomJID.getDomain().replace("."+ XMPPServer.getInstance().getServerInfo().getXMPPDomain(), "");
String userName = user.getNode();

Map<String, String> props = MUCRoomProperties.get(serviceName, roomName);
Element childElement = message.getChildElement("json-message", "http://jitsi.org/jitmeet");

if (childElement != null && props != null) {
String data = childElement.getText();
net.sf.json.JSONObject json = new net.sf.json.JSONObject(data);

if (json.has("type") && json.has("pollId")) {
Log.debug("messageReceived polls\n" + json + "\n" + props.values());

String pollType = json.getString("type");
String key = "jitsi.meet.polls." + json.getString("pollId");

if ("new-poll".equals(pollType)) {
net.sf.json.JSONObject newPoll = new net.sf.json.JSONObject();
net.sf.json.JSONArray storedAnswers = new net.sf.json.JSONArray();

net.sf.json.JSONArray answers = json.getJSONArray("answers");

for (int i = 0; i < answers.length(); i++)
{
String name = answers.getString(i);

net.sf.json.JSONObject answer = new net.sf.json.JSONObject();
answer.put("name", name);
answer.put("voters", new net.sf.json.JSONObject());
storedAnswers.put(i, answer);
}

newPoll.put("id", json.getString("pollId"));
newPoll.put("senderId", json.getString("senderId"));
newPoll.put("senderName", json.getString("senderName"));
newPoll.put("question", json.getString("question"));
newPoll.put("answers", storedAnswers);

props.put(key, newPoll.toString());
}
else

if ("answer-poll".equals(pollType)) {
String data2 = props.get(key);

if (data2 != null) {
net.sf.json.JSONObject poll = new net.sf.json.JSONObject(data2);
net.sf.json.JSONArray answers = json.getJSONArray("answers");

for (int i = 0; i < answers.length(); i++) {
net.sf.json.JSONObject voters = poll.getJSONArray("answers").getJSONObject(i).getJSONObject("voters");
String voterId = json.getString("voterId");
String voterName = json.getString("voterName");

if (answers.getBoolean(i)) {
voters.put(voterId, voterName);
}
}

props.put(key, poll.toString());
}
}
}
}
}

@Override
Expand Down

0 comments on commit 41ee42d

Please sign in to comment.