Browse Source

Exclude static jitsi links from calendar fetch

master
Bettenbuk Zoltan 6 years ago
parent
commit
4da8c626f7
1 changed files with 32 additions and 8 deletions
  1. 32
    8
      react/features/calendar-sync/functions.any.js

+ 32
- 8
react/features/calendar-sync/functions.any.js View File

96
                 .slice(0, MAX_LIST_LENGTH)));
96
                 .slice(0, MAX_LIST_LENGTH)));
97
 }
97
 }
98
 
98
 
99
+/**
100
+ * Checks a string against a positive pattern and a negative pattern. Returns
101
+ * the string if it matches the positive pattern and doesn't provide any match
102
+ * against the negative pattern. Null otherwise.
103
+ *
104
+ * @param {string} str - The string to check.
105
+ * @param {string} positivePattern - The positive pattern.
106
+ * @param {string} negativePattern - The negative pattern.
107
+ * @returns {string}
108
+ */
109
+function _checkPattern(str, positivePattern, negativePattern) {
110
+    const positiveRegExp = new RegExp(positivePattern, 'gi');
111
+    let positiveMatch;
112
+
113
+    while ((positiveMatch = positiveRegExp.exec(str)) !== null) {
114
+        // $FlowFixMe
115
+        const url = positiveMatch[0];
116
+
117
+        if (!new RegExp(negativePattern, 'gi').exec(url)) {
118
+            return url;
119
+        }
120
+    }
121
+}
122
+
99
 /**
123
 /**
100
  * Updates the calendar entries in Redux when new list is received.
124
  * Updates the calendar entries in Redux when new list is received.
101
  *
125
  *
155
 function _getURLFromEvent(event, knownDomains) {
179
 function _getURLFromEvent(event, knownDomains) {
156
     const linkTerminatorPattern = '[^\\s<>$]';
180
     const linkTerminatorPattern = '[^\\s<>$]';
157
     const urlRegExp
181
     const urlRegExp
158
-        = new RegExp(
159
-        `http(s)?://(${knownDomains.join('|')})/${linkTerminatorPattern}+`,
160
-        'gi');
161
-    const schemeRegExp
162
-        = new RegExp(`${APP_LINK_SCHEME}${linkTerminatorPattern}+`, 'gi');
182
+        = `http(s)?://(${knownDomains.join('|')})/${linkTerminatorPattern}+`;
183
+    const schemeRegExp = `${APP_LINK_SCHEME}${linkTerminatorPattern}+`;
184
+    const excludePattern = '/static/';
163
     const fieldsToSearch = [
185
     const fieldsToSearch = [
164
         event.title,
186
         event.title,
165
         event.url,
187
         event.url,
170
 
192
 
171
     for (const field of fieldsToSearch) {
193
     for (const field of fieldsToSearch) {
172
         if (typeof field === 'string') {
194
         if (typeof field === 'string') {
173
-            const matches = urlRegExp.exec(field) || schemeRegExp.exec(field);
195
+            const match
196
+                = _checkPattern(field, urlRegExp, excludePattern)
197
+                || _checkPattern(field, schemeRegExp, excludePattern);
174
 
198
 
175
-            if (matches) {
176
-                const url = parseURIString(matches[0]);
199
+            if (match) {
200
+                const url = parseURIString(match);
177
 
201
 
178
                 if (url) {
202
                 if (url) {
179
                     return url.toString();
203
                     return url.toString();

Loading…
Cancel
Save