Browse Source

add a prosody module to insert identity information (when available) … (#2627)

* add a prosody module to insert identity information (when available) into
presence

prosody will check for jitsi_meet_context_user and
jitsi_meet_context_group in the session and, if they are present, insert
them into presence (we do this in prosody so they cannot be spoofed).

* remove unused 'presence' variable

* refactor to modify presence message in place

* make object member access consistent

* make the group information optional
master
bbaldino 7 years ago
parent
commit
fef1d8b520
1 changed files with 40 additions and 0 deletions
  1. 40
    0
      resources/prosody-plugins/mod_presence_identity.lua

+ 40
- 0
resources/prosody-plugins/mod_presence_identity.lua View File

@@ -0,0 +1,40 @@
1
+local stanza = require "util.stanza";
2
+
3
+-- For all received presence messages, if the jitsi_meet_context_(user|group)
4
+-- values are set in the session, then insert them into the presence messages
5
+-- for that session.
6
+function on_message(event)
7
+    if event and event["stanza"] then
8
+      if event.origin and event.origin.jitsi_meet_context_user then
9
+          -- First remove any 'identity' element if it already
10
+          -- exists
11
+          event.stanza:maptags(
12
+              function(tag)
13
+                  for k, v in pairs(tag) do
14
+                      if k == "name" and v == "identity" then
15
+                          return nil
16
+                      end
17
+                  end
18
+                  return tag
19
+              end
20
+          )
21
+          module:log("debug", "Presence after previous identity stripped: %s", tostring(event.stanza))
22
+
23
+          event.stanza:tag("identity"):tag("user")
24
+          for k, v in pairs(event.origin.jitsi_meet_context_user) do
25
+              event.stanza:tag(k):text(v):up()
26
+          end
27
+          event.stanza:up()
28
+            
29
+          -- Add the group information if it is present
30
+          if event.origin.jitsi_meet_context_group then
31
+              event.stanza:tag("group"):text(event.origin.jitsi_meet_context_group)
32
+          end
33
+
34
+          module:log("debug", "Sending presence with identity inserted %s", tostring(event.stanza))
35
+      end
36
+    end
37
+end
38
+
39
+module:hook("pre-presence/bare", on_message);
40
+module:hook("pre-presence/full", on_message);

Loading…
Cancel
Save