Преглед на файлове

Exclude static jitsi links from calendar fetch

master
Bettenbuk Zoltan преди 6 години
родител
ревизия
4da8c626f7
променени са 1 файла, в които са добавени 32 реда и са изтрити 8 реда
  1. 32
    8
      react/features/calendar-sync/functions.any.js

+ 32
- 8
react/features/calendar-sync/functions.any.js Целия файл

@@ -96,6 +96,30 @@ export function _updateCalendarEntries(events: Array<Object>) {
96 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 124
  * Updates the calendar entries in Redux when new list is received.
101 125
  *
@@ -155,11 +179,9 @@ function _parseCalendarEntry(event, knownDomains) {
155 179
 function _getURLFromEvent(event, knownDomains) {
156 180
     const linkTerminatorPattern = '[^\\s<>$]';
157 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 185
     const fieldsToSearch = [
164 186
         event.title,
165 187
         event.url,
@@ -170,10 +192,12 @@ function _getURLFromEvent(event, knownDomains) {
170 192
 
171 193
     for (const field of fieldsToSearch) {
172 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 202
                 if (url) {
179 203
                     return url.toString();

Loading…
Отказ
Запис