From bc0bfa63776af55042297cc8b4dc7638ea22294a Mon Sep 17 00:00:00 2001
From: Travis Ralston <travisr@matrix.org>
Date: Fri, 13 May 2022 09:20:43 -0600
Subject: [PATCH] Iterate on search results for message bubbles (#7047)

* PSFD-455: Iterate on search results for message bubbles

Though not perfect, this is a bit better than it was before. Specifically, we ensure our matching for `isOwnEvent` correctly identifies the user and that the results don't look *awful*.

There's still room for improvement, but this should be a measurable improvement itself. Most notably, this doesn't fix a couple obvious bugs due to complexity:
* Message bubbles have the wrong corners for the display format (pre-existing).
* The sender's own messages are missing avatars/names. This is just way too complex to fix.

**Requires https://github.com/matrix-org/matrix-js-sdk/pull/2004**

* Tweak opacity

Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
---
 res/css/views/rooms/_EventBubbleTile.scss | 21 +++++++++++++++++++++
 src/components/views/rooms/EventTile.tsx  |  3 ++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/res/css/views/rooms/_EventBubbleTile.scss b/res/css/views/rooms/_EventBubbleTile.scss
index a4814c3faf..36488c7448 100644
--- a/res/css/views/rooms/_EventBubbleTile.scss
+++ b/res/css/views/rooms/_EventBubbleTile.scss
@@ -31,6 +31,27 @@ limitations under the License.
     margin-right: 60px;
 }
 
+.mx_RoomView_searchResultsPanel {
+    .mx_EventTile[data-layout=bubble] {
+        .mx_SenderProfile {
+            // Group layout adds a 64px left margin, which we really don't want on search results
+            margin-left: 0;
+        }
+
+        &[data-self=true] {
+            // The avatars end up overlapping, so just hide them
+            .mx_EventTile_avatar {
+                display: none;
+            }
+        }
+
+        // Mirror rough designs for "greyed out" text
+        &.mx_EventTile_contextual .mx_EventTile_line {
+            opacity: 0.4;
+        }
+    }
+}
+
 .mx_EventTile[data-layout=bubble] {
     position: relative;
     margin-top: var(--gutterSize);
diff --git a/src/components/views/rooms/EventTile.tsx b/src/components/views/rooms/EventTile.tsx
index f5eb751e0b..9ccf7d44dd 100644
--- a/src/components/views/rooms/EventTile.tsx
+++ b/src/components/views/rooms/EventTile.tsx
@@ -1235,7 +1235,8 @@ export class UnwrappedEventTile extends React.Component<IProps, IState> {
             />;
         }
 
-        const isOwnEvent = this.props.mxEvent?.sender?.userId === MatrixClientPeg.get().getUserId();
+        // Use `getSender()` because searched events might not have a proper `sender`.
+        const isOwnEvent = this.props.mxEvent?.getSender() === MatrixClientPeg.get().getUserId();
 
         switch (this.context.timelineRenderingType) {
             case TimelineRenderingType.Notification: {