Disabe search in encrypted room
authorAjay Bura <ajbura@gmail.com>
Mon, 17 Jan 2022 04:45:13 +0000 (10:15 +0530)
committerAjay Bura <ajbura@gmail.com>
Mon, 17 Jan 2022 04:45:13 +0000 (10:15 +0530)
Signed-off-by: Ajay Bura <ajbura@gmail.com>
src/app/molecules/room-search/RoomSearch.jsx
src/app/organisms/room/RoomSettings.scss

index cbbaf23f214be4dc5590126bb62bc802a7a47ba3..39b83b405338465044f561ec51816f579f588f47 100644 (file)
@@ -104,10 +104,12 @@ function useRoomSearch(roomId) {
 
 function RoomSearch({ roomId }) {
   const [searchData, search, paginate, status] = useRoomSearch(roomId);
-
+  const mx = initMatrix.matrixClient;
+  const isRoomEncrypted = mx.isRoomEncrypted(roomId);
   const searchTerm = searchData?._query.search_categories.room_events.search_term ?? '';
 
   const handleSearch = (e) => {
+    if (isRoomEncrypted) return;
     e.preventDefault();
     const searchTermInput = e.target.elements['room-search-input'];
     const term = searchTermInput.value.trim();
@@ -148,22 +150,27 @@ function RoomSearch({ roomId }) {
         {searchData?.results.length > 0 && (
           <Text>{`${searchData.count} results for "${searchTerm}"`}</Text>
         )}
-      </form>
-      {searchData === null && (
-        <div className="room-search__help">
-          {status.type === cons.status.IN_FLIGHT && <Spinner />}
-          {status.type === cons.status.IN_FLIGHT && <Text>Searching room messages...</Text>}
-          {status.type === cons.status.PRE_FLIGHT && <RawIcon src={SearchIC} size="large" />}
-          {status.type === cons.status.PRE_FLIGHT && <Text>Search room messages</Text>}
-          {status.type === cons.status.ERROR && <Text>Failed to search messages</Text>}
-        </div>
-      )}
+        {!isRoomEncrypted && searchData === null && (
+          <div className="room-search__help">
+            {status.type === cons.status.IN_FLIGHT && <Spinner />}
+            {status.type === cons.status.IN_FLIGHT && <Text>Searching room messages...</Text>}
+            {status.type === cons.status.PRE_FLIGHT && <RawIcon src={SearchIC} size="large" />}
+            {status.type === cons.status.PRE_FLIGHT && <Text>Search room messages</Text>}
+            {status.type === cons.status.ERROR && <Text>Failed to search messages</Text>}
+          </div>
+        )}
 
-      {searchData?.results.length === 0 && (
-        <div className="room-search__help">
-          <Text>No result found</Text>
-        </div>
-      )}
+        {!isRoomEncrypted && searchData?.results.length === 0 && (
+          <div className="room-search__help">
+            <Text>No result found</Text>
+          </div>
+        )}
+        {isRoomEncrypted && (
+          <div className="room-search__help">
+            <Text>Search does not work in encrypted room</Text>
+          </div>
+        )}
+      </form>
       {searchData?.results.length > 0 && (
         <>
           <div className="room-search__content">
index 909dbb309c9d5f97619f450b49b2f1d4ef83dd13..fb1b251972cad01d2fd354cbf9a70337971fa6d4 100644 (file)
@@ -48,7 +48,6 @@
 
 .room-settings .room-permissions__card,
 .room-settings .room-search__form,
-.room-settings .room-search__help,
 .room-settings .room-search__result-item {
   @extend .room-settings__card;
 }
\ No newline at end of file