Commit Graph

2333 Commits

Author SHA1 Message Date
Joffrey JAFFEUX 5abe98afb5
DEV: faster browse page spec (#21814) 2023-05-29 23:21:10 +02:00
Martin Brennan c57ae992b3
FIX: Page size edge case for null last_read_message_id (#21811)
Followup 55ef2d0698.

In the cases where the user has no last_read_message_id for
a channel, we want to make sure that a page_size is set for
the ChannelViewBuilder + MessagesQuery, otherwise we end up
loading way more messages than needed (the additional message
loading was fixed in the last commit).
2023-05-29 20:12:01 +02:00
Joffrey JAFFEUX 4ce8ea7496
DEV: adds sendChatMessage client API (#21783)
Usage:

```
api.sendChatMessage(channelId, message, { threadId: 6 });
```
2023-05-29 18:41:12 +02:00
Alan Guo Xiang Tan 7218da7510
DEV: Fix and improve chat system test for editing name and slug (#21810)
This commit introduces a couple of changes:

1. When editing a chat channel's slug, we were using `this.model.set("title", title)` when the `set`
   function does not exist. This was actually throwing the error in the
   "can edit slug" system test where the modal was not closed after
   saving and was flashing an error.

2. Introduce `PageObjects::Pages::ChatChannelAbout` and
   `PageObjects::Modals::ChatChannelEdit` page object to encapsulate
   logic better.
2023-05-29 18:00:59 +02:00
Martin Brennan 72e46b98a9
FIX: Create original message user thread membership (#21808)
When a thread is created / a new message is created in the
thread, we want to make sure that the original message user
has a membership for that thread, otherwise they will not
receive unread indicators for messages in the thread.
2023-05-29 17:37:17 +02:00
Joffrey JAFFEUX 55ef2d0698
FIX: auto fill was not happening on first load (#21809)
This commit attempts to fix the case where the messages loaded initially don't fill the screen. It would prevent user to scroll and as a result to load more.

There are multiple fixes in this commit:
- the main fix is removing this code which was preventing the actual fill:

```javascript
        // prevents an edge case where user clicks bottom arrow
        // just after scrolling to top
        if (loadingPast && this.#isAtBottom()) {
          return;
        }
```

- ensures we always give a page site to the `chatApi.channel(...)` call if we have one, in the current state when `fetchFromLastRead` was `true` we would not set `args.page_size`
- ensures the `query_paginated_messages` is having a valid page size, which is not nil and not > `MAX_PAGE_SIZE`
- write a spec for the autofill, it was a challenging spec to write but it should give us the confidence we need here
2023-05-29 17:34:44 +02:00
chapoi 5bf2dca24a
UX: add support for flagged chat message in reviewqueue (#21802)
* UX: add support for flagged chat message in reviewqueue

* correctly init a chat message object

---------

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-05-29 10:02:02 +02:00
Joffrey JAFFEUX 9215de3af7
FIX: ensures chat-thread is not overflowing (#21782) 2023-05-29 09:55:50 +02:00
Martin Brennan 6ddd17a756
DEV: Remove old ChatController routes for messages & lookup (#21723)
Since 5cce829 and the new
channel view builder, we have no need of these obsolete
routes which have way too much logic in the controller, which
has been superseded by the view builder anyway.

Remove the routes and update the channel message loading to use it.
2023-05-29 09:37:10 +02:00
Martin Brennan 7a9514922b
FEATURE: Improving thread list item and header (#21749)
* Moved the settings cog from thread list to thread and
  put it in a new header component
* Remove thread original message component, no longer needed
  and the list item and thread indicator styles/content
  will be quite different
* Start adding content (unread indicator etc.) to the thread
  list item and changing structure to be more like designs
* Serialize the last thread reply when opening the thread index,
  show in list and update with message bus
2023-05-29 09:11:55 +02:00
Joffrey JAFFEUX 705410ee48
DEV: ensures chat browse spec is waiting for search (#21789)
We were not checking that the page had finished loading resulting in various flakeys. This comlit also refactors the spec to use a proper page object.
2023-05-28 16:16:09 +02:00
Martin Brennan e4d628a931
FIX: Move thread storage out of chatApi.thread() call (#21773)
In some cases activeChannel can be null so this will error,
also it is limiting to have this code in chatApi. Instead
move to the threads manager, and also lean on channelsManager.find
to get the channel from the cache instead, which will not error.
2023-05-27 09:43:29 +02:00
Joffrey JAFFEUX d1f785e7de
UX: closes drawer on esc if input is not focused (#21772)
The current behavior is to close drawer when pressing escape inside the input.

After this change, first escape will blur the input, and second escape will close the drawer.

This commit also refactors the whole shortcuts for drawer system spec.
2023-05-26 18:48:45 +02:00
Joffrey JAFFEUX acb4c19eea
PERF: sends publish_new_channel only when not followed (#21755) 2023-05-26 17:13:05 +02:00
Martin Brennan 594636183d
FIX: N+1 query for chat message serializer on mentions (#21767)
Followup to d4a5b79592,
this introduced an N1 because every message in the list
we had to query users for the mentions and then the user's
status too. Instead we can just include both in Chat::MessagesQuery.
2023-05-26 12:44:03 +02:00
Martin Brennan 39d213a023
DEV: Add explicit order for chat mentioned users (#21765)
Followup d4a5b79592
which could sometimes flake on tests due to ordering issues.
2023-05-26 11:47:55 +02:00
Joffrey JAFFEUX 4676524094
FIX: do not attempt to mark as read a staged message (#21764)
This has not much impact as it would just be a silent 404 server side, but this is unnecessary work.
2023-05-26 11:00:48 +02:00
Martin Brennan ae74d5b32e
FIX: Chat deleted last read message and tracking state issues (#21762)
#### FIX: Do not use client lastReadMessageId when fetching channel messages

We had an issue where the following happened:

1. User opened channel and saw the last message, and we set the
   lastReadMessageId on the server and the client
2. User navigated to another channel
3. Another user deleted the message in the original channel
4. The first user navigated back to the original channel before
   the MessageBus event for the deleted message arrived, and got
   a 404 error because we were sending the deleted lastReadMessageId as
   target_message_id to the channel controller.

Instead of this which is a bit flaky and is hard to cover all
the issues for, instead we can pass a fetch_from_last_read boolean
param to the channels controller, and just get the user's
last_read_message_id straight from the database to use for the
target_message_id. This gets rid of any sources of race conditions
or lack of updates from MessageBus.

#### FIX: Include missing memberships for thread tracking publish

When we publish the channel/message tracking state for a
user and that message was a thread reply the publisher
was erroring because we were not telling Chat::TrackingStateReportQuery
to return missing memberships (which have zeroed out unread counts)
as well, which is what we do for the channel tracking state here.
Also just make sure that the TrackingStateReport does not error
when passed an ID it doesn't have data for.
2023-05-26 10:44:27 +02:00
Joffrey JAFFEUX 8d2ae1e4a6
DEV: waits for transition in move message spec (#21763)
This flakey has been very visible by the new headless chrome. The problem was that after moving a message we automatically redirect to the channel where the message has been moved to. However, we were not explicitly waiting for this transition and a result it could happen that we attempt to check the presence of the message on the channel page before the redirect actually happened.

The various naming changes are due to an early mistake we made in chat specs to use `chat` as the variable name for the page object which prevents to use the automatic path `chat.channel_path(...)`.

Co-authored-by: Alan Guo Xiang Tan <gxtan1990@gmail.com>
2023-05-26 10:04:37 +02:00
Joffrey JAFFEUX 0645f3628c
UI: minor spacing adjustment in message details (#21761) 2023-05-26 09:16:27 +02:00
Andrei Prigorshnev f0dfe56870
DEV: extract more logic into ParsedMentions class (#21729)
This doesn't change any behavior, only moves code around.
2023-05-25 15:41:22 +04:00
Martin Brennan c3779a371f
FIX: Serialize thread membership for user (#21743)
This commit follows up b6c5a2da08
by serializing the user's thread memberships in these cases:

1. When we do the initial channel fetch with messages, we get
   all threads and all the user's thread memberships for those
   messages.
2. When the thread list is fetched, we get all the user's memberships
   in that list.
3. When the single thread is fetched, either from opening it from
   the list, an OM indicator, or just from doing .find() on the
   manager when a new MessageBus message comes in

This will let us track the lastReadMessageId on the client, and
will also let us fix an issue where the unread indicator in the
channel header was incrementing for every thread that got a
new message, regardless of whether the user was a member.
2023-05-25 12:54:50 +02:00
Loïc Guitaut 0733dda1cb DEV: Add policy objects to services
This patch introduces policy objects to chat services. It allows putting
more complex logic in a dedicated class, which will make services
thinner. It also allows providing a reason why the policy failed.

Some change has been made to the service runner too to use more easily
these new policy objects: when matching a failing policy (or any failing
step actually), the result object is now provided to the block. This
way, instead of having to access the reason why the policy failed by
doing `result["result.policy.policy_name"].reason` inside the block,
this one can be simply written like this:
```ruby
  on_failed_policy(:policy_name) { |policy| policy.reason }
```
2023-05-25 12:34:00 +02:00
Jarek Radosz 22a6ae7e32
DEV: Remove `renderTemplate` from the styleguide (#21660)
Adds plugin API:

```js
import fidget from "../components/styleguide/molecules/fidget";

api.addStyleguideSection({
  component: fidget,
  id: "fidget",
  category: "molecules",
  priority: 0,
});
```

Removes notes. You can always add `<p class="styleguide-note">` to section components to annotate them.
2023-05-25 11:22:36 +02:00
Martin Brennan b6c5a2da08
FEATURE: Initial chat thread unread indicators (#21694)
This commit adds the thread index and individual thread
in the index list unread indicators, and wires up the message
bus events to mark the threads as read/unread when:

1. People send a new message in the thread
2. The user marks a thread as read

There are several hacky parts and TODOs to cover before
this is more functional:

1. We need to flesh out the thread scrolling and message
   visibility behaviour. Currently if you scroll to the end
   of the thread it will just mark the whole thread read
   unconditionally.
2. We need to send down the thread current user membership
   along with the last read message ID to the client and
   update that with read state.
3. We need to handle the sidebar unread dot for when threads
   are unread in the channel and clear it based on when the
   channel was last viewed.
4. We need to show some indicator of thread unreads on the
   thread indicators on original messages.
5. UI improvements to make the experience nicer and more
   like the actual design rather than just placeholders.

But, the basic premise around incrementing/decrementing the
thread overview count and showing which thread is unread
in the list is working as intended.
2023-05-25 09:56:19 +02:00
Joffrey JAFFEUX eae47d82e2
FEATURE: Apply hashtag styles to autocomplete (#21731)
This commit uses improvements done in 0b3cf83 to apply these styles to the autocomplete in composer.
2023-05-25 09:38:12 +02:00
Joffrey JAFFEUX 398eaf0429
FIX: prevents saving draft in incorrect channel (#21741)
This commit regroups 3 changes
- serializes channel ID and json draft when calling the debouncer instead of inside the debounced function, it seems very unlikely to happen, but in a case where the debouncing wouldn't be canceled and the new message not set yet, we could save the draft on an invalid channel
- cancel persist draft handler when changing channel
- ensures we exit early when channel is not set
2023-05-25 09:29:31 +02:00
Joffrey JAFFEUX 082921c4c8
FIX: correctly nullifies active message (#21739)
Very fast or specific mouse moves could allow to leave a message actions menu without reseting the active message. This commit should ensure we correctly catch this event.

No test as it's hard and not reliable to reproduce these in a test.
2023-05-25 09:28:46 +02:00
Joffrey JAFFEUX f3f841a018
DEV: implements initial messages component (#21727)
This should also make `message_notifications_with_sidebar_spec.rb` more resilient as we are now checking for `is-persisted` class instead of checking for the absence of `is-staged`.
2023-05-24 19:28:54 +02:00
Andrei Prigorshnev d6d5eae16f
DEV: temporarily skip tests tha fails on the build machine (#21725) 2023-05-24 18:49:00 +04:00
Joffrey JAFFEUX 4de1d3952b
FIX: improves draft for channels (#21724)
This commit attempts to correctly change draft when the channel changes. It moves responsibility to the composer instead of the channel.

A new service `chatDraftsManager` is being introduced here to allow finer control and pave the way for future thread draft support.

These changes also now allow an editing message to be stored as a draft.
2023-05-24 15:36:46 +02:00
Andrei Prigorshnev d4a5b79592
FEATURE: Add user status to inline mentions in chat (#20564)
This PR adds status to mentions in chat and makes those mentions receive live updates.

There are known unfinished part in this implementation: when posting a message, status on mentions on that message appears immediately, but only if a user used autocomplete when typing the message. If user copy and paste a message with mentions into chat composer, those mentions won't have user status on them.

PRs with fixes for both problems are following soon.

Preparations for this PR that were made previously include:
- DEV: correct a relationship – a chat message may have several mentions 0dcfd7ddec
- DEV: extract the logic for extracting and expanding mentions from ChatNotifier 75b81b6854
- DEV: Always create chat mention records fa543cda06
- DEV: better split create_notification! and send_notifications logic e292c45924
- DEV: more tests for mentions when updating chat messages e7292e1682
- DEV: extract updating status on mentions into a lib function e49d338c21
- DEV: Create and update chat message mentions earlier 35a414bb38
- DEV: Create a chat_mention record when self mentioning 2703f2311a
- DEV: When deleting a chat message, do not delete mention records f4fde4e49b
2023-05-24 16:55:20 +04:00
Jan Cernik 436b68a581
FIX: Do not preview chat channels to read-only users (#21700)
We want to simplify this case as it contains a lot of rabbit holes.
2023-05-24 14:05:20 +02:00
Martin Brennan 2b4dc97551
FIX: Do not error if admin/owner checks target message (#21721)
In the ChannelViewBuilder, we introduced a check to see if
the target message exists, which errors if the message has
been trashed. However if the user is the creator of the message
or admin then they are able to see trashed messages, so
we need to take this into account.
2023-05-24 12:01:41 +02:00
Martin Brennan 8076a84ff0
DEV: Reinstate Chat::MessageCreator skipped thread specs (#21718)
Followup to 7f85624a01

Fixes the specs that were skipped and reinstates them
2023-05-24 10:59:11 +02:00
Martin Brennan 177d8dfcd1
FIX: Improve chat membership update on deleted message (#21716)
Followup to c908eeacc9

Instead of using the latest message ID in the channel, which
could cause issues if you have an earlier last read message ID
that matches the deleted one, instead we use the first non-deleted
message that comes before the deleted message by ID.
2023-05-24 10:31:15 +02:00
Kris 5dd89e0b70
UX: iPad footer nav now included in header offset (#21699) 2023-05-23 17:49:19 -04:00
Joffrey JAFFEUX 8feee8149f
DEV: attempts to increase wait for a flakey spec (#21705) 2023-05-23 22:43:50 +02:00
Discourse Translator Bot 0d7a742bb9
Update translations (#21702) 2023-05-23 21:23:44 +02:00
Joffrey JAFFEUX 68364461f8
FIX: ensure sidepanel size is correctly applied when showing (#21701)
We were not correctly setting the widthStyle on insert.

Note this commit also changes throttling from 24ms to 50ms. 24ms was probably overkill.
2023-05-23 20:13:58 +02:00
Martin Brennan c908eeacc9
FIX: Update client lastReadMessageId on trashed message (#21697)
Followup ae3231e140, when a
message is trashed we already update the lastReadMessageId of
all users in the channel to the latest non-deleted message on
the server side. However we didn't propagate this to the client,
so in some cases when we did the following:

1. Delete the last message in the channel
2. Switch to another channel
3. Switch back to the original

We would get a 404 error from the target message ID being looked
up still being the old lastReadMessageId (now deleted) for the
user's channel membership.

All we need to do is send the last not-deleted message ID for
the channel (or thread) to all the member users.
2023-05-23 18:32:19 +02:00
Joffrey JAFFEUX bce56d843c
FIX: keeps panel size when changing content (#21698)
Before this commit the following actions would have shown the issue:
- visit a thread
- changes the width of the side panel
- open threads list
- the size has reverted to previous state

This was caused by the width change to not correctly be tracked.
2023-05-23 18:29:12 +02:00
Joffrey JAFFEUX c543a3207d
DEV: removes very frequent flakey spec (#21696) 2023-05-23 17:45:10 +02:00
Joffrey JAFFEUX 2a7dae51fa
DEV: attempts to make deleted spec not flakey (#21695)
It easier to check for presence in this case that to check for something not present, as depending on performance of the machine running the test this could take sometime to be changed and the test would fail.
2023-05-23 17:13:12 +02:00
Joffrey JAFFEUX 0764dc3452
FIX: cancel fetching messages after channel change (#21689)
This issue was especially visible in tests. the `@debounce(100)` was not cancelled when changing channel which was causing 404s as we were trying to load messages on a channel which was deleted as the channel has been destroyed at the end of the test.

This is still not a perfect solution, as we can only cancel the start of `fetchMessages`, but we can't cancel the actual `chatApi.channel` request which result can potentially happens after channel changed, which we try to mitigate with various checks on to ensure visible channel == loaded messages channel.

This commit also tries to make handler naming and cancelling more consistent.

<!-- NOTE: All pull requests should have tests (rspec in Ruby, qunit in JavaScript). If your code does not include test coverage, please include an explanation of why it was omitted. -->
2023-05-23 16:01:47 +02:00
Martin Brennan 6dc05dc535
DEV: Fix chat pagination spec (#21693) 2023-05-23 12:47:43 +02:00
Martin Brennan 3fed1abf2f
FIX: Page size check for thread messages (#21692) 2023-05-23 11:59:19 +02:00
Martin Brennan dad6b61807
DEV: Bump thread page size to 100 (#21691)
We don't have proper pagination yet so this
should help us in the interim.
2023-05-23 10:43:39 +02:00
Joffrey JAFFEUX b8bd3b07ef
DEV: regroups composer button code (#21690)
This commit makes it easier to ensure each button have a similar behavior: hover, disabled, focus...

It also removes some dead code (__inline-button) and fixes a bug where the emoji button didnt have the right un-focused color (it was more visible than it should.
2023-05-23 10:12:03 +02:00
Martin Brennan 0b3cf83e3c
FIX: Do not cook icon with hashtags (#21676)
This commit makes some fundamental changes to how hashtag cooking and
icon generation works in the new experimental hashtag autocomplete mode.
Previously we cooked the appropriate SVG icon with the cooked hashtag,
though this has proved inflexible especially for theming purposes.

Instead, we now cook a data-ID attribute with the hashtag and add a new
span as an icon placeholder. This is replaced on the client side with an
icon (or a square span in the case of categories) on the client side via
the decorateCooked API for posts and chat messages.

This client side logic uses the generated hashtag, category, and channel
CSS classes added in a previous commit.

This is missing changes to the sidebar to use the new generated CSS
classes and also colors and the split square for categories in the
hashtag autocomplete menu -- I will tackle this in a separate PR so it
is clearer.
2023-05-23 09:33:55 +02:00