Commit Graph

2628 Commits

Author SHA1 Message Date
Joffrey JAFFEUX 65d61b87c1
FIX: prevents back history loop (#22001)
The following case would create the perception of a broken back button on desktop:

- open discourse on home page
- click chat button in header
- hit back button
- observes that we are still on the channel didn't navigate to homepage as we would have expected

The back button is actually working but it's in a loop. We were doing a `transitionTo` after finding the ideal channel to show, so the browser history would look something like this:

- home
- chat index
- channel page

When hitting back, we would go to chat index which would run the same logic and transition us to channel page.

This change will use `replaceWith` to replace the chat index step by the channel step, this way our history will now look like this:

- home
- channel page

Hitting back will now correctly bring us to home.
2023-06-08 14:35:29 +02:00
Joffrey JAFFEUX 6513ca69da
UX: improves chat message long press and touch (#21984)
This commit attempts to refactor our long press logic to make it more resilient and precise.

With this improvement two very UX/UI changes have been made:
- scale animation on long press
- prevents click on reaction to propagate to the message which would cause the active state of the message to trigger
2023-06-08 08:21:32 +02:00
Martin Brennan 482ef0782d
FIX: Do not allow blank chat messages (#21968)
This fixes an issue where a user could send an empty
string as a chat message .e.g '   ' and the message would
be posted. We don't want this, we need to strip the message
first before validating for length etc.
2023-06-08 16:06:09 +10:00
Martin Brennan e48750281e
FIX: Pasting files into chat was not working (#21995)
Followup to e6c6c342d9,
we missed one part of this refactor which was to give
the correct composer element reference to ChatComposerUploads.
Without this the pasteEventListener for uploads was not
bound so uploading via paste did not work.

I tried to test this, and though I can write binary/text to
the clipboard and paste it into the composer, it does not
seem to be possible to end up with a paste event that
has clipboardData.files filled in, which is what is used
for the uploads. I think this is a restriction of JS
generally, and there doesn't seem to be a way to work around
it, so unfortunately we have to have no test for this still.
2023-06-08 13:03:55 +10:00
Joffrey JAFFEUX 699f3e7014
FIX: correctly set value on textarea interactor (#21990)
This would mostly work without it by mutation but could cause subtle bugs.
2023-06-08 01:21:30 +02:00
Bianca Nenciu 10ee92656c
FIX: Send TL2 promotion message to correct user (#21978)
Usually, when a user is promoted to TL2 two messages are sent. The
first one is a system message 'tl2_promotion_message' which triggers a
'system_message_sent' Discourse event.

When the event is fired and if Discourse Narrative Bot is enabled, then
a second message is sent to the recipient of the first message. The
recipients was determined by looking at the list of users that can
access that topic and pick the last one. This method does not work if
'site_contact_group_name' site setting is set because it adds the group
in the list of recipients.

A solution to this problem would have been to select the last user in
the list of 'topic_allowed_users', but an even better solution is to
pass the name of the recipients when the 'system_message_sent'
Discourse event is fired.
2023-06-07 22:51:24 +03:00
Joffrey JAFFEUX e6c6c342d9
REFACTOR: composer/thread (#21910)
This commit contains multiple changes to improve the composer behavior especially in the context of a thread:

- Generally rename anything of the form `chatChannelThread...` to `chatThread...``
- Moves the textarea interactor instance inside the composer server
- Improves the focus state and closing of panel related to the use of the Escape shortcut
- Creates `Chat::ThreadList` as a component instead of having `Chat::Thread::ListItem` and others which could imply they were children of a the `Chat::Thread` component
2023-06-07 21:49:15 +02:00
Joffrey JAFFEUX 330137e7e4
FIX: Non-Interfering Backdrop Clicks (#21916)
Previously, there was an issue where closing the message actions menu on mobile would unintentionally trigger a click event on an element below it, such as a thread indicator or a reaction. With the recent fix, this problem has been resolved. Now, when you close the menu, it will no longer interfere with or activate any elements positioned underneath it.
2023-06-07 11:40:43 +02:00
chapoi 86facadec1
FIX: apply chat header icon indicator style to urgent only (#21967)
* FIX: apply chat header icon indicator style to urgent only

* UX: smaller padding
2023-06-07 06:42:51 +02:00
chapoi 9809103ed9
UX: fix number cutoff in header chat indicator (#21946)
In the chat header indicator, expand to a pill when the number reaches
N digits, and also display 99+ if the number is over 99.
2023-06-07 11:42:08 +10:00
Alan Guo Xiang Tan 41f8bff2c3
DEV: Remove superfluous `js: true` metadata (#21960)
Why this change?

It is very unlikely that we need to ever JS for system tests considering
that we rely on a JS framework on the frontend.
2023-06-07 09:26:58 +08:00
Martin Brennan 69eecf92d0
FIX: Use a default hashtag icon color for user with no permission (#21825)
One user can create a post or chat message with a hashtag they
have permission to use, but then when other users look at that
post they will see an empty space next to the hashtag because they
do not have the permission to load the colors in CSS classes for
the related category.

This fixes the issue by adding a default color with a special
CSS class if the user doesn't have permission to see the linked
channel/category on the hashtag.
2023-06-07 10:15:39 +10:00
Discourse Translator Bot 9661a8c214
Update translations (#21950) 2023-06-06 15:36:51 +02:00
Andrei Prigorshnev b7a66bd6ad
DEV: Use await when sending chat messages (#21915)
This is a follow-up to d086888, I forgot to update these places in that commit.
2023-06-06 13:58:15 +04:00
chapoi 8c4cbd748d
UX: fix greyed out add button in chat composer when focussed (#21947) 2023-06-06 11:18:50 +02:00
Joffrey JAFFEUX 95a51b7d8a
FIX: correctly set last message bus ids on resync (#21911)
Replaces `channel.meta.message_bust_last_ids` on full resync instead of restarting the subscriptions, which was moreover not using a correct id.
2023-06-02 18:06:13 +02:00
chapoi d40649c648
UX: chat channel header icons (#21887)
* UX: BEM fix for has-unreads

* UX: small refactor for chat channel header icons

* UX: refactor chat thread unread indicator

* UX: channel header thread icon hover styling

* DEV: Spec fixes

* UX: fix font + line-height

---------

Co-authored-by: Martin Brennan <martin@discourse.org>
2023-06-02 10:34:19 +02:00
Alan Guo Xiang Tan 876734bcb6
DEV: Partially revert d1924c7328 (#21895)
Just remove the assertions for now as they are a constant source of
tests flakiness.
2023-06-02 06:35:42 +08:00
Joffrey JAFFEUX 676b558265
FIX: correctly resubscribe after restart (#21891)
Few weeks ago we implemented `onPresenceChangeCallback` to re-sync chat channels state when going back to a long time inactive tab. This codepath however contained a bug as we were reseting all subscriptions but only restarting global subscriptions and not per channel subscriptions.

This commit should correctly ensure we correctly do so. It's sadly very hard to test time related changes in system specs.

Co-authored-by: Martin Brennan <mjrbrennan@gmail.com>
2023-06-01 19:00:54 +02:00
Alan Guo Xiang Tan d1924c7328
DEV: Update checks in chat channel and thread page objects (#21889)
What is the problem?

We were calling out to methods that calls `has_css?` or `has_selector?`
which returns a boolean. Since we are not using the return value, it
means the methods can be deemed unnecessary. However, we do want those
checks and this commit adds the necessarily assertions to make use of
the return values.
2023-06-01 22:31:01 +08:00
Andrei Prigorshnev bb21476f68
FIX: Do not add mentioned groups as mentioned users (#21867)
When a user type a message with mentions, the autocomplete popup 
may suggest users or groups. We were adding all these object to 
the `currentMessage.mentionedUsers` collection, while we should 
have been adding only users. A group added to that collection led to 
the error later when trying to update user status on mentions.
2023-06-01 15:55:59 +04:00
Andrei Prigorshnev d086888549
DEV: Make chatMessage.cook function async (#21829)
This will make it simpler to work with this code. This also can make this code more stable and increase stability of our test suite.

Cooked message now will be available immediately after cooking, it wasn't the case before:

    await message.cook();
    const cooked = message.cooked;


This also removes a call to `message.cook()` from message fabricator. Alternatively we may leave the call there and make the fabricator function async, but I fill it's better this way. If someone needs to test something related to cooked message, they can either pass cooked text to fabricator:

    message = fabricators.message({ cooked: "<p>cooked</p>" });

or call `message.cook()` after fabrication:

    message = fabricators.message({ message: "raw message" });
    await message.cook()
2023-06-01 13:39:32 +04:00
Alan Guo Xiang Tan 30e4ebd19b
Revert "DEV: Update checks in chat channel and thread page objects (#21875)" (#21883)
This reverts commit ddf4ecba04.

Causing a flaky test to appear:

```
main $ LOAD_PLUGINS=1 rspec plugins/chat/spec/system/chat/composer/shortcuts/channel_spec.rb

Randomized with seed 17765
.....F..

Failures:

  1) Chat | composer | shortcuts | channel when using ArrowUp when last message is staged does not edit a message
     Failure/Error: channel_page.send_message
       expected `#<PageObjects::Components::Chat::Messages:0x00007fe823ac1710 @context=".chat-channel">.has_message?({:persisted=>true, :text=>"2"})` to be truthy, got false

     [Screenshot Image]: /home/tgxworld/work/discourse/tmp/capybara/failures_r_spec_example_groups_chat_composer_shortcuts_channel_when_using_arrow_up_when_last_message_is_staged_does_not_edit_a_message_148.png
```
2023-06-01 16:59:03 +08:00
Andrei Prigorshnev 576d389ded
Add a test (#21866)
This adds a test for the fix made in 6c3a513.
2023-06-01 11:30:22 +04:00
Alan Guo Xiang Tan ddf4ecba04
DEV: Update checks in chat channel and thread page objects (#21875)
What is the problem?

We were calling out to methods that calls `has_css?` or `has_selector?`
which returns a boolean. Since we are not using the return value, it
means the methods can be deemed unnecessary. However, we do want those
checks and this commit adds the necessarily assertions to make use of
the return values.
2023-06-01 15:25:11 +08:00
Joffrey JAFFEUX 9ba333808f
FIX: prevents admins to be silenced (#21854)
Currently in chat it was possible to have TL4 users to flag admins and silence them, this change should ensure it's never possible.
2023-06-01 08:36:11 +02:00
Alan Guo Xiang Tan 6fec9628a4
DEV: Use `has_no_css?` instead of `!has_css?` (#21874)
If we're asserting that something is missing, we want to use
`has_no_css?` instead of `!has_css?` since `has_css?` will wait the full
capybara default wait time before return if the selector is not present.
2023-06-01 10:41:43 +08:00
Sam c2332d7505
FEATURE: reduce avatar sizes to 6 from 20 (#21319)
* FEATURE: reduce avatar sizes to 6 from 20

This PR introduces 3 changes:

1. SiteSetting.avatar_sizes, now does what is says on the tin.
previously it would introduce a large number of extra sizes, to allow for
various DPIs. Instead we now trust the admin with the size list.

2. When `avatar_sizes` changes, we ensure consistency and remove resized
avatars that are not longer allowed per site setting. This happens on the
12 hourly job and limited out of the box to 20k cleanups per cycle, given
this may reach out to AWS 20k times to remove things.

3.Our default avatar sizes are now "24|48|72|96|144|288" these sizes were
very specifically picked to limit amount of bluriness introduced by webkit.
Our avatars are already blurry due to 1px border, so this corrects old blur.

This change heavily reduces storage required by forums which simplifies
site moves and more.

Co-authored-by: David Taylor <david@taylorhq.com>
2023-06-01 10:00:01 +10:00
Joffrey JAFFEUX 7b7c4c383a
UX: followups to #1f37fe5 (#21859)
- ensures buttons are aligned to the bottom
- makes the emoji icon tertiary as initially intended
- correctly sets the icon scale of the sending button
2023-05-31 16:58:31 +02:00
chapoi 1f37fe5fa5
UX: chat composer buttons refactor + emoji (#21852)
- Made the emoji btn blue when composer is focused
- Moved everything chat-composer-button to its own file and BEM-ified it and making the choice to only work with our own is-disabled definition instead of with the attribute :disabled, for consistency
2023-05-31 15:12:35 +02:00
Joffrey JAFFEUX f189c20578
DEV: ensures thread list has finished loading (#21855)
This should fix this failure:

```
Failures:

  1) Thread list in side panel | full page when there are no threads that the user is participating in shows a message
     Failure/Error: measurement = Benchmark.measure { example.run }
       expected to find text "You are not participating in any threads in this channel." in "Community\nEverything\nMy Posts\nMore\nMessages\nInbox\nChannels\nRandom 25\nPersonal chat\nRandom 25\nShowing all messages\nOngoing discussions"
```

The screenshot failure was clearly showing the spinner still being present.
2023-05-31 15:04:34 +02:00
Joffrey JAFFEUX 80c18b97b4
FIX: uses DiscourseURL.routeTo for drawer transitions (#21850)
Calling `transitionTo` directly was bypassing various custom codepaths of core.
2023-05-31 10:44:26 +02:00
Joffrey JAFFEUX 473992bd36
DEV: introduces Chat::Thread::ListItem in styleguide (#21851) 2023-05-31 10:29:38 +02:00
Discourse Translator Bot 4e99ef3952
Update translations (#21827) 2023-05-31 09:15:16 +02:00
Joffrey JAFFEUX 7c4d229f37
FIX: applies getURL on both app and chat URLs (#21847) 2023-05-31 01:30:54 +02:00
Joffrey JAFFEUX 852086e888
FIX: correctly uses getURL to open full page (#21843) 2023-05-31 00:52:27 +02:00
Joffrey JAFFEUX 6c3a51328c
FIX: removes destroyed mentioned used (#21841)
This would generate a 500 as we would call id on a nil object.
2023-05-31 00:21:09 +02:00
Joffrey JAFFEUX 906e053f32
FIX: recover by showing drawer index on 404 (#21839)
If the drawer receives an unexpected route, attempt to show the index. This is probably a more serious issue with subfolder but should limit the effects.
2023-05-30 23:51:55 +02:00
Jarek Radosz 3569a48b2d
DEV: Rescue the timeout error for a better spec cleanup (#21826)
Rescuing them still makes timing-out tests fail but doesn't break `after` spec cleanup (which could trigger more errors) Using custom error class to avoid any other possible timeout-catching code.

Also:
* remove an unnecessary `.select { |x| x.size > 0 }`
* fix a typo in a test title
2023-05-30 19:14:54 +02:00
Joffrey JAFFEUX 111ac4c7f2
FIX: call composer reset with correct params (#21777)
We were calling reset without the proper params which was causing errors in the console. This commit does the following changes:

- ensures `composer.cancel()` is the only way to cancel editing/reply
- adds a `draftSaved` property to chat message to allow for better tests
- writes a spec to ensure the flow is correct
- adds more page objects for better tests
- homogenize the default state of objects on chat message

Co-authored-by: Martin Brennan <martin@discourse.org>
2023-05-30 18:37:30 +02:00
Joffrey JAFFEUX 67102f7e4e
UX: deletes a message when editing to blank (#21785)
Editing a message to an empty string and sending it, will delete it.

This commit also refactors a lot of channel/thread composer shortcuts specs.

---

This commit also includes various spec fixes which have been flakey while finishing this pull request.
2023-05-30 18:15:34 +02:00
Andrei Prigorshnev 6491be9f2b
DEV: fix and enable flaky specs (#21753)
These specs were disabled in 786f7503. While investigating this, I found out that at some point `:user_membership` got deleted. It's hard to tell why exactly without investing more time, but it seems using `let!` instead of `fab!` solves the issue.

If in the future we decide to investigate why these tests were flaky with `fab!` to reproduce the failure run:

    LOAD_PLUGINS=1 rspec --seed 46586  plugins/chat/spec/mailers/user_notifications_spec.rb
2023-05-30 14:25:14 +04:00
Martin Brennan 6ec6cfccf8
FEATURE: Chat thread header indicator improvements (#21807)
This changes the thread header positioning of the
unread indicator to match the designs based on the route:

1. When the channel is open, show the indicator of # unread
   threads with the icon
2. When the threads list is open, show no indicator since
   you are on the list and can see which threads are unread
3. When a single thread is open, show the unread threads
   indicator along with a left < back button, with a label
   to show that this goes back to ongoing discussions

Drawer changes to come in another PR.
2023-05-30 10:10:07 +02:00
Alan Guo Xiang Tan e7b55c11df
DEV: Speed chat channel system test (#21820)
Why is this change required?

In the `PageObjects::Components::Chat::Messages#has_no_message?` method,
it ended up calling `has_selector` when trying to assert that the
selector is not present. This is an anti-pattern which results in us
waiting the full Capybara default wait time
2023-05-30 12:44:47 +08:00
Alan Guo Xiang Tan 289fb8f29c
DEV: Remove unnecessary wait for chat transcript system test (#21819)
What is this change required?

In the `chat/spec/system/transcript_spec.rb` test, there is a helper
method that uses `page.has_css?` in a conditional but it do not
specify a wait time and hence the default Capybara default max wait
time is used. However, there is no need for us to be waiting here so
we specify the `wait: 0` option.
2023-05-30 12:44:19 +08:00
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
Joffrey JAFFEUX c3a3ede8cf
FIX: correct replying indicator padding (#21679) 2023-05-22 17:55:31 +02:00
Joffrey JAFFEUX bdfd80bfe0
UI: chat composer step 2 (#21641)
- few improved alignments
- displays emoji picker button inline on desktop
- keeps composer focused when focusing dropdown button
- align buttons to bottom when increasing height of textarea
- max-height of textarea is now linked to the height of the screen

Co-authored-by: chapoi <charlie@discourse.org>
2023-05-22 17:00:50 +02:00
Martin Brennan 5cce829901
DEV: Chat API channel#show changes for threading (#21632)
This commit moves message lookup and querying to the
/chat/api/channel/:id endpoint and adds the ability
to query the tracking state overview for threads as well
as the threads and thread tracking state for any thread
original messages found.

This will allow us to get an initial overview of thread
tracking for a user when they first enter a channel, rather
than pre-emptively loading N threads and tracking state
for those across all channels on the current user serializer,
which would be expensive.

This initial overview will be used in subsequent PRs to
flesh out the thread unread indicators in the UI.

This also moves many chunks of code that were in services
to reusable Query classes, since use of services inside
services is discouraged.
2023-05-22 13:59:46 +02:00
Jarek Radosz 7f85624a01
DEV: Fix plugin:spec task return code (#21661)
Regressed in eec10efc3d. It means that backend plugin spec failures in CI were not failing the spec suite.

Fixes recent regressions and skips two of them - to be handled next week.

---------

Co-authored-by: Andrei Prigorshnev <a.prigorshnev@gmail.com>
2023-05-19 16:17:02 +02:00
chapoi 4f8dbe345f
UX: add indicator for msg from currentUser (#21657)
* UX: add indicator for msg from currentUser

* move up a level
2023-05-19 11:33:56 +02:00
Jarek Radosz f2339d2d5b
DEV: Fix random typos (#21638) 2023-05-18 15:34:46 +02:00
chapoi 7444ab006d
UX: General chat composer tweaks (#21639)
- prevent hover on disabled state
- more contrast between focus and not focus for send button
2023-05-18 15:15:10 +02:00
Joffrey JAFFEUX ed123c7cec
FIX: adds missing margin on desktop draft message (#21637) 2023-05-18 14:40:37 +02:00
Joffrey JAFFEUX c1d3a6a205
FIX: ensures message has been added before scroll (#21636)
Wrap scroll to bottom inside a next block to ensure the message has correctly been added to the array before actually attempt to scroll.

This commit also removes an unnecessary line which was essentially adding the message two times with no real consequences as we are uniq on ID.
2023-05-18 13:50:09 +02:00
chapoi ab4e2bed84
UX: minor fix with new composer and reply/edit (#21634) 2023-05-18 12:04:14 +02:00
Andrei Prigorshnev 20a7192b4e
DEV: Avoid infinite calling of computeDatesSeparators() (#21616) 2023-05-18 09:53:40 +02:00
Penar Musaraj a25bb81a64
DEV: Improve manual color scheme toggle in styleguide (#21629) 2023-05-18 07:31:20 +02:00
Joffrey JAFFEUX 4c4401b726
FIX: various fixes to chat styleguide (#21617)
- uses current user as user for fabricators, allows for correct avatar image and presence indicator
- uses a non existing channel ID to avoid setting a draft of an existing channel
- attempts to make color toggle more reliable
2023-05-17 20:03:19 +02:00
Joffrey JAFFEUX 0c1efecddd
FIX: more resilient bottom of message check (#21613)
1.0 lenience might not be enough in rare cases and there are no real consequences to slightly increase it.
2023-05-17 18:05:18 +02:00
Joffrey JAFFEUX 44d28cd778
FIX: ensures replying indicator has limited height (#21614) 2023-05-17 18:03:15 +02:00
Joffrey JAFFEUX 60c67afba4
DEV: various improvements to devex on chat (#21612)
- Improves styleguide support
- Adds toggle color scheme to styleguide
- Adds properties mutators to styleguide
- Attempts to quit a session as soon as done with it in system specs, this should at least free resources faster
- Refactors fabricators to simplify them
- Adds more fabricators (uploads for example)
- Starts implementing components pattern in system specs
- Uses Chat::Message creator to create messages in system specs, this should help to have more real specs as the side effects should now happen
2023-05-17 17:49:52 +02:00
Joffrey JAFFEUX df2614c0fb
FIX: ensures chat composer docks to topic composer (#21610) 2023-05-17 11:16:03 +02:00
chapoi 4c476b42b0
UX: chat composer styling on focus (#21603) 2023-05-17 07:10:02 +02:00
Joffrey JAFFEUX 928fab1c4e
FIX: compensate for lack of replying indicator on draft (#21597)
As we don't have the spacing generated by the replying indicator, we need to manually add spacing.
2023-05-16 22:32:07 +02:00
Martin Brennan 009006893e
FIX: Sync channel tracking state properly on presence change (#21596)
Followup from 9953a6edd9,
which broke an issue fixed in e8d6277062.

In the refactor we did not update the place where we resync
channel tracking based on onPresenceChange to use the new
tracking object we added to the serializer, and to directly
update channel.tracking
2023-05-16 21:37:51 +02:00
Joffrey JAFFEUX 0881186bfd
UI: removes thread margins (#21595) 2023-05-16 21:28:25 +02:00
Joffrey JAFFEUX 2f73316104
FIX: followups to composer notch adjustments (#21592)
We had safe-area-inset-bottom still set at a wrong place which was causing issues but was also useful to some cases. This commit removes it and ensures the affected cases are corrected.
2023-05-16 20:05:56 +02:00
Discourse Translator Bot 791630f08b
Update translations (#21583) 2023-05-16 19:40:01 +02:00
Joffrey JAFFEUX 4bfd1fd998
FIX: allows notch to have composer bg color (#21589) 2023-05-16 18:46:14 +02:00
Joffrey JAFFEUX f45d1e6791
UX: implements new composer design (#21588)
This is only the first steps of a redesign

- redesigns the buttons to have a larger hitzone
- generally bigger composer
- clicking near textarea focuses the input
- relies on the fact that safe-area-inset-bottom is set globally and doesn’t need to be set in sub components
2023-05-16 17:17:12 +02:00
Joffrey JAFFEUX 230a71b264
FIX: show scrollbars under firefox in chat (#21587) 2023-05-16 16:44:15 +02:00
Penar Musaraj 56422ca8b8
FIX: Don't show duplicates in styleguide (#21582) 2023-05-16 09:27:15 -04:00
Martin Brennan 9953a6edd9
DEV: Rearchitect chat tracking state (#21550)
This moves chat tracking state calculation for channels
and threads into a central Chat::TrackingStateManager service, that
serves a similar purpose to the TopicTrackingState model
in core.

This service calls down to these query classes:

* ThreadUnreadsQuery
* ChannelUnreadsQuery

To get the unread_count and mention_count for the appropriate
channels and threads.

As well as this, this commit refactors the client-side chat
tracking state.

Now, there is a central ChatTrackingStateManager Ember Service
so all tracking is accessible and can be counted from one place,
which can also initialize tracking from an initial payload.

The actual tracking counts are now maintained in a ChatTrackingState
class that is initialized on the `.tracking` property of both channel and
thread objects.

This removes the attributes on UserChatChannelMembership and decoration
of said membership from ChannelFetcher, preferring instead to have an additional
object for tracking in the JSON.
2023-05-16 14:51:13 +02:00
Martin Brennan a2b12b6ace
FIX: Drawer styles for chat thread icon (#21577)
The spacing was not correct for this icon
in the drawer.
2023-05-16 12:49:19 +02:00
chapoi 7032733f10
FIX: Add new chat threads icon and move thread list button to right (#21575)
* DEV: add new thread icon

* FIX: Use new thread icon, fix typo in SVG

UX: move the thread list icon to the right of
the collapse button

---------

Co-authored-by: Martin Brennan <martin@discourse.org>
2023-05-16 11:48:01 +02:00
Joffrey JAFFEUX a3522a5937
FIX: chat height fixes (#21561)
- Correctly resize when sending a message on android
- Do not blur active element
- Update direct message creator height following changes
2023-05-15 22:00:03 +02:00
Joffrey JAFFEUX 94b95266ca
FIX: hides global notice on chat (#21557)
It's not necessary and we already hide create-topics-notice and bootstrap mode, and it's also annoying to get correct chat's height.
2023-05-15 17:08:05 +02:00
Joffrey JAFFEUX 4b15ba405c
FIX: moves chat height computation to a mixin (#21555)
This commit also removes safe-area-inset-bottom when keyboard is displayed to avoid having a taller than needed space between composer and replying indicator.
2023-05-15 15:53:18 +02:00
Joffrey JAFFEUX 660a40ca06
FIX: various fixes following channel height changes (#21553)
- apply height on threads list
- apply height on thread
- correctly applies env(safe-area-inset-bottom)
2023-05-15 14:39:11 +02:00
Joffrey JAFFEUX 5ce0697348
FIX: limits max height to viewport on channel only (#21539)
Before this commit chat was applying a fixed height on everything under the `/chat` route. It's only really needed on the channel page with the composer at the bottom of the page.

This commits makes the following changes:
- moves height limitation from `#main-outlet-wrapper` to `.chat-channel`
- makes browse channel page and members list page full height and rely on main document scrollbar
- adds height computation for draft header and direct message creator block to ensure the height is correct when creating a draft channel
- makes chat index full height to rely on the browser scrollbar. As a result the <kbd> + </kbd> button used on mobile to create a direct message as been moved out of `<ChannelsList>` into the chat index template
- sidebar height was relying on chat setting a max height, as a result the height computation of sidebar has been changed to work correctly, especially with an opened keyboard on mobile or ipad
2023-05-15 11:46:33 +02:00
Joffrey JAFFEUX 580f60d61d
Revert "DEV: attempts to fix flakey spec (#21547)" (#21549)
This reverts commit 64971e5972.
2023-05-15 08:18:18 +02:00
Joffrey JAFFEUX c8eb1a275c
UX: opens side panel early to avoid jitter (#21516)
Hard to write a test for this behavior, this is a micro optimisation which doesn’t change the behavior but only makes it smoother by happening right before async request.
2023-05-15 08:14:50 +02:00
chapoi 74f01b8cbd
UX: hide settings btn when disabled
Also sets lighter border on hover
2023-05-15 07:53:30 +02:00
Joffrey JAFFEUX 64971e5972
DEV: attempts to fix flakey spec (#21547)
The failure screenshot shows the message is on screen while the error is:

```
     Failure/Error: example.run
       expected to find text "My favorite message" in "Community\nEverything\nMy Posts\nMore\nMessages\nInbox\nChannels\nPolitics 1\nPersonal chat\nPolitics 1". (However, it was found 1 time including non-visible text.)
```

I expect the arrow element might e slightly hiding the link, but not 100% sure of this.
2023-05-15 07:52:02 +02:00
Daniel Waterworth 53d99d1a26
DEV: Skip flaky tests (#21534) 2023-05-15 07:51:25 +02:00
Joffrey JAFFEUX 3f2c16a8d7
FIX: do not set VH while zooming (#21538)
This was an optimisation I mistakenly removed from 4cfa78c3f3
2023-05-13 17:39:24 +02:00
Joffrey JAFFEUX 4cfa78c3f3
FIX: always listen on window resize (#21536)
When using `navigator.virtualKeyboard.overlaysContent = false` we can rely on using only the resize event. Also attempts to no over trigger `setProperty` when value didn't change.
2023-05-13 15:39:46 +02:00
Andrei Prigorshnev b85d057df4
FIX: ensures `all_mentioned_user_ids` is not used as identifier (#21491)
A follow-up to 54b2a85b. That commit didn't fix the issue because the to_notify hash that we return from the notify_edit method isn't used anywhere apart from tests (that's confusing, we're going to fix that soon).
2023-05-12 17:47:48 +04:00
Martin Brennan c1cde16966
FIX: Thread reply indicator overflow (#21529)
In some cases the thread reply count indicator
(e.g. 433 replies) would wrap to the next line.
2023-05-12 15:46:22 +02:00
Jarek Radosz d8e5426bba
FIX: Incorrect `PLUGIN_NAME` for "poll" (#21525)
This resulted in `Required plugin 'discourse_poll' not found` warnings in logs
2023-05-12 12:54:14 +02:00
Joffrey JAFFEUX e10b262eb9
DEV: fix flakey spec (#21515)
Similar fix to the one made in aab6fb13a0

Instead of checking last object, check against all modified objects in no specific order.
2023-05-11 23:27:26 +02:00
Joffrey JAFFEUX f20be4b092
FIX: prevents subscribing with an old id (#21509)
This issue was for example possibly causing the last visit indicator to be reset by `sent` messages events.

The following was happening:
- a user (bob) had a last message bus ID of 1 on a channel (id:1) subscription
- bob then go to another channel (id:2), unsubscribing from updates of channel (id:1)
- another user (laura) then send messages to channel (id:1)
- bob goes back to channel (id:1)

At this point we we doing in the same sequence:
- loading channel with messages, getting a new last message bus id
- subscribing to updates using the last known message bus id

Most of the times we were lucky enough for this to work (no events while away, or just got the new id in time...) but it was also very likely to do a double fetch of messages as MessageBus would think we were late.
2023-05-11 22:27:48 +02:00
Joffrey JAFFEUX e905de66ff
FIX: close panel earlier (#21512)
deactivate was happening too late and sometimes after we did reopen for next panel causing the panel to stay effectively closed
2023-05-11 21:15:31 +02:00
Andrei Prigorshnev f4fde4e49b
DEV: When deleting a chat message, do not delete mention records (#21486)
A chat message may be restored later, so we shouldn't be deleting `chat_mentions` records for it.

But we still have to remove notifications (see 082cd139).
2023-05-11 20:05:59 +04:00
Joffrey JAFFEUX 92bb845db2
FIX: messages selection with shift + click (#21506)
This commit fixes the shift+click multi selection in threads. We were not correctly using the manager of the message and would attempt to find messages in the channel instead of the thread.

The `activeThread` was also not correctly set sometimes.

Also adds tests for message selection in threads.
2023-05-11 17:52:53 +02:00
Andrei Prigorshnev 2703f2311a
DEV: Create a chat_mention record when self mentioning (#21438)
In the past, we create a `chat_mention` records only when we wanted to notify a user about a mention. Since we don't send notifications when a user mentioning himself, we didn't create a `chat_mention` records in those cases.

Now we use `chat_mentions` records in other scenarios too, so when a user is mentioning himself we want to:
1. Create a `chat_mention` record for that mention
2. Do not create a notification for that mention
2023-05-11 19:30:26 +04:00
Joffrey JAFFEUX 0c27baef76
FIX: keyboard on android (#21505) 2023-05-11 16:12:48 +02:00
Martin Brennan 26f9ccd8bb
FEATURE: Create and update thread memberships (#21501)
When the user sends a message in a thread, we want to
create a membership for them in the background (default
to notification level of Watching) so we can track whether
they have read the thread.

Then, for now since we don't have granular message reading/
scrolling in the thread panel, we just update the thread
last_read_message_id for the user to the latest reply in the
thread when they open the thread panel. This at least will
mark the thread as read.

In future PRs we want to show the blue dot indicator in various
places in the UI for unread threads which will also require
some MessageBus functionality.

This takes into account the same issue fixed for channels
in ae3231e140
2023-05-11 14:35:26 +02:00
Joffrey JAFFEUX 5b12d23b1d
FIX: rely only on one keyboard computation solution (#21492)
We were combining both solutions which was apparently causing issues from chrome 113 on Android at least.

The commit will now use `geometrychange` (android) only when available and fallback to `visualViewport` otherwise (iOS).
2023-05-11 08:58:29 +02:00
Joffrey JAFFEUX 55c4a550c1
FEATURE: chat-replying indicator for threads (#21485)
This feature adds the replying indicator in threads, it uses the same `/chat-reply/CHANNEL_ID` prefix than the channel composer replying indicator as we don't have specific right on threads ATM (if you can access channel, you can access thread). Thread will however use a presence channel name of the following format: `/chat-reply/CHANNEL_ID/thread/THREAD_ID`

This commit also simplifies the computation of `users` to eventually avoid a race-condition leading to a leak of the indicator in another channel/thread.

<!-- 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-11 08:02:04 +02:00
Joffrey JAFFEUX aab6fb13a0
DEV: fix flakey spec in handle_category_udpated (#21488) 2023-05-11 08:01:02 +02:00
Martin Brennan 616885895a
FIX: Chat NotificationLevels extension breaking in prod (#21484)
When setting DISCOURSE_ZEITWERK_EAGER_LOAD=1 to enable
eager loading the previous solution to adding chat_levels
to the core NotificationLevels would break with a module
loading error (c.f. cc2570fce3)

We don't actually _need_ to extend the core class, we can just
make our own for chat, let's do this instead.
2023-05-10 18:46:06 +02:00
Martin Brennan 79812db7d3
DEV: Fix double Chat:: module usage in chat models (#21483) 2023-05-10 17:51:46 +02:00
Martin Brennan 9b95a65dff
DEV: Fix thread excerpt word break (#21482)
Changing from break-all to break-word because otherwise
longer words (not just links) are split into separ
ate lines.
2023-05-10 17:20:02 +02:00
Martin Brennan cc2570fce3
DEV: Create UserChatThreadMembership table and model (#21481)
This will enable us to begin work on user tracking
state for a thread so we can show thread-specific
unreads and mentions indicators. In this case are following
the core notification_level paradigm rather than the solution
UserChatChannelMembership went with, and eventually we
will want to refactor the other table to match this as well.

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-05-10 17:19:48 +02:00
Joffrey JAFFEUX b713ae166f
FIX: excerpt overflow and children click events (#21473) 2023-05-10 15:07:43 +02:00
Martin Brennan 91c5658e9b
FIX: Handle deleted original message for thread index (#21470)
Since we have channel message retention which deletes
messages, we can end up with cases where the thread
is still around but the message is deleted. We will
handle the cascade delete in a different commit --
for now we will ensure the thread list lookup handles
this case and doesn't error.
2023-05-10 13:58:15 +02:00
Jan Cernik cbbaeb55b5
FIX: Don't autojoin users when they have ready-only permissions (#20213)
After this change, in order to join a chat channel, a user needs to be in a group with at least “Reply” permission for the category. If the user only has “See” permission, they are able to preview the channel, but not join it or send messages. The auto-join function also follows this new restriction.

---------

Co-authored-by: Martin Brennan <martin@discourse.org>
2023-05-10 08:45:13 -03:00
Joffrey JAFFEUX 3727c95f6f
Revert "DEV: Add configurable? helper to Plugin::Instance (#20767)" (#21469)
This reverts commit 3073e5cfb0.
2023-05-10 12:41:55 +02:00
Bianca Nenciu 3073e5cfb0
DEV: Add configurable? helper to Plugin::Instance (#20767)
This can be used to forcibly disable plugins.
2023-05-10 13:16:37 +03:00
Joffrey JAFFEUX c6b43ce68b
FEATURE: Thread list initial UI (#21412)
This commit adds an initial thread list UI. There are several limitations
with this that will be addressed in future PRs:

* There is no MessageBus reactivity, so e.g. if someone edits the original
   message of the thread it will not be reflected in the list. However if
   the thread title is updated the original message indicator will be updated.
* There is no unread functionality for threads in the list, if new messages
   come into the thread there is no indicator in the UI.
* There is no unread indicator on the actual button to open the thread list.
* No pagination.

In saying that, this is the functionality so far:

* We show a list of the 50 threads that the user has most recently participated
   in (i.e. sent a message) for the channel in descending order.
* Each thread we show a rich excerpt, the title, and the user who is the OM creator.
* The title is editable by staff and by the OM creator.
* Thread indicators show a title. We also replace emojis in the titles.
* Thread list works in the drawer/mobile.
2023-05-10 11:42:32 +02:00
Joffrey JAFFEUX 7a84fc3d9d
DEV: more resilient scroll to bottom spec (#21467)
The spec now checks we are in the state we expect to be before clicking bottom button. The bottom button could show while it's still loading and on slow systems cause failures.
2023-05-10 10:54:02 +02:00
Discourse Translator Bot a010c3495b
Update translations (#21455) 2023-05-10 00:48:10 +02:00
Joffrey JAFFEUX dacb605e98
DEV: more resilient upload spec (#21462)
Checking "uploading" string is tricky because it both takes time before showing, and when it will show it will show for a short period of time. I prefer to reduce the surface tested here while still getting some confidence out of it and making the test more reliable.
2023-05-10 00:33:40 +02:00
Joffrey JAFFEUX 44e650d175
FIX: prevents fast channel switching to cause an error (#21461)
`this.users` would end up being nil and `this.users.filter` would generate an exception.
2023-05-09 23:52:46 +02:00
Joffrey JAFFEUX e935d2bddb
FIX: minor thread changes on mobile (#21457)
- do not render sidepanel resizer as it's not usable on mobile
- removes 1px to the bottom spacing, this spacing won't be necessary once we implement chat-replying-indicator for thread
2023-05-09 22:38:44 +02:00
Joffrey JAFFEUX d1e4e7cd6f
FIX: more precise chat-replying-indicator (#21451)
- correctly subscribe/unsubscribe channel
- instantly changes users list
- adds a test for testing channel change
- rewrites tests to be less verbose
- ensures users is always an array
2023-05-09 13:25:33 +02:00
Joffrey JAFFEUX 54b2a85b27
FIX: ensures `all_mentioned_user_ids` is not used as identifier (#21452)
When making the list of users to notify we set `all_mentioned_user_ids` key on the `to_notify` Hash.

This hash will be passed around until the actual moment where we send the notifications:

```ruby
identifier_text =
  case identifier_type
  when :here_mentions
    "@here"
  when :global_mentions
    "@all"
  when :direct_mentions
    ""
  else
    "@#{identifier_type}"
  end
```

As not found `all_mentioned_user_ids` would end up being sent as `@all_mentioned_user_ids` which is obviously incorrect.

This commit is a direct fix to the issue and will remove the key as soon as we have used it sooner up in the chain.

This bug was reproducible when doing this sequence of events:

- create a message with a direct mention: `@bob hi`
- edit this message into a global mention `@all hi`
2023-05-09 13:00:19 +02:00
Joffrey JAFFEUX 8f27913ec1
FIX: no event when threading is disabled (#21439)
Every replies creates a thread, even when threading is disabled. This is how we ensure we can go back and forth. However, a message bus event should only be published when threading is enabled, otherwise frontend will attempt to display a thread which is not possible when disabled.

This fixes a silent background 404 when doing a reply in a direct message channel or a non threading enabled category channel.
2023-05-09 10:11:29 +02:00
Joffrey JAFFEUX bc847e54d4
DEV/ glimmerify chat-channel-status (#21445)
This commit also adds a component test for it and fixes a bug in `chat-channel-archive-status` `#getTopicURL` property which was incorrectly called as a function.
2023-05-09 09:22:25 +02:00
Joffrey JAFFEUX 3bc5c0ad18
FIX: makes mouse events passive (#21441) 2023-05-09 08:03:03 +02:00
Alan Guo Xiang Tan 9c39053d6f
FIX: Ensure order when moving chat messages to another channel (#21447)
What is the problem?

Previously, this was the query used to move change messages into another
channel.

```
INSERT INTO chat_messages(
  chat_channel_id, user_id, last_editor_id, message, cooked, cooked_version, created_at, updated_at
)
SELECT :destination_channel_id,
        user_id,
        last_editor_id,
        message,
        cooked,
        cooked_version,
        CLOCK_TIMESTAMP(),
        CLOCK_TIMESTAMP()
FROM chat_messages
WHERE id IN (:message_ids)
RETURNING id
```

The problem is that this incorrectly assumes that the insertion will be based on the order of `message_ids`. However, that
is not the case as PostgreSQL provides no such guarantee. Instead we need to explicitly order the messages to ensure
the right order of insertion.

This problem was discovered by a flaky test which exposed the non-guarantee order of insertion.
2023-05-09 10:37:12 +08:00
Joffrey JAFFEUX 6f26732551
UI: thread panel sizing/spacing on mobile (#21440)
The side panel on mobile is full screen. As a result we need to tweak spacing and sizing to make it correctly full screen like the channel.
2023-05-09 00:17:42 +02:00
Joffrey JAFFEUX 24cc3ac7dc
DEV: more resilient spec (#21436)
Allows more time for the members to be appended in tests
2023-05-08 21:10:57 +02:00
Andrei Prigorshnev c45fff9405
DEV: group mentions related specs into context (#21434) 2023-05-08 21:18:11 +04:00
Joffrey JAFFEUX 22521d3428
DEV: converts models to native classes (#21418)
- `ChatChannel`
- `UserChatChannelMembership`

Also creates a new `chat-direct-message` model used as the object for the`chatable` property of the `ChatChannel` when the `ChatChannel` is a direct message channel. When the chatable is a category a real `Category` object will now be returned.

Archive state of a `ChatChannel` is now hold in a `ChatChannelArchive` object.
2023-05-08 18:24:41 +02:00
Jarek Radosz fdf38335ab
DEV: Correct the app-events service injections (#21413) 2023-05-08 10:48:56 +02:00
Joffrey JAFFEUX 5c9efea480
FIX: correct link on original message (#21415)
Ensures that using copy link on the the original message of a thread in a channel, copies the link to the channel and not the thread.
2023-05-08 09:10:10 +02:00
Joffrey JAFFEUX e8d6277062
FIX: attempts to reconciliate tracking state (#21416)
After a long time with no activity or hidden browser (2.5 minutes), the app will re-sync the chat user-tracking-state to ensure unreads are synced.

We might also need to couple this later with more recovering logic.
2023-05-08 09:09:35 +02:00
Joffrey JAFFEUX cb5e5f3e5b
UX: groups deleted messages (#21411)
Any continuous series of deleted messages will now be grouped into one single expand button.
2023-05-05 17:08:33 +02:00
Martin Brennan ae3231e140
FIX: Incorrect unread count shown in channel when message deleted (#21410)
When we were deleting messages in chat, we would find all of
the UserChatChannelMembership records that had a matching
last_read_message_id and set that column to NULL.

This became an issue when multiple users had that deleted message
set to their last_read_message_id. When we called ChannelUnreadsQuery
to get the unread count for each of the user's channels, we were
COALESCing the last_read_message_id and returning 0 if it was NULL,
which meant that the unread count for the channel would be the total
count of the messages not sent by the user in that channel.

This was particularly noticeable for DM channels since we show
the count with the indicator in the header. This issue would disappear
as soon as the user opened the problem channel, because we would then
set the last_read_message_id to an actual ID.

To circumvent this, instead of NULLifying the last_read_message_id in
most cases, it makes more sense to just set it to the most recent
non-deleted chat message ID for the channel. The only time it will
be set to NULL now is when there are no more other messages in the
channel.
2023-05-05 15:28:48 +02:00
Andrei Prigorshnev 35a414bb38
DEV: Create and update chat message mentions earlier (#21388)
We need to create and update `chat_mentions` records for messages earlier. They should be created or updated before we  call `Chat::Publisher.publish_new!` `Chat::Publisher.publish_edit!` to send the message to message bus subscribers).

This logic is covered with tests in `message_creator_spec.rb`, `message_updater_spec.rb`, `notifier_spec.rb` and `notify_mentioned_spec.rb`.

See the commits history for steps of refactoring.
2023-05-05 15:47:07 +04:00
Joffrey JAFFEUX 78616404ce
UX: scroll to bottom when message is staged (#21408)
Since our recent change of inverting thread scrolling direction it feels more responsive to scroll down in thread panel as soon as message is staged and not after it's actually persisted.
2023-05-05 13:14:13 +02:00
Joffrey JAFFEUX e88b997153
Revert "UX: preloads a thread when hovering thread indicator (#21406)" (#21407)
This reverts commit 028dba144d.
2023-05-05 12:06:30 +02:00
Joffrey JAFFEUX 028dba144d
UX: preloads a thread when hovering thread indicator (#21406)
When hovering a thread indicator in a channel we will now append two `<link rel="preload" ...>` to the `<head>` of the document. Clicking on it should be significantly faster.

Co-authored-by: Martin Brennan <martin@discourse.org>
2023-05-05 11:18:03 +02:00
Joffrey JAFFEUX 187b59d376
UX: implements draft threads (#21361)
This commit implements all the necessary logic to create thread seamlessly. For this it relies on the same logic used for messages and generates a `staged-id`(using the format: `staged-thread-CHANNEL_ID-MESSAGE_ID` which is used to re-conciliate state client sides once the thread has been persisted on the backend.

Part of this change the client side is now always using real thread and channel objects instead of sometimes relying on a flat `threadId` or `channelId`.

This PR also brings three UX changes:
- thread starts from top
- number of buttons on message actions is dependent of the width of the enclosing container
- <kbd>shift + ArrowUp</kbd> will reply to the last message
2023-05-05 08:55:55 +02:00
Alan Guo Xiang Tan 7ff8e5580f
DEV: Speed up chat plugin system tests (#21399)
See e323628d8a for more details.

This commit speeds up the tests by roughly 10 seconds locally where the
default wait time is 2 seconds. On CI, this speeds up the tests by 20
seconds where the default wait time is 4 seconds.
2023-05-05 08:16:23 +08:00
Martin Brennan b2a727336e
FIX: Thread mention read state and notification links (#21385)
* FIX: Link to thread for mentions inside thread

When mentioning a user in a thread, when we send the
notification and display it in the UI we want the URL
of the notification to point to the thread URL to open
the panel, rather than the main channel which is confusing.

For now, we don't have a way to highlight the linked-to message
in the thread, we can revisit this later.

* FIX: Mark mention notifications read when thread opens

Since we have no scrolling/message visibility/thread membership
for now, when a user opens the thread panel we just want to mark
all mention notifications relating to messages in the thread
for the user as read.
2023-05-04 17:28:51 +02:00
Jan Cernik 4e0563a8fe
FIX: Remove double escaped Vimeo titles (#21368)
og_data is already escaped
2023-05-04 07:54:00 -03:00
Joffrey JAFFEUX b46899e5fa
FIX: more resilient dates separators computation (#21370)
In the past this was happening on scroll so we needed to be very conservative here. Also, if we wait too much theres a visible element flashing so this PR attempts to compute right away, and a second time 100ms later in case the first one happened too early.
2023-05-03 21:29:18 +02:00
Joffrey JAFFEUX ed077cf3f1
DEV: after has been proven problematic in other tests (#21358)
It seems more reliable to revert state at the end of the it block. In another PR I noticed that the network state was leaking in other tests when I was reverting in the after block.

Also trashes a suspicious spec.
2023-05-03 11:03:38 +02:00
Jan Cernik 8e590dc5d4
FIX: Add thumbnails for Vimeo unlisted lazy videos (#21343)
Previously, the image for the thumbnail was taken from the oembed endpoint.
Since these images are not available for some unlisted videos,
the thumbnails are now sourced from Open Graph instead.
2023-05-02 23:32:12 -03:00
Joffrey JAFFEUX e66f640234
FIX: ensures page height is correct on ipad + hub (#21345)
The previous style was not being in each case, this should correctly fix it.
2023-05-02 23:00:16 +02:00
Jan Cernik bfd3bd5516
FIX: ChatComposerMessageDetails icon was always edit (#21340) 2023-05-02 14:31:42 -03:00
Joffrey JAFFEUX 616f4a1118
FIX: disables send btn while uploads in progress (#21298)
Before this fix you could press send while upload was in progress and lose it as it was not yet uploaded.
2023-05-02 18:11:40 +02:00
Discourse Translator Bot 6bbf9a0bcc
Update translations (#21334) 2023-05-02 17:39:33 +02:00
Joffrey JAFFEUX 69a72015f0
UX: resets active message when scrolling (#21305)
This will avoid the messages actions floating around while scrolling. Note it's not testing the thread counterpart yet as I have a plan in mind to tests channels and threads in a clean way in the near future.
2023-05-02 14:21:30 +02:00
Joffrey JAFFEUX 6c90747dea
FIX: correctly use types for reviewables type (#21333)
Before this fix if the underlying model of a reviewable was changed, the filter wouldn't work anymore as it was expecting a 1:1 relation between filter type and model name.

This commit also relies on the `Reviewable.types` array to check against valid types instead of a regex not checking much.

Finally this commit adds a spec to ensure chat reviewables are listable from the review index page.
2023-05-02 14:21:14 +02:00
Joffrey JAFFEUX 3e50a81d96
DEV: potential flakey fixes (#21309) 2023-04-29 00:15:51 +02:00
Joffrey JAFFEUX cd24656570
DEV: potential flakey specs fixes (#21307) 2023-04-28 22:06:27 +02:00
Joffrey JAFFEUX 0239e88809
UX: cook message before sending edit (#21303)
This allows for instant feedback in the UI.
2023-04-28 20:11:57 +02:00
Joffrey JAFFEUX 290bd975c5
FIX: correctly differentiates channel/thread upload inputs (#21301)
Prior to this fix uploads event could end up in the wrong textarea. This will most importantly allow pasting an image in the thread composer.

Also fixes a minor padding issue on thread when uploads are associated to it.
2023-04-28 19:08:55 +02:00
Joffrey JAFFEUX 69696843c6
FIX: allows youtube embeds to respect the `t` param (#21295) 2023-04-28 15:46:27 +02:00
Joffrey JAFFEUX 1403064835
FIX: correctly homogenizes panels min width (#21294)
`.chat-channel` had `300px` min width, when `.chat-drawer` was `250px`, resulting in overflowing channel when in drawer. This commits ensures the limits are always set at `250px`.
2023-04-28 13:05:00 +02:00
Joffrey JAFFEUX e4029bfab8
FIX: chat height was incorrect on ipad (#21289) 2023-04-28 10:51:23 +02:00
chapoi f29f131387
UX: composer use BEM + small tweaks to enabled/disabled styling (#21246)
- using BEM notation
- making animation linear instead of default ease
- small tweaks to composer state (disabled/send-disabled/send-enabled)
- fixing bug with disabled composer on mobile
2023-04-28 10:24:49 +02:00
Joffrey JAFFEUX e5ec0b84a9
DEV: fix a spec and skips another one (#21277)
- It seems that `window_opened_by/within_window` it not reliable in our current setup/test
- System specs should avoid at all cost to rely on backend state, any change should be visible one way or another on the front to be properly tested
2023-04-27 09:43:26 +02:00
Joffrey JAFFEUX 7f803a0335
FIX: ensures thread is cleared when closing it (#21264) 2023-04-26 20:37:58 +02:00
Joffrey JAFFEUX 36db953bc6
FIX: cancels saving draft when composer is destroyed (#21260) 2023-04-26 19:42:57 +02:00
Joffrey JAFFEUX d381629655
FIX: correct border color of message actions (#21261)
This is a followup of 1372c5c435
2023-04-26 19:42:04 +02:00
Jarek Radosz a1b35601fc
FIX: Improve chat route cleanup (#20557)
1. `this.chat.activeChannel = null` was being done in twice
2. using `willTransition()` and checking transition.to.name prefix for route cleanup rather than using `deactivate()` was unnecessarily verbose and could be premature (if something aborted the transition you'd end up in a broken state)
3. `activeChannel` on Chat service can be null, check for that before accessing
2023-04-26 18:18:23 +02:00
Joffrey JAFFEUX 6487c8ef24
FIX: properly respects chat_minimum_message_length (#21256)
Before this fix we were only considering `>` and not `>=`, this also adds two tests.
2023-04-26 17:35:35 +02:00
Joffrey JAFFEUX 731282c2ec
FIX: attempts to make cooking less order dependent (#21253)
It's very hard to repro but under specific circumstances I suspect it was possible for this sequence to happen:

- set message TEXT
- cooking starts
- set message COOKED through another mean (like a message bus)
- the cooking started sooner finished and erases the cooked set at the step before causing the message to have the incorrect cooked
2023-04-26 16:50:38 +02:00
chapoi 1372c5c435
UX: onebox/blockquote/chatreaction slight accent colour change (#21252) 2023-04-26 15:11:20 +02:00
Joffrey JAFFEUX e495a2fc3f
DEV: Enable parallel system specs in GitHub actions CI (#21251)
Also skips/improves few flakey specs
2023-04-26 13:02:19 +02:00
Joffrey JAFFEUX 427fa36edd
FIX: generates markdown from pasting link (#21241)
After removing `TextareaTextManipulation` from `ChatComposer` and using `TextareaInteractor` as a proxy, one function has been forgotten: `paste(event)` which is not available in glimmer components anymore, and even less avaiable now that the mixin is not tied to a component anymore but a real DOM node. As a solution we now add a manual paste event listener which will call `paste(event)`.
2023-04-26 10:05:48 +02:00
Joffrey JAFFEUX 6ea4854c51
UX: displays channel title in document title (#21242) 2023-04-26 09:09:07 +02:00
Discourse Translator Bot 76176eda9d
Update translations (#21145) 2023-04-25 17:23:21 +02:00
Joffrey JAFFEUX a052ecee62
FIX: safeguard in case the message is active during transition (#21235)
Prior to this fix, we could sometimes still have an active message while the DOM node was already removed.
2023-04-25 13:16:55 +02:00
Joffrey JAFFEUX 7c9b8c42c1
FIX: allows composer to expand (#21234)
The fixed height was preventing the underlying textarea to expand (up to 125px height) when adding new lines with shift + enter
2023-04-25 11:00:18 +02:00
Joffrey JAFFEUX bf886662df
UX: improves composer and thread panel (#21210)
This pull request is a full overhaul of the chat-composer and contains various improvements to the thread panel. They have been grouped in the same PR as lots of improvements/fixes to the thread panel needed an improved composer. This is meant as a first step.

### New features included in this PR

- A resizable side panel
- A clear dropzone area for uploads
- A simplified design for image uploads, this is only a first step towards more redesign of this area in the future

### Notable fixes in this PR

- Correct placeholder in thread panel
- Allows to edit the last message of a thread with arrow up
- Correctly focus composer when replying to a message
- The reply indicator is added instantly in the channel when starting a thread
- Prevents a large variety of bug where the composer could bug and prevent sending message or would clear your input while it has content

### Technical notes

To achieve this PR, three important changes have been made:

- `<ChatComposer>` has been fully rewritten and is now a glimmer component
- The chat composer now takes a `ChatMessage` as input which can directly be used in other operations, it simplifies a lot of logic as we are always working a with a `ChatMessage`
- `TextareaInteractor` has been created to wrap the existing `TextareaTextManipulation` mixin, it will make future migrations easier and allow us to have a less polluted `<ChatComposer>`

Note ".chat-live-pane" has been renamed ".chat-channel"

Design for upload dropzone is from @chapoi
2023-04-25 10:23:03 +02:00
David Taylor 26b7f8a63b
DEV: Improve add_to_serializer include_* options (#21220)
- Move the old '`define_include_method`' arg to a `respect_plugin_enabled` kwarg

- Introduce an `include_condition` kwarg which can be passed a lambda with inclusion logic. Lambda will be run via `instance_exec` in the context of the serializer instance

This is backwards compatible - old-style invocations will trigger a deprecation message
2023-04-24 12:17:51 +01:00
Natalie Tay e1bc43aa31
Revert "DEV: Improve `add_to_serializer` `include_*` options (#21073)" (#21219)
This reverts commit 4895e76ef7.
2023-04-24 16:14:52 +08:00
David Taylor 4895e76ef7
DEV: Improve `add_to_serializer` `include_*` options (#21073)
- Move the old '`define_include_method`' arg to a `respect_plugin_enabled` kwarg
- Introduce an `include_condition` kwarg which can be passed a lambda with inclusion logic. Lambda will be run via `instance_exec` in the context of the serializer instance

This is backwards compatible - old-style invocations will trigger a deprecation message

Update chat and poll plugins to new pattern
2023-04-24 15:47:28 +10:00
Martin Brennan 896707c7ea
FIX: Do not delete old chat messages if chat disabled (#21214)
Further followup to 24ec06ff85,
where I prevented other chat scheduled jobs from running if
chat was disabled. We should not be running any plugin scheduled
jobs if that plugin is disabled, it can cause unexpected
behaviour.
2023-04-24 14:42:50 +10:00
Martin Brennan 24ec06ff85
FEATURE: Reintroduce better thread reply counter cache (#21197)
This was reverted in 38cebd3ed5.
The issue was that I was using Discourse.redis.delete_prefixed
which does a slow redis KEYS lookup, which is not advised in
production. This commit removes that, and also ensures the periodical
thread count update only happens if threading is enabled.

I changed to use a redis INCR/DECR for reply count
cache. This avoids a round trip to redis to GET the current
count, and also avoids multi-process issues, where
if there's two processes trying to increment at the
same time, they may both receive the same value, add one
to it, then both write the same value back.
Then, it's only n+1 instead of n+2.

This also prevents almost all chat scheduled jobs from
running if chat is disabled, the only one remaining is
the message retention job.
2023-04-24 09:32:04 +10:00
Martin Brennan 21f93731a3
DEV: Move channel creation for category into service (#21167)
This commit moves the category channel creation out
of the Chat::Api::Channel controller and into a
dedicated CreateCategoryChannel service. A follow up
commit will move the DM channel creation out of
the old DirectMessageChannelCreator service.

Also includes a new on_model_errors helper
for chat service class usage, that collects model
validation errors to present in a nice way.

---------

Co-authored-by: Loïc Guitaut <loic@discourse.org>
2023-04-24 09:15:16 +10:00
Andrei Prigorshnev ea5dec82a6
DEV: Extract mentions.count method (#21116) 2023-04-21 17:54:02 +04:00
Andrei Prigorshnev e7292e1682
DEV: more tests for mentions when updating chat messages (#21185)
This adds these two new test cases:

    context "when updating a mentioned user" do
      it "updates the mention record" do

    # and
    context "when there are duplicate mentions" do
        it "creates a single mention record per mention" do

Apart from that, this groups mention related tests into a context, renames one test, and moves setup of another test into the test case itself from the before block (to make it more clear, that test is the only one that uses that setup). See the PR's commit history.
2023-04-21 16:58:01 +04:00
Daniel Waterworth 38cebd3ed5
Revert "FEATURE: Better thread reply counter cache (#21108)" (#21192)
This reverts commit 180e3e11d1.

Per internal discussions, this is a temporary revert, to investigate if this is causing a performance regression.
2023-04-20 15:09:47 -05:00
Andrei Prigorshnev 8b438767e5
FIX: send notifications after a chat message was updated with new mentions (#21173)
Steps to reproduce the bug:
1. Send a chat message
2. Edit the message and add a mention to it
3. The mentioned user won't receive a notification

This PR fixes the problem.

Also:
1. There's no need anymore to have a code for removing notifications in the `notify_edit` method, because a call to `@chat_message.update_mentions` in the first line of the `notify_edit` method does that job:
    ff56f403a2/plugins/chat/lib/chat/notifier.rb (L90)

2. There's no need to load mention records from database, it's enough to pluck user ids
2023-04-20 19:05:17 +04:00
chapoi ba2adc7793
UX: chat thread hover (#21181)
* UX: switch standard message hover to new hover colour var

* UX: chat thread indication minor design changes
2023-04-20 16:32:21 +02:00
Martin Brennan 351e3ccd98
FIX: Chat publisher publishing to thread when threading disabled (#21179)
Followup to bd5c5c4b5f, a
bug was introduced there for any channel that did not have
threading enabled or sites with the experimental threading
disabled. When the user replied to another chat message,
since this is always a thread in the background, we weren't
sending any MessageBus messages to the main channel, since
the message was a thread reply.

However in the UI these messages still show in the main stream
of the channel if threading is turned off, so the UI was not
reacting to these things happening in the backend. The worst
issue was that new clients would not see new replies sent in
reply to other messages in the channel.
2023-04-20 14:38:00 +10:00
Martin Brennan 525d23e0e0
FIX: Revert "DEV: Add `overflow-x: hidden` to chat message containers (#21030)" (#21178)
This reverts commit 768851920e.

This was causing issues with the local date popup, cutting off
the top of it, there is no way to overrule an overflow:hidden
on the parent. Not z-index related.
2023-04-20 03:01:48 +02:00
Martin Brennan 6442bbf46c
DEV: Reintroduce chat rake dev generate tasks (#21164)
This is to help generate random channels and chat
messages for local dev. This was removed in 12a18d4d55
presumably because it was not worth refactoring at the
time.

I've only added these tasks:

- `rake chat:message:populate\[113,20\]` (channel_id, count)
  - Generates the count of messages for a channel ID provided,
    otherwise uses a random channel and 200 count.
- `rake chat:category_channel:populate`
  - Creates a chat channel for a random category.
- `rake chat🧵populate\[132,5\]` (channel_id, message_count)
  - Creates a thread with N messages in the specified channel,
    and enables threading in that channel if necessary
2023-04-20 10:53:10 +10:00
chapoi c57f423083
UX: remove new message element from chatpane (#21143)
* UX: remove new message element

* Update chat-scroll-to-bottom-arrow.hbs

* Linting

---------

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-04-19 01:54:15 +02:00
chapoi 4b02fa7082
UX: slight design changes to chat timestamp (#21144) 2023-04-19 01:54:02 +02:00
Martin Brennan 5b3420d854
FIX: Chat composer shortcuts should respect context (#21130)
This commit fixes an issue where if you pressed a format
shortcut (e.g. bold, italic, code) for the composer and
you had the thread panel open as well, the shortcut would
trigger in both composers, not just the one that was focused.
2023-04-19 09:07:52 +10:00
Martin Brennan a8cf8e57b4
FIX: Do not count thread messages for channel unreads (#21126)
We currently don't have a nice UI to show unread messages for the thread,
and it will take some time to create one. For now, this commit makes it so
new messages inside a thread do not count towards a chat channel's unread
counts, and new messages sent in a thread do not update a user's `last_read_message_id`
for a channel.

In addition, this PR refactors the `Chat::ChannelFetcher` to use the `Chat::ChannelUnreadsQuery`
query class for consistency, and made said class able to return zeroed-out records
for channels the user is not a member of.

Finally, a small bug is fixed here where if a user's `last_read_message_id` for
a channel was a thread's OM ID, then the thread OM would not show in the
main channel stream for them until another reply to the channel was posted.
2023-04-19 08:53:51 +10:00
Andrei Prigorshnev 26543a5b59
FIX: nil exception in chat notifier (#21105)
We've found these exceptions in logs:

    Job exception: undefined method `destroy!' for nil:NilClass
    
    /var/www/discourse/plugins/chat/lib/chat/notifier.rb:102:in `block in notify_edit' 
    /var/www/discourse/plugins/chat/lib/chat/notifier.rb💯in `each' 
    /var/www/discourse/plugins/chat/lib/chat/notifier.rb💯in `notify_edit' 
    /var/www/discourse/plugins/chat/app/jobs/regular/chat/send_message_notifications.rb:18:in `execute' 

In the past, we were creating `chat_mention` records only for sending notifications, so every mention record had a related notification. It isn't the case anymore (since fa543cda). This PR fixes the problem by making sure the notification exists before trying to remove it. Also, we shouldn't be deleting a `chat_mention` record itself, only a notification, this PR fixes that too.

It's quite hard to reproduce this bug locally, I wasn't able to do so, the logic in this class is quite complicated, that's why I'm not adding a test. Also, when looking at this I realized that this method isn't in a fully correct state now, I suspect sometimes some notifications may not be delivered after someone edits a chat message and adds new mentions to it. I'm going to refactor and simplify the method in a subsequent PR.
2023-04-18 19:57:56 +04:00
Jan Cernik 95238be953
FIX: Add missing translations strings for lazy-videos (#21127) 2023-04-18 07:01:27 -03:00
chapoi 0f7eeb5500
FIX: apply clear-transition class to correct wrapper for chat drawer (#21129) 2023-04-18 08:37:13 +02:00
Martin Brennan 180e3e11d1
FEATURE: Better thread reply counter cache (#21108)
This commit introduces a redis cache over the top of the thread
replies_count DB cache, so that we can quickly and accurately
increment/decrement the reply count for all users and not have
to constantly update the database-level count. This is done so
the UI can have a count that is displayed to the users on each
thread indicator, that appears to live update on each chat
message create/trash/recover inside the thread.

This commit also introduces the `Chat::RestoreMessage` service
and moves the restore endpoint into the `Api::ChannelMessages`
controller as part of incremental migrations to move things out
of ChatController.

Finally, this commit refactors `Chat::Publisher` to be less repetitive
with its `MessageBus` sending code.
2023-04-18 14:01:01 +10:00
chapoi b8583f274d
UX: prevent overflow in description (#21124) 2023-04-18 04:20:25 +02:00
Martin Brennan 1e85de36e2
FEATURE: Hook up chat bulk delete for threads (#21109)
Followup to bd5c5c4b5f,
this commit hooks up the bulk delete events for chat
messages inside the thread panel, by fanning out the
deleted message IDs based on whether they belong to
a thread or not.

Also adds a system spec to cover this case, as previously
the bulk delete event would have been broken with an incorrect
`typ` rather than `type` hash key.
2023-04-18 08:28:20 +10:00
Meghna 68549fe54e
UX: Vertical alignment issues on mobile (#21118)
Vertical alignment fixes for topic closed small message and poll info.
2023-04-17 22:51:13 +05:30
Joffrey JAFFEUX 5b187ad25e
FIX: error when quoting message into topic (#21114)
This error was only happening on mobile, note we also already have a (mobile) test (plugins/chat/spec/system/transcript_spec.rb:184) for this which was passing as it's only happening at a specific speed. I don't want to complicate the test too much for this case, will reconsider if it regresses again.
2023-04-17 17:14:51 +02:00
Loïc Guitaut 430d6308a8 FIX: Render links with subfolders properly in Discobot
Currently, some links aren’t properly built in Discobot when Discourse
is hosted in a subfolder. This is because we’re providing
`Discourse.base_url` to the Rails helpers which contains the base URL
*with* the prefix. But Rails helpers already handle this prefix so the
resulting link gets the prefix twice.

The fix is quite simple: use `Discourse.base_url_no_prefix` instead of
`Discourse.base_url`.
2023-04-17 16:53:00 +02:00
Loïc Guitaut a5235f7d16
DEV: Refactor STI/polymorphic associations in chat (#20789) 2023-04-17 15:41:56 +02:00
chapoi 9e269f993b
FIX: overflow of channel title in preview card (#21112) 2023-04-17 15:05:59 +02:00
Martin Brennan 9a15eab3ab
FIX: Do not serialize thread data if threading disabled (#21107)
Followup to ba11cf4767,
this commit makes it so that none of the chat message
thread data is serialized if threading_enabled is false
for the channel or if enable_experimental_chat_threaded_discussions
is false, there is no need to serialize the data in this
case.
2023-04-17 14:29:06 +10:00
Joffrey JAFFEUX 274820d247
FIX: prevents exception when publishing processed (#21104)
This regression happened in bd5c5c4b5f and is due to `message_bus_targets = calculate_publish_targets(chat_channel, chat_message)` expecting a `chat_channel` which was only defined after.

Example exception in logs:

```
Job exception: undefined local variable or method `chat_channel' for Chat::Publisher:Module

/var/www/discourse/plugins/chat/app/services/chat/publisher.rb:91:in `publish_processed!' 
/var/www/discourse/plugins/chat/app/jobs/regular/chat/process_message.rb:21:in `block in execute' 
/var/www/discourse/lib/distributed_mutex.rb:53:in `block in synchronize' 
/var/www/discourse/lib/distributed_mutex.rb:49:in `synchronize' 
/var/www/discourse/lib/distributed_mutex.rb:49:in `synchronize' 
/var/www/discourse/lib/distributed_mutex.rb:34:in `synchronize' 
/var/www/discourse/plugins/chat/app/jobs/regular/chat/process_message.rb:7:in `execute' 
/var/www/discourse/app/jobs/base.rb:249:in `block (2 levels) in perform' 
```

This commit also:
- adds a spec to ensure oneboxing is not regressing anymore
- increment the version on message processed to ensure callbacks are correctly ran

Note we should also have more tests in `Chat::Publisher`, this will be done when we move it to a proper service.

<!-- 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-04-16 10:30:33 +02:00
Joffrey JAFFEUX ba11cf4767
FIX: prevents exception if thread is not found (#21099)
It is yet to investigate the exact reasons leading to this, but probably due to some delete operation or migration, it seems possible to have a message with a thread_id leading to a non existing thread row. This is only a temporary solution to prevent the crash. We should also probably be more defensive here and not include any of this if threading is not enabled.
2023-04-14 23:03:09 +02:00
Joffrey JAFFEUX e190c00bc4
DEV: skip flakey chatables controller spec (#21093) 2023-04-14 06:06:57 +08:00
Joffrey JAFFEUX 9b3408223b
FIX: relies on native focus behavior in chat emoji picker (#21092)
This codepath was responsible to scroll to the first emoji of a section, however `scrollIntoView` was not super reliable and was also causing the whole page to scroll with drawer. This is also simply not necessary code as native focus behavior will scroll to the element.
2023-04-13 20:35:13 +02:00
Martin Brennan bd5c5c4b5f
FEATURE: Reacting to MessageBus in chat thread panel (#21070)
This commit introduces a ChatChannelPaneSubscriptionsManager
and a ChatChannelThreadPaneSubscriptionsManager that inherits
from the first service that handle MessageBus subscriptions
for the main channel and the thread panel respectively.

This necessitated a change to Chat::Publisher to be able to
send MessageBus messages to multiple channels based on whether
a message was an OM for a thread, a thread reply, or a regular
channel message.

An initial change to update the thread indicator with new replies
has been done too, but that will be improved in future as we have
more data to update on the indicators.

Still remaining is to fully move over the handleSentMessage
functionality which includes scrolling and new message indicator
things.

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-04-13 14:45:50 +02:00
David Taylor e52f322cb5
UX: Use dominant color while loading onebox images (#21091)
When we "pull hotlinked images" on onebox images, they are added to the uploads table and their dominant color is calculated. This commit adds the data to the HTML so that it can be used by the client in the same way as non-onebox images. It also adds specific handling to the new `discourse-lazy-videos` plugin.
2023-04-13 12:04:46 +01:00
Joffrey JAFFEUX 18c81958e5
UX: various tweaks on thread (#21083)
- Back button in drawer will bring you back to channel
- Larger font for thread indicator
- Prevents screen flashing due to clearing messages when they were already loaded
- Fixes a bug where did-update params were inverted causing an error when expanding/collapsing drawer
2023-04-13 10:08:12 +02:00
David Battersby 967010e545
FEATURE: Add an emoji deny list site setting (#20929)
This feature will allow sites to define which emoji are not allowed. Emoji in this list should be excluded from the set we show in the core emoji picker used in the composer for posts when emoji are enabled. And they should not be allowed to be chosen to be added to messages or as reactions in chat.

This feature prevents denied emoji from appearing in the following scenarios:
- topic title and page title
- private messages (topic title and body)
- inserting emojis into a chat
- reacting to chat messages
- using the emoji picker (composer, user status etc)
- using search within emoji picker

It also takes into account the various ways that emojis can be accessed, such as:
- emoji autocomplete suggestions
- emoji favourites (auto populates when adding to emoji deny list for example)
- emoji inline translations
- emoji skintones (ie. for certain hand gestures)
2023-04-13 15:38:54 +08:00
Alan Guo Xiang Tan d86691a767
DEV: Skip flaky test on actions (#21072)
https://github.com/discourse/discourse/actions/runs/4675927190/jobs/8281605117
2023-04-12 16:51:00 +08:00
Alan Guo Xiang Tan 2eb60c9713
DEV: Switch sidebar section link identifier to data attribute (#21051)
Data attribute is less restrictive than relying on the class attribute
2023-04-12 15:52:10 +08:00
Martin Brennan 584a17c948
FEATURE: Initial chat thread indicator and disabling echo mode in channels (#21047)
This commit introduces a new thread indicator for channels with `threading_enabled`
set to true and the `enable_exp` site setting set to true. In addition, in the main channel
stream we now hide all messages that are linked to threads except for the original message,
disabling the concept of an "echo mode" for now, we may revisit this in future. We also
remove the jigsaw puzzle "Open Thread" button for message actions, since the thread
indicator can just be used instead.

This also stops the `Chat::Publisher` from sending any messages related to chat
messages that are linked to a thread, unless that chat message is the OM of the
thread. A subsequent PR will link up all MessageBus events within the thread panel,
and for the message indicators.

Another subsequent PR will add the excerpt of the latest message in each thread,
as well as the avatars of the users messaging in the thread.

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-04-12 11:09:06 +10:00
Discourse Translator Bot 9a562f54d7
Update translations (#21055) 2023-04-11 15:45:03 +02:00
Joffrey JAFFEUX f55266e1ca
UX: chat mobile tweaks (#21041)
- rounded active style for messages
- better active state on chat message actions rows
- ensures long press on a message is not selecting text
- slightly improved messages actions animation and background fading
- ensures chat emoji picker is not cutoff on right side
- removes old legacy code related to hovered message
2023-04-11 09:03:12 +02:00
Martin Brennan e34fb7e0b2
DEV: Chat thread reply counter cache (#21050)
Similar to 22a55ef0ce,
this commit adds a replies_count to the Chat::Thread
table, which is updated every 15 minutes via PeriodicalUpdates.
This is done so the new thread indicator for the UI can
show the count without intense serializer queries, but
in future we likely want this to update more frequently.
2023-04-11 15:40:25 +10:00
Martin Brennan 7ae716fa69
FIX: Multiple channels marked active in sidebar (#21045)
Followup to c1dc6a2db4,
this commit just missed removing one of the @computed
decorators which was causing multiple active channels
to show in the sidebar. Fix the issue and introduce a
system spec to catch this.
2023-04-11 12:31:17 +10:00
Joffrey JAFFEUX c1dc6a2db4
FIX: ensures activeMessage is reset with channel (#21031) 2023-04-10 08:10:01 +02:00
Joffrey JAFFEUX c7b49a14c7
Chat/drawer ux tweaks (#21032)
- clicking empty area on the header will toggle collapse/expand it
- applies a background on hover of the channel title
- active state for small buttons
- the back button now has the correct icon color when hovered
- adds missing focus state for heade buttons icons
2023-04-10 07:43:11 +02:00
Jan Cernik 768851920e
DEV: Add `overflow-x: hidden` to chat message containers (#21030) 2023-04-08 13:37:13 -03:00
Jan Cernik a6cba32e57
FIX: Resize chat collapser when using small width drawer (#21017) 2023-04-08 10:43:17 -03:00
Joffrey JAFFEUX 3176d4cb5a
FIX: ensures message actions are bounded (#21027) 2023-04-07 20:54:41 +02:00
Joffrey JAFFEUX 720cf24659
FIX: shows a message as hovered when hovering actions (#21026)
When hovering the chat message actions we are technically not hovering the message anymore, which was removing the background and is slightly unexpected. This commit ensures we keep this background until closing the message actions.
2023-04-07 20:29:33 +02:00
Joffrey JAFFEUX 6d99e6408f
FIX: correctly show user info (#21023)
This PR primarily fixes this case:

- USER A message
- USER B message
- USER B reply to USER A message <-- not showing user info when it should

Moreover, this commit also improves the spec to correctly test more cases.
2023-04-07 20:08:31 +02:00
Joffrey JAFFEUX 9117ea0e3f
FIX: scroll when clicking first emoji of section (#21020)
This bug was also happening when tabbing through sections
2023-04-07 14:11:25 +02:00
Joffrey JAFFEUX 79cacba948
FIX: cancel editing should clear the composer (#21011) 2023-04-07 09:55:55 +02:00
Joffrey JAFFEUX fef279acd5
FIX: do not display the message content when it errors (#21008) 2023-04-06 19:32:21 +02:00
Daniel Waterworth 0ff86feb96
DEV: Rely on helpers for ajax error handling to reduce repetition (#20988) 2023-04-06 11:25:24 -05:00
Joffrey JAFFEUX 5c2c1bf9a7
FIX: correct backdrop on mobile for the emoji picker (#21005) 2023-04-06 15:51:40 +02:00
Martin Brennan ea548292bc
DEV: Refactoring chat message actions for ChatMessage component usage in thread panel (#20756)
This commit is a major overhaul of how chat message actions work, to make it so they are reusable between the main chat channel and the chat thread panel, as well as many improvements and fixes for the thread panel.

There are now several new classes and concepts:

* ChatMessageInteractor -  This is initialized from the ChatMessage, ChatMessageActionsDesktop, and ChatMessageActionsMobile components. This handles permissions about what actions can be done for each
message based on the context (thread or channel), handles the actions themselves (e.g. copyLink, delete, edit),
and interacts with the pane of the current context to modify the UI
* ChatChannelThreadPane and ChatChannelPane services - This represents the UI context which contains the
messages, and are mostly used for state management for things like message selection.
* ChatChannelThreadComposer and ChatChannelComposer - This handles interaction between the pane, the
message actions, and the composer, dealing with reply and edit message state.
* Scrolling logic for the messages has now been moved to a helper so it can be shared between the main channel pane and the thread pane
* Various improvements with the emoji picker on both mobile and desktop. The DOM node of each component is now located outside of the message which prevents a large range of issues.

The thread panel now also works in the chat drawer, and the thread messages have less
actions than the main panel, since some do not make sense there (e.g. moving messages to
a different channel). The thread panel title, excerpt, and message sender have also been removed
for now to save space.

This gives us a solid base to keep expanding on and fixing up threads. Subsequent PRs will
make the thread MessageBus subscriptions work and disable echo mode
for the initial release of threads.

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2023-04-06 15:19:52 +02:00
Joffrey JAFFEUX 838fb37019
FIX: accounts for `hide_profile_and_presence` core user option (#20991)
Chat will now correctly use this core setting and will not show the presence of the user in this case.
2023-04-06 09:29:54 +10:00
Discourse Translator Bot 171e8b679d
Update translations (#20861) 2023-04-05 09:12:48 +02:00
Martin Brennan 6ad9e4ad06
FEATURE: Add CSS class generation for category colors and hashtags (#20951)
This commit adds a system to generate CSS variables and classes for categories
and hashtags, which will be used in an effort to remove baked icons for hashtags
and add color to those icons.

This is in two parts. First I added an initializer generate a category color CSS
variable style tag in the head tag that looks like this:

```css
:root {
--category-1-color: #0088CC;
--category-2-color: #808281;
--category-3-color: #E45735;
--category-4-color: #A461EF;
--category-5-color: #ee56c9;
--category-6-color: #da28c2;
--category-7-color: #ab8b0a;
--category-8-color: #45da37;
...
}
```

The number is the category ID. This only generates CSS variables for categories
the user can access based on `site.categories`. If you need the parent color variable
you can just use the `category.parentCategory.id` to get it.

Then, I added an initializer to generate a hashtag CSS style tag using these variables.
Only the category and channel hashtags need this, the category one generates the
background-gradient needed for the swatch, and the channel just generates a color
for the icon. This is done in an extendable way using the new `api.registerHashtagType`
JS plugin API:

```css
hashtag-color--category-1 {
  background: linear-gradient(90deg, var(--category-1-color) 50%, var(--category-1-color) 50%);
}
hashtag-color--category-2 {
  background: linear-gradient(90deg, var(--category-2-color) 50%, var(--category-2-color) 50%);
}
hashtag-color--category-5 {
  background: linear-gradient(90deg, var(--category-5-color) 50%, var(--category-4-color) 50%);
}
...
.hashtag-color--channel-4 {
  color: var(--category-12-color);
}
.hashtag-color--channel-92 {
  color: var(--category-24-color);
}
```

Note if a category has a parent, its color is used in the gradient correctly. The numbers
here are again IDs (e.g. channel ID, category ID) and the channel’s chatable ID is used
to find the category color variable.
2023-04-05 13:02:35 +10:00
Bianca Nenciu 6da2fbbf76
FIX: Use correct translation key (#20958)
The translation key is built using the name of the reviewable as it was
defined in Ruby. The chat plugin uses the `Chat` namespace and defines
`Chat::ReviewableMessage`. This was then transformed to
`chat::reviewable_message`, but it should be `chat_reviewable_message`
to resemble the other translation keys.
2023-04-04 16:28:04 +03:00
chapoi 6e2fd7a451
UX: Chat channel title overflow ellipsis fixes (#20956)
* UX: add correct class

* UX: prioritise name over user messages when truncating

* UX: add missing overflows to enable ellipsis
2023-04-04 12:44:36 +02:00
Jan Cernik b4096f4636
FIX: Add lazy-videos support for Vimeo unlisted videos (#20916) 2023-04-03 22:49:32 -03:00
Martin Brennan 894586afa9
FIX: Trashing message should reset last read (#20912)
When a chat message is trashed and the message is used
for someone's UserChatChannelMembership#last_read_message_id,
the user would end up with some read state issues until
someone posted a new message in the channel, since we didn't
clear it like we did on bulk message delete.

This commit fixes the issue, and also takes the opportunity
to start a MessagesController in the API namespace, and move
the trash message functionality into the new service format.
2023-04-04 09:30:38 +10:00
Martin Brennan c00d17535f
DEV: Drop chat_uploads table and model and remove old references (#20926)
Followup to 0924f874bd,
we migrated Chat::Upload records to UploadReference records
there and have not been making new Chat::Upload records
for some time, we can now delete the model and table.
2023-04-04 09:13:39 +10:00
Jarek Radosz 29e2e3ff3b
DEV: Fix random typos (#20937) 2023-04-03 19:27:32 +02:00
Joffrey JAFFEUX 1219f41c68
UX: multiple minor improvements (#20917)
- Raises the scroll distance to 250px instead of 100px to show the arrow down button
- Always have a margin on drawer when showing channel list, removes this margin when the scrollbar is apparent
- Makes all scrollbar used in chat look the same through the chat-scrollbar mixin
- Ensures hover state is not persistent on channel row in mobile
- Makes the channel row full width on mobile
2023-04-03 10:46:38 +02:00
Jan Cernik af98df8cb9
FIX: Vertically center youtube thumbnails in lazy-videos (#20914) 2023-03-31 09:41:58 -03:00
Martin Brennan f7997ae882
DEV: Add debug for ChatablesControllerSpec (#20909)
We keep getting this failure on the spec but I
cannot reproduce locally, add this extra log line
to see if it helps:

```
>  Chat::Api::ChatablesController#index with chat permissions does not return DM channels for users who are not in the chat allowed group
>  Failure/Error: example.run
>
>    expected: 200
>         got: 500
>
>    (compared using ==)
>  # ./plugins/chat/spec/requests/chat/api/chatables_controller_spec.rb:158:in `block (4 levels) in <main>'
>  # ./spec/rails_helper.rb:358:in `block (2 levels) in <top (required)>'
>  # ./vendor/bundle/ruby/3.2.0/gems/webmock-3.18.1/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
>  # ------------------
>  # --- Caused by: ---
>  #
>  #   expected: 200
>  #        got: 500
>  #
>  #   (compared using ==)
>  #   ./plugins/chat/spec/requests/chat/api/chatables_controller_spec.rb:158:in `block (4 levels) in <main>'

```
2023-03-31 11:50:12 +10:00
Joffrey JAFFEUX 6ba24b3599
UX: prevents long press on reaction to open actions (#20899)
This is super hard to write a test as a combination of: long press, mobile and popup.
2023-03-30 20:01:38 +02:00
Martin Brennan f8ff97b2ec
DEV: Add specs to ChannelSerializer and StructuredChannelSerializer (#20872)
This adds specs to the mentioned serializers to catch regressions
with MessageBus last_ids and to ensure the correct ones are being
returned and passed down to the ChannelSerializer.

Followup to d8ad5c3
2023-03-30 12:16:32 +10:00
Jan Cernik afe3e36363
DEV: Remove lazy-yt and replace with lazy-videos (#20722)
- Refactors the old plugin to remove jquery usage
- Adds support for Vimeo videos (default on) and Tiktok (experimental and default off)
2023-03-29 11:54:25 -04:00
Joffrey JAFFEUX 69de5b161f
FIX: ensures removing a reaction doesn’t remove others (#20869) 2023-03-29 08:39:52 +02:00
Martin Brennan 70c0955722
DEV: Uncomment chat upload system specs (#20859)
These were commented in  daaa41ae07,
doesn't seem to have made an observable difference, uncommenting
these now to see if chat system specs still pass.
2023-03-28 10:55:01 -04:00
Martin Brennan d8ad5c38b9
FIX: channel_message_bus_last_id was incorrect (#20858)
Followup to 3ea8df4b06,

I forgot to wrap the call to Chat::Publisher.root_message_bus_channel(object.chat_channel.id)
in MessageBus.last_id, so the channel_message_bus_last_id key was
ending up as e.g. "/chat/58" instead of the last ID value.
2023-03-28 16:01:27 +10:00
Martin Brennan 3ea8df4b06
DEV: Fix excessive MessageBus#last_id calls in chat (#20855)
We noticed via profiling that chat was doing N redis calls
per channel. Part of this was from the kick_message_bus_last_id
from 520d4f504b being incorrectly
passed down for DM channels rather that public channels, and the
other part was from the root MessageBus channel last_id
being fetched in ChannelSerializer for every single channel.

This commit fixes both issues, for me going from 134 redis calls
on page load to 20 locally.

Also deletes an old file missed in 12a18d4d55
2023-03-28 14:45:45 +10:00
Martin Brennan c912c58d6c
FIX: Make chat tracking payload backwards compatible (#20852)
Followup cab4b2cfba,
this was causing client JS errors because the old version
of the client was expecting the old keys, but the new
ruby version of the app was sending different keys via
the MessageBus payload. We can remove this in a couple
of weeks.
2023-03-28 12:56:32 +10:00
Martin Brennan cab4b2cfba
DEV: Introduce bulk channel tracking publisher (#20838)
This commit introduces a Chat::Publisher and MessageBus endpoint
that allows for updating a user's channel tracking state in bulk for
multiple channels, rather than having to do it for one channel
at a time.

This also required an improvement to ChannelUnreadsQuery -- now
multiple channel IDs can be passed to this to get the unread counts
and mention counts for those channels for a user, also increasing
efficiency rather than having to do a query for every individual
channel.

Followup to #20802
2023-03-28 09:36:28 +10:00