Commit Graph

778 Commits

Author SHA1 Message Date
Joffrey JAFFEUX f0d82de5d9
DEV: fix flakeyness with drawer specs (#22476)
Chat drawer was using the `DiscourseURL` hook `afterRouteComplete`. This hook suffer from a very poor implementation which makes it very unreliable:

```javascript
if (typeof opts.afterRouteComplete === "function") {
  schedule("afterRender", opts.afterRouteComplete);
}
```

This commit attempts to return the promise from `handleURL` to directly use it and have a very reliable after transition hook.
2023-07-07 00:46:04 +02:00
Joffrey JAFFEUX d41fa579c8
DEV: more resilient auto remove spec (#22472)
We have no guarantees on the last record here, it's easier and more stable to check all created records.
2023-07-06 21:44:53 +02:00
Joffrey JAFFEUX c0808b2537
FIX: correctly makes dm creator to follow channel (#22470)
In previous changes we prevented creating a channel to also make users follow the channel. We were forcing recipients to follow the channel on message sent but this was not including the creator of the message itself.

This commit fixes it and also write an end-to-end system spec to cover these cases. The message creator service is currently being rewritten and should correctly test and ensure this logic is present.

This commit also makes changes on the frontend to instantly follow a DM when you open it, this change prevents a green dot to appear for a split second when you send a message in a channel you were previously not following. Only recipients will see the green dot.
2023-07-06 21:42:19 +02:00
Jarek Radosz dc46acb851
DEV: Remove `OK` pretender helper (#22438)
We already have the `response` helper (which additionally sets the `Content-Type` header)

(also: all-caps name suggested a constant, not a function)
2023-07-06 20:39:23 +02:00
Isaac Janzen b8cf50798b
DEV: Skip flaky visit-channel system tests (#22469)
Consistently seeing failures on 
- visit-channel
- navigation

specs
2023-07-06 13:17:37 -05:00
Joffrey JAFFEUX 250e3d881d
FIX: removes discourse-teams-sidebar support (#22465)
This plugin is now archived we don't need to carry this code anymore.
2023-07-06 15:40:24 +02:00
Joffrey JAFFEUX 30e4b898f5
FIX: limits legacy sidebar height (#22466)
Prior to this fix the sidebar was taking unlimited height.
2023-07-06 15:40:20 +02:00
Mark VanLandingham 3171fd1a0a
DEV: Introduce Chat Notices with publishing method (#22369) 2023-07-06 08:26:25 -05:00
Loïc Guitaut 5134b28d83 FIX: Add missing chat translations
Some error messages when creating a new chat message were not defined.
2023-07-06 11:35:02 +02:00
Martin Brennan f69748e325
FIX: Mark threads read when threading enabled for a channel (#22458)
Since we create threads in the background regardless of whether
threading is enabled for a channel, we get the unexpected behaviour
of everyone having a lot of unread threads when threading is enabled
for the channel.

To counteract this, when the admin enables threads for a channel
we can just run a high priority background job to mark all threads
as read in the channel for all users, so they are essentially
starting from a clean slate.
2023-07-06 16:24:56 +10:00
Martin Brennan 9b14bf82dc
FIX: Show replies count on thread indicator regardless of participants (#22459)
Followup to 802fb3b194

We should not hide the replies count if there is only 1 participant
for a thread, because this makes it look like the last reply is the
only reply.
2023-07-06 14:31:18 +10:00
Martin Brennan 1cd512a03a
DEV: Normalize key modifier checks for keyboard shortcuts (#22451)
This introduces a PLATFORM_KEY_MODIFIER const that
can be used both client and server side, to determine
whether we should be using the Meta or Ctrl key based
on whether the user is on Windows/Linux or Mac.
2023-07-06 13:34:24 +10:00
Alan Guo Xiang Tan 4c810703c1
FIX: Avoid transitioning when a chat thread component is destroyed (#22457)
Why this change?

Before this commit, there is a chance that we will transition the user
to a different route if the chat thread component has been destroyed
prior to the request for fetching messasges in a chat thread returning.

This commit makes it such that we simply ignore the request if the chat
thread component has been destroyed.

We believe this is the cause of the flaky system tests in plugins/chat/spec/system/navigation_spec.rb
which we've been seeing on CI.
2023-07-06 10:53:28 +08:00
Alan Guo Xiang Tan ff38bccb80
DEV: Fix number of chars for chat message content in fabricator (#22454)
Why this change?

`Faker::Lorem.paragraph` generates a differrent length of string
every time. When a string happens to be long, it can change the UI
across system test runs making it harder to reason about our system
tests across multiple runs since the state is never really consistent.

We will just generate a paragraph with a fixed length going forward so
that the UI remains consistent. This should make certain tests which
relies on the UI being in a certain state to become less flaky.
2023-07-06 10:34:57 +08:00
Alan Guo Xiang Tan cb9ae1eb1f
DEV: Fix flaky chat drawer system test (#22452)
Why this change?

This change ensures that we scroll to the top of the message when
hovering over a message to ensure that the message actions container
that appears on hover is not hidden in the chat drawer when the content
of the chat message is long.
2023-07-06 09:03:42 +08:00
Alan Guo Xiang Tan 9a65c78d87
DEV: Avoid waiting full capybara default wait time (#22449)
Why this change?

`not_to be_open` ends up calling `has_css?` on a selector that will
never appear so it ends up waiting the full default wait time.
2023-07-06 08:16:58 +08:00
Martin Brennan 37a8036b2d
FIX: Better handling of deleted thread original messages (#22402)
This commit includes several fixes and improvements to thread
original message handling:

1. When a thread's original message is deleted, the thread no longer
   counts as unread for a user
2. When a thread original message is deleted and the user is looking
   at the thread list, it will be removed from the list
3. When a thread original message is restored and the user is looking
   at the thread list, it will be added back to the list if it was
   previously loaded
2023-07-06 09:47:34 +10:00
Joffrey JAFFEUX 478c4b1a74
DEV: prevents message actions to hide drawer's header (#22448)
In specific conditions (generally a small drawer, with a long message) it is possible to have the message’s actions menu to be displayed hover the drawer's header.

This is particularly hard to fix correctly using popper due to our positioning which is slightly at the limit of the container.

The proposed fix targets mostly the specs by ensuring the messages actions will be hidden before attempting to click any header's button.
2023-07-06 07:33:39 +08:00
Alan Guo Xiang Tan 772334a346
DEV: Add more helpful assertions for flaky system tests in CI (#22432)
Why this change?

In CI, we know we're clicking a link to a chat channel's threads list.
However, the threads list is not loaded and we want to add more
assertions here to try and figure out why. By asserting for the current
URL, we will at least know that the transition to the URL is successful.
2023-07-06 07:08:59 +08:00
Joffrey JAFFEUX 972e0f74ff
FIX: more consistent composer focus and replying indicator (#22443) 2023-07-05 22:24:53 +02:00
Joffrey JAFFEUX 2ce9364c08
FIX: do not filter on category name (#22442) 2023-07-05 21:12:39 +02:00
Joffrey JAFFEUX cfdf5b9518
FIX: correctly show unread and presence (#22441)
- Presence needs to be explicitly set on the component now
- We were not checking and testing correctly the presence of the unread indicator in the menu
2023-07-05 21:01:23 +02:00
Joffrey JAFFEUX d75d64bf16
FEATURE: new jump to channel menu (#22383)
This commit replaces two existing screens:
- draft
- channel selection modal

Main features compared to existing solutions
- features are now combined, meaning you can for example create multi users DM
- it will show users with chat disabled
- it shows unread state
- hopefully a better look/feel
- lots of small details and fixes...

Other noticeable fixes
- starting a DM with a user, even from the user card and clicking <kbd>Chat</kbd> will not show a green dot for the target user (or even the channel) until a message is actually sent
- it should almost never do a full page reload anymore

---------

Co-authored-by: Martin Brennan <mjrbrennan@gmail.com>
Co-authored-by: Jordan Vidrine <30537603+jordanvidrine@users.noreply.github.com>
Co-authored-by: chapoi <101828855+chapoi@users.noreply.github.com>
Co-authored-by: Mark VanLandingham <markvanlan@gmail.com>
2023-07-05 18:18:27 +02:00
Alan Guo Xiang Tan 1e26a521c2
FIX: Error when loading a channel with threading enabled but no threads (#22434)
Without this fix, the following error is raised:

```
ActiveRecord::StatementInvalid:
  PG::SyntaxError: ERROR:  syntax error at or near ")"
  LINE 4:   WHERE thread_id IN ()
```
2023-07-05 14:33:49 +08:00
Alan Guo Xiang Tan 14517785b2
DEV: Fix flaky system test when expanding chat message actions on mobile (#22428)
Why this change?

Chat system tests that opens the message actions on mobile have been
flaky on our CI. Those system test usually fails when the message
actions do not show up as expected causing subsequent actions to fail.

In the case of the `Reply to message - channel - mobile when the message has an existing thread replies to the existing thread`
system test, failure screenshot shows that we ended up navigating to the
thread instead of opening the message actions button. To understand why
this happens, we first need to understand that by default Capybara clicks
on the centre of an element. Also, we need to note that the HTML structure of
a chat message is like so:

```
<div class="chat-message-container">
  <div class="chat-message">
    <div class="chat-message-avatar" />
    <div class="chat-message-content" />
    <div class="chat-message-thread-indicator" />
  </div>
</div>
```

Since `PageObjects::Pages::ChatChannel#expand_message_actions_mobile`
attempts to click on the `.chat-message-contaier`, there is a
possibility that the center of that element is the
`.chat-message-thread-indicator` element which would explain why we
navigated to the thread list instead of opening up the message actions.
This is possible because the content of the original chat message as
well as the message excerpt in the thread is randomly generated where the
length of the message and how the text wraps on mobile can affect the
height of the `.chat-message-content` element as thus its position in
the `.chat-message-container` element. In most cases, the middle of the
`.chat-message-container` happens to be the `.chat-message-content`
which is why this test "flakes" sometimes.

What is the solution?

Instead of clicking on the `.chat-message-container`, we be more
specific and click on the `.chat-message-content` element instead.
2023-07-05 10:39:04 +08:00
Martin Brennan e9e3f147f0
DEV: Unhide chat experimental threads site setting (#22426)
This is in preparation for the V1 thread announcement,
where we will begin to allow site admins to enable this
themselves.
2023-07-05 11:20:31 +10:00
Discourse Translator Bot 9ee1972a2c
Update translations (#22412) 2023-07-04 18:14:46 +02:00
chapoi ee1dbd46c6
UX: Thread indicator small fixes (#22389)
* UX: make timestamp font size smaller

* UX: participants use copy instead of avatar

* FIX: Move thread participant count into i18n

---------

Co-authored-by: Martin Brennan <martin@discourse.org>
2023-07-04 10:32:09 +02:00
Martin Brennan 56aef3c082
DEV: Fix or remove flaky chat specs (#22406)
* DEV: Fix flaky thread nav spec

When we transitioned from the chat thread panel under some conditions
the request for the thread would come back and realise the component
was destroyed, which was trying to do a transition to the channel
itself.

Now we check for the previous route here too and transition to the
correct route.

* DEV: Fix chat transcript spec relying on animation

The on-animation-end modifier is not reliable in system specs
because it fires instantly (we have disabled capybara animations)
so the showCopySuccess boolean can be mutated back to false straight
away.

Better to have a separate boolean tracked with a data-attr that we
can reliably inspect in the system spec.
2023-07-04 16:23:04 +10:00
Alan Guo Xiang Tan 454a4af0bf
DEV: Ensure browser network conditions is reset in system tests (#22404)
Why this change?

By ensuring the reset happens in an `ensure` code block, we ensure that
the code will always be run even if code fails or an error is raised.
This helps to prevent leaking custom network condition states and
improves the stability of our system tests.
2023-07-04 13:22:58 +08:00
Isaac Janzen 2910b76138
DEV: Skip all chat user status tests (#22398) 2023-07-03 16:42:47 -05:00
Isaac Janzen 45ed84354b
DEV: Skip remaining flaky mention status tests (#22397) 2023-07-03 16:20:19 -05:00
Isaac Janzen f596de2143
DEV: Skip flaky chat deleted message mention status flake (#22396) 2023-07-03 16:00:09 -05:00
Isaac Janzen debe47cc0b
DEV: Skip flaky chat mention status test (#22395) 2023-07-03 15:54:03 -05:00
Jan Cernik 585a2e4e77
FEATURE: Use rich user status tooltip everywhere (#21125)
- Inline mentions on posts
- Inline mentions on chat messages
- The user autocomplete for the composer
- The user autocomplete for chat
- The chat section of the sidebar
2023-07-03 11:09:41 -03:00
Martin Brennan f6072ba804
DEV: Move user count update for channels to ensure_consistency! (#22321)
This fixes a longstanding TODO to move the contents of the
UpdateUserCountsForChannels job to the ensure_consistency!
method of Chat::Channel, which runs every 15 mins as part of
periodical updates.

This commit also addresses the performance issue of the original,
where we would fetch all channels and do an individual query to
get the count and update the count of each one. Now we do it all
in one query, and only publish the changed channels to the UI.
2023-07-03 11:41:51 +10:00
Martin Brennan 821cf201f5
FIX: ActiveModel::Types :array load error in production (#22377)
Followup to 3f1024de76

The ActiveModel::Types.register(:array) call for chat was
called too late in the Zeitwerk load order in production,
causing this error:

> `lookup': Unknown type :array (ArgumentError)
> raise ArgumentError, "Unknown type #{symbol.inspect}"
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

We need to load the type and register it manually before the rest
of the chat files are loaded via the engine and Zeitwerk.
2023-07-03 11:30:09 +10:00
Martin Brennan 3f1024de76
DEV: Refactor DM channel creation into new service pattern (#22144)
This will be used when we move the channel creation for DMs
to happen when we first send a message in a DM channel to avoid
a double-request. For now we can just have a new API endpoint
for creating this that the existing frontend code can use,
that uses the new service pattern.

This also uses the new policy pattern for services where the policy
can be defined in a class so a more dynamic reason for the policy
failing can be sent to the controller.

Co-authored-by: Loïc Guitaut <loic@discourse.org>
2023-07-03 10:18:37 +10:00
Martin Brennan 58a3cdc6ae
DEV: Try fix flaky chat navigation spec (#22356)
Followup to e57070af92,
try to check for href of link first before clicking.
2023-06-30 09:08:29 +08:00
Alan Guo Xiang Tan e57070af92
DEV: Skip a flaky system test (#22354)
This has been flagged by our internal system as well and has been
failing on CI. Skip this for now to improve the stability of our system
test runs while we figure out why it is flaky.
2023-06-30 07:35:44 +08:00
Joffrey JAFFEUX ea0b8ca38c
FEATURE: allows to enable/disable threading in UI (#22307)
Enabling/Disabling threading has been possible through command line until now. This commit introduces two new UIs:

- When creating a channel, it will be available once the category has been selected
- On the settings page of a channel for admins
2023-06-29 07:19:12 +02:00
Martin Brennan 1194ed10e1
FEATURE: Track last_viewed_at datetime for channel members (#22294)
Whenever a user opens a channel or marks it read, we now
update the last_viewed_at datetime for that channel membership
record. This is so we will be able to show thread unread indicators
in the channel sidebar that clear independently of the main thread
unread indicators. This unread functionality will follow in another
PR.
2023-06-29 09:22:17 +10:00
Martin Brennan 58c14ba0f9
DEV: Remove AJAX usage in chat-channel model (#22320)
Addressing TODO about using chatApi in the ChatChannel model,
but since it's a model we cannot easily use the chatApi service.
The model function is only called in one place so we may as well
just move the call there since the component can use chatApi
2023-06-29 09:21:28 +10:00
Martin Brennan 58c8f91d9a
DEV: Use same excerpt everywhere in chat (#22319)
Followup to c6b43ce68b

We can just use the rich excerpt everywhere since we know
we don't need text_entities -- that introduced security issues
just to fix a spec.
2023-06-29 09:20:20 +10:00
Martin Brennan ccdc0822a8
DEV: Fix flaky thread navigation spec (#22323)
Introduced in cec68b3e2c,
this is flaky because if you click the back button before
the route is fully transitioned to the loaded thread,
we end up going to the history _before_ the thread list,
which ends up being the channel.

We need to make sure that everything is loaded for the
thread first, meaning the skeleton is not there.

Also exclude some noise from the capybara logs (image load failures)
2023-06-28 17:20:05 +10:00
Martin Brennan c4c566846d
DEV: Get rid of old chat TODOs (#22324)
These are all well-known things we need to deal with
(e.g. scrolling and granular read in thread panel) or just
unnecessary to keep around.
2023-06-28 17:16:03 +10:00
Martin Brennan 41ebbab4ff
FIX: Chat threads N1 (#22322)
Followup to 1526d1f97d

This commit fixes an N1 for mentions/user status
when querying chat threads. This only happened if
any of the thread OMs had mentions.
2023-06-28 15:41:51 +10:00
Martin Brennan 1526d1f97d
FEATURE: Sort thread list by unread threads first (#22272)
* FEATURE: Sort thread list by unread threads first

This commit changes the thread list to show the threads that
have unread messages at the top of the list sorted by the
last reply date + time, then all other threads sorted by
last reply date + time.

This also fixes some issues by removing the last_reply
relationship on the thread, which did not work for complex
querying scenarios because its order would be discarded.

* FIX: Various fixes for thread list loading

* Use the channel.threadsManager and find the channel first rather
  than use activeChannel in the threads manager, otherwise we may
  be looking at differenct channels.
* Look at threadsManager directly instead of storing result for threads
  list otherwise it can get out of sync because of replace: true in
  other places we are loading threads into the store.
* Fix sorting for thread.last_reply, needed a resort.
2023-06-28 13:14:01 +10:00
Martin Brennan cec68b3e2c
FEATURE: Conditionally change back button route for thread (#22129)
When clicking back from a thread, we want to either go back to the
channel if the thread was opened from an indicator, or to the thread
list if we opened it from there. Since ember doesn't give a nice way
to get the previous route, we need to store this ourselves. We only
do this on mobile, on desktop we just follow existing behaviour.

Also implements a chat router history.

---------

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-06-28 09:58:47 +10:00
Jarek Radosz a6bd3994f3
UX: Align chat separators, increase mobile chat width (#22298) 2023-06-27 18:49:45 +02:00