Commit Graph

2000 Commits

Author SHA1 Message Date
Loïc Guitaut b8762172e4 DEV: Allow `with_service` in jobs
This patch introduces a new `ServiceJob` class allowing the use of
`with_service` in jobs.

This way, it’s easier to use the chat service objects in jobs and
provides the same level of functionality than the one we have in
controllers.
2023-02-23 09:28:53 +01:00
Martin Brennan 74e7ee175b
FIX: Blank dialog when auto-join selected in channel creation modal (#20405)
Fixes issue introduced in 7ef482a292
where the correct warning message was not shown when enabling auto-join
for public categories when creating a channel. Adds more system specs
as well to avoid regressions.
2023-02-22 17:38:54 +10:00
Discourse Translator Bot 76260a4d79
Update translations (#20389) 2023-02-21 17:12:10 +01:00
Loïc Guitaut f7c57fbc19 DEV: Enable `unless` cops
We discussed the use of `unless` internally and decided to enforce
available rules from rubocop to restrict its most problematic uses.
2023-02-21 10:30:48 +01:00
chapoi 87de3c2319
UX: highlight vars updates (#20346)
* UX: replace highlight vars in popup menu

* UX: replace highlight vars in autcomplete

* UX: replace highlight vars in menu-panel

* UX: update style guide

* UX: bulk replace highlight vars in various small appearances
2023-02-21 10:15:49 +01:00
chapoi 8c80d330fa
UX: apply skeleton animation on content only (#20376) 2023-02-20 18:54:00 +01:00
David Taylor 7ed4eaabda
DEV: Update styleguide example titles to use angle-bracket naming (#20375) 2023-02-20 15:16:18 +00:00
Gerhard Schlager 3d7aec36b5
FIX: Wrong interpolation key (#20374)
follow-up to 7ef482a2
2023-02-20 16:03:45 +01:00
Keegan George 9c29d688e7
FEATURE: Add word count and indicator when exceeded max (#19367)
**This PR creates a new core reusable component wraps a character counter around any input.**

The component accepts the arguments: `max` (the maximum character limit), `value` (the value of text to be monitored).

It can be used for example, like so:
```hbs
  <CharCounter @max="50" @value={{this.charCounterContent}}>
    <textarea
      placeholder={{i18n "styleguide.sections.char_counter.placeholder"}}
      {{on "input" (action (mut this.charCounterContent) value="target.value")}}
      class="styleguide--char-counter"></textarea>
  </CharCounter>
```

**This PR also:**
1. Applies this component to the chat plugins edit channel's *Edit Description** modal, thereby replacing the simple text area which provided no visual indication when text exceeded the max allowed characters.
2. Adds an example to the `/styleguide` route
2023-02-20 12:06:43 +01:00
Discourse Translator Bot 43800eeb73
Update translations (#20370) 2023-02-20 11:01:01 +01:00
Gerhard Schlager 7ef482a292
REFACTOR: Fix pluralized strings in chat plugin (#20357)
* FIX: Use pluralized string

* REFACTOR: Fix misuse of pluralized string

* REFACTOR: Fix misuse of pluralized string

* DEV: Remove linting of `one` key in MessageFormat string, it doesn't work

* REFACTOR: Fix misuse of pluralized string

This also ensures that the URL works on subfolder and shows the site setting link only for admins instead of staff. The string is quite complicated, so the best option was to switch to MessageFormat.

* REFACTOR: Fix misuse of pluralized string

* FIX: Use pluralized string

This also ensures that the URL works on subfolder and shows the site setting link only for admins instead of staff.

* REFACTOR: Correctly pluralize reaction tooltips in chat

This also ensures that maximum 5 usernames are shown and fixes the number of "others" which was off by 1 if the current user reacted on a message.

* REFACTOR: Use translatable string as comma separator

* DEV: Add comment to translation to clarify the meaning of `%{identifier}`

* REFACTOR: Use translatable comma separator and use explicit interpolation keys

* REFACTOR: Don't interpolate lowercase channel status

* REFACTOR: Fix misuse of pluralized string

* REFACTOR: Don't interpolate channel status

* REFACTOR: Use %{count} interpolation key

* REFACTOR: Fix misuse of pluralized string

* REFACTOR: Correctly pluralize DM chat channel titles
2023-02-20 10:31:02 +01:00
Joffrey JAFFEUX 39be3cb619
DEV: fixes spec failing with ruby 3.2.1 (#20356)
The error was:

```
Failures:

  1) Chat::Endpoint.call(service, &block) when using the on_failed_contract action when the service contract does not fail does not run the provided block
     Failure/Error: subject(:endpoint) { described_class.call(service, controller, &actions_block) }

     NoMethodError:
       private method `run' called for #<SuccessContractService:0x000000011e3b28a0 @initial_context={"guardian"=>nil}, @context=#<Chat::Service::Base::Context guardian=nil, __steps__=[#<Chat::Service::Base::ContractStep:0x000000011de51230 @name=:default, @method_name=:default, @class_name=SuccessContractService::Contract, @default_values_from=nil>]>>
     # ./plugins/chat/app/services/base.rb:305:in `call'
     # ./plugins/chat/app/helpers/with_service_helper.rb:20:in `run_service'
     # ./plugins/chat/lib/endpoint.rb:76:in `call'
     # ./plugins/chat/lib/endpoint.rb:70:in `call'
     # ./plugins/chat/spec/lib/endpoint_spec.rb:80:in `block (3 levels) in <main>'
     # ./plugins/chat/spec/lib/endpoint_spec.rb:198:in `block (5 levels) in <main>'
     # ./spec/rails_helper.rb:358:in `block (2 levels) in <top (required)>'
```
2023-02-18 12:13:41 +01:00
Joffrey JAFFEUX e797d2082b
UX: contains overscroll in channels list (#20353) 2023-02-18 11:00:02 +01:00
Jarek Radosz 3c6e3173cd
FIX: Glimmer component arg access (#20354)
This regressed in b94fa3b87a as the component was migrated to a glimmer component.
2023-02-18 10:59:28 +01:00
Jarek Radosz 9519747a01
FIX: Correctly update _subscribedTo* props (#20351)
`_subscribedToChat` was previously a never-true, and `_subscribedToCore` once set to false could no longer be flicked back to true.
2023-02-17 21:45:21 +01:00
Joffrey JAFFEUX 8144730ebb
FIX: correctly add user info data to message serializer (#20348)
Previous commit 479c0a3051 was done with the assumption that this info was defined on user serializer but it was actually defined on post serializer in core. This commit extends the user serializer for messages to add this data to the user.

Also correctly adds serializer test to ensure we actually have this data.
2023-02-17 17:07:44 +01:00
Jan Cernik f48e25b215
FIX: Chat member user card rendered out of view (#20332) 2023-02-17 10:14:00 -03:00
Joffrey JAFFEUX a0b83dac86
UX: prevents scroll in chat to propagate to parents (#20347)
Prior to this fix, scrolling in the drawer for example, would also scroll the full page when reaching bottom of available messages.
2023-02-17 13:39:51 +01:00
chapoi 8465f53a35
UX: userstatus limit handling in UI (#20343)
* UX: handle long userstatus in menupanel

* UX: remove margin on userstatus emoji

* UX: change emoji sise of user status in DM creator

* FIX: user status overflow on chat index
2023-02-17 06:54:56 +01:00
Martin Brennan 584d9a9438
DEV: Use service objects for chat thread lookup (#20276)
Adds a new LookupThread class that handles finding the
thread based on thread + channel ID, checking permissions
and policy/contract checks.

Co-authored-by: Loïc Guitaut <loic@discourse.org>
2023-02-16 19:17:26 +01:00
Joffrey JAFFEUX 5ebf016a3f
FIX: removes uneeded footer-nav-height subtraction (#20336)
This was incorrectly added.
2023-02-16 18:25:36 +01:00
Joffrey JAFFEUX eb0caed75a
FIX: ensures staged message are set with channel id (#20335) 2023-02-16 18:05:13 +01:00
Joffrey JAFFEUX 479c0a3051
DEV: adds is-new-user and primary group class (#20322)
This commit also refactors chat-message-info to use glimmer.
2023-02-16 17:17:16 +01:00
Andrei Prigorshnev 75b81b6854
DEV: extract the logic for extracting and expanding mentions from ChatNotifier (#20290)
Initially, the ChatMention model / db table was introduced to better support notifications (see discourse/discourse-chat@0801d10). That means that currently, we create a new chat_mention record only if a user will be notified about the mention.

Now we plan to start using the ChatMention model in other scenarios (for example for implementing user status on mentions) so we need to always create a new record in the chat_mention table. This PR does the first step into that direction by decoupling the logic for extracting and expanding mentions from the code related to notifications.

This doesn't change any behavior, only extracts code from ChatNotifier.
2023-02-16 19:55:18 +04:00
Joffrey JAFFEUX 7391f8e077
FIX: correctly account for ipad footer nav height (#20334)
This code also removes duplicated code in chat which doesn’t seem necessary anymore.
2023-02-16 16:49:17 +01:00
Joffrey JAFFEUX 7cc0c59469
FIX: removes stored scroll position in drawer (#20328) 2023-02-16 12:58:47 +01:00
Martin Brennan 9704d9aed6
DEV: Glimmerize ChatMessageActionsDesktop/Mobile components (#20325)
These are fairly small components, so we can change to using
glimmer without too much trouble.
2023-02-16 11:24:29 +01:00
chapoi 33ee46d62b
UX: update chat draft icon colour (#20326) 2023-02-16 09:16:07 +01:00
Krzysztof Kotlarek 1a5f6aefc7
FIX: correct sidebar and chat height on DiscourseHub (#20323)
Before that change, footer of the sidebar was not visible.
Footer is very important, especially now, when add custom section button is located there.
Also, distance between chat input and keyboard were increased
2023-02-16 15:59:09 +11:00
Martin Brennan c0a086a988
DEV: Move ChatThreadsManager to channel (#20304)
This commit changes the ChatThreadsManager into a native
class instead of an ember service, and initializes it
for every ChatChannel model. This way each channel has its
own thread manager and cache that we can load/unload as
needed, and we also move activeThread to the channel since
it makes more sense to keep it there, not inside the chat service.

The pattern of calling setOwner with the passed in owner
from ChatChannel is adapted from the latest ember docs,
and is needed to avoid the error below when calling services
from the native class:

> Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container

It works well _only_ if we use our own getOwner wrapper
from addon/lib/get-owner, which is for backwards compat.

c.f. https://guides.emberjs.com/release/in-depth-topics/native-classes-in-depth/
2023-02-16 10:00:40 +10:00
Joffrey JAFFEUX 79c94afdc5
DEV: fixes deprecation warning in SendMessageNotifications (#20318)
We were calling the job with a symbol as one of the values:

```ruby
Jobs.enqueue(
  :send_message_notifications,
  chat_message_id: 1,
  timestamp: Time.now.iso8601(6),
  reason: :new,
)
```

Which is a bad pattern as when the job serialisation will happen, `:new` will become `"new"` and you have to deal with a string in your job and not a symbol, which can be confusing and lead to bugs.
2023-02-15 22:13:24 +01:00
Joffrey JAFFEUX 723a7e316b
DEV: adds spec for deleted message (#20317) 2023-02-15 22:05:16 +01:00
Martin Brennan c07f1e442f
DEV: Fix failing chat spec and add unexpected failure indicator (#20299)
This commit fixes the UpdateUserLastRead spec which was checking
for a message ID that did not exist -- this could fail at times
since message ID 2 could exist. Better to create + destroy a message
since then it's guaranteed we have a unique ID.

This also attempts to clarify a step that we expect to fail which
succeeds instead by adding another emoji next to the success tick and
an explanation text.

Also removes some uses of unless in Services::Base, we generally prefer
to use alternatives, since unless can be hard to parse in a lot of
cases.

Co-authored-by: Loïc Guitaut <loic@discourse.org>
2023-02-15 19:16:13 +01:00
Loïc Guitaut c20b381508 DEV: Refactor chat service matchers 2023-02-15 17:49:51 +01:00
Joffrey JAFFEUX 61934afbb1
FIX: ensures chat-message is recomputed with model (#20312)
The message model is not yet using tracked properties and as a result we were not correctly recomputing on various cases.
2023-02-15 15:08:55 +01:00
Joffrey JAFFEUX 075af7ba84
REFACTOR: channel retention reminder text (#20310)
- Moves logic into one specialised component
- Adds more tests
- Removes duplicate key
- Uses pluralization
- Handles 0 case properly

Co-authored-by: Gerhard Schlager <mail@gerhard-schlager.at>
2023-02-15 14:50:01 +01:00
Discourse Translator Bot a8fa3299de
Update translations (#20283) 2023-02-15 10:51:00 +01:00
Martin Brennan 4f509b045c
FIX: Regression with chat shift+select messages (#20305)
Followup to b94fa3b87a,
which broke the functionality to click on a message
checkbox, hold shift, then click another one, and have
the messages inbetween selected. Add system spec to
catch this.
2023-02-15 08:49:56 +01:00
Martin Brennan c65cdc0779
DEV: Remove chat_channel_id from chat-live-pane details (#20302)
This is unnecessary indirection, we can just have the
chat_channel_id in the message serializer and use that.
2023-02-15 08:27:09 +01:00
Joffrey JAFFEUX 714e903e81
FIX: correctly open channel info (#20297)
A typo was preventing a click on channel title when in drawer mode to correctly open the channel info in full page.

This commit fixes the typo and adds a test.
2023-02-15 14:03:29 +10:00
Martin Brennan c767a38086
FIX: Overflowing chat content in main-chat-outlet grid (#20301)
Follow up to 82b4a53d29

On mobile, we just need to add `min-width: 0` to
`chat-live-pane` so it will not overflow the grid
defined in `main-chat-outlet.chat-view`.

The overflow could be triggered by:

1. Replying on mobile to a really long chat message
2. Uploading > 2 files

Both of these situations are fixed.
2023-02-15 12:48:18 +10:00
Joffrey JAFFEUX 585d1e2f4d
UX: hide chat button on user card when suspended (#20292) 2023-02-14 21:12:50 +01:00
Joffrey JAFFEUX b94fa3b87a
DEV: changes <ChatMessage> to use @glimmer (#20056) 2023-02-14 19:34:55 +01:00
Joffrey JAFFEUX 82b4a53d29
FIX: reverts part of thread css (#20286)
This css was causing the view on mobile to take more space than the available width. This was particularly visible with uploads due to a bug preventing the overflow, this is also fixed.
2023-02-14 15:38:26 +01:00
Joffrey JAFFEUX f12724b5a5
DEV: routable chat part 2 (#20232)
This commit is expanding on previous work making everything chat working through an URL.

Improves drawer templates to be all URLs
Implements some kind of router for the drawer
Removes few remaining actions for opening channels
2023-02-14 11:27:07 +01:00
Martin Brennan 07ab20131a
FEATURE: Chat side panel with threads initial skeleton (#20209)
This commit introduces the skeleton of the chat thread UI. The
structure of the components looks like this. Its done this way
so the side panel can be used for other things as well if we wish,
not just for threads:

```
.main-chat-outlet
   <ChatLivePane />
   <ChatSidePanel>
     <-- rendered with {{outlet}} -->
     <ChatThread />
   </ChatSidePanel>
```

Later on the `ChatThreadList` will be rendered here as well.
Now, when you go to a channel you can open a thread by clicking
on either the Open Thread message action button or by clicking on
the reply indicator. This will take you to a route like `chat/c/:slug/:channelId/t/:threadId`.
This works on mobile as well.

This commit includes basic serializers and routes for threads,
as well as a new `ChatThreadsManager` service in JS that caches
threads for a channel the same way the channel threads manager does.

The chat messages inside the thread are intentionally left out
until a later PR.

**NOTE: These changes are gated behind the site setting enable_experimental_chat_threaded_discussions
and the threading_enabled boolean on a ChatChannel**
2023-02-14 11:38:41 +10:00
Loïc Guitaut 5f4623ba47 DEV: Refactor `UpdateUserLastRead` a little
We’re now using `contract` as the first step and validations for
mandatory parameters have been added.

To simplify specs a bit, we only assert the service contract is run as
expected without testing each validation case. We’re now testing the
contract itself in isolation.
2023-02-13 17:03:41 +01:00
Martin Brennan 60ad836313
DEV: Chat service object initial implementation (#19814)
This is a combined work of Martin Brennan, Loïc Guitaut, and Joffrey Jaffeux.

---

This commit implements a base service object when working in chat. The documentation is available at https://discourse.github.io/discourse/chat/backend/Chat/Service.html

Generating documentation has been made as part of this commit with a bigger goal in mind of generally making it easier to dive into the chat project.

Working with services generally involves 3 parts:

- The service object itself, which is a series of steps where few of them are specialized (model, transaction, policy)

```ruby
class UpdateAge
  include Chat::Service::Base

  model :user, :fetch_user
  policy :can_see_user
  contract
  step :update_age

  class Contract
    attribute :age, :integer
  end

  def fetch_user(user_id:, **)
    User.find_by(id: user_id)
  end

  def can_see_user(guardian:, **)
    guardian.can_see_user(user)
  end

  def update_age(age:, **)
    user.update!(age: age)
  end
end
```

- The `with_service` controller helper, handling success and failure of the service within a service and making easy to return proper response to it from the controller

```ruby
def update
  with_service(UpdateAge) do
    on_success { render_serialized(result.user, BasicUserSerializer, root: "user") }
  end
end
```

- Rspec matchers and steps inspector, improving the dev experience while creating specs for a service

```ruby
RSpec.describe(UpdateAge) do
  subject(:result) do
    described_class.call(guardian: guardian, user_id: user.id, age: age)
  end

  fab!(:user) { Fabricate(:user) }
  fab!(:current_user) { Fabricate(:admin) }

  let(:guardian) { Guardian.new(current_user) }
  let(:age) { 1 }

   it { expect(user.reload.age).to eq(age) }
end
```

Note in case of unexpected failure in your spec, the output will give all the relevant information:

```
  1) UpdateAge when no channel_id is given is expected to fail to find a model named 'user'
     Failure/Error: it { is_expected.to fail_to_find_a_model(:user) }

       Expected model 'foo' (key: 'result.model.user') was not found in the result object.

       [1/4] [model] 'user' 
       [2/4] [policy] 'can_see_user'
       [3/4] [contract] 'default'
       [4/4] [step] 'update_age'

       /Users/joffreyjaffeux/Code/pr-discourse/plugins/chat/app/services/update_age.rb:32:in `fetch_user': missing keyword: :user_id (ArgumentError)
       	from /Users/joffreyjaffeux/Code/pr-discourse/plugins/chat/app/services/base.rb:202:in `instance_exec'
       	from /Users/joffreyjaffeux/Code/pr-discourse/plugins/chat/app/services/base.rb:202:in `call'
       	from /Users/joffreyjaffeux/Code/pr-discourse/plugins/chat/app/services/base.rb:219:in `call'
       	from /Users/joffreyjaffeux/Code/pr-discourse/plugins/chat/app/services/base.rb:417:in `block in run!'
       	from /Users/joffreyjaffeux/Code/pr-discourse/plugins/chat/app/services/base.rb:417:in `each'
       	from /Users/joffreyjaffeux/Code/pr-discourse/plugins/chat/app/services/base.rb:417:in `run!'
       	from /Users/joffreyjaffeux/Code/pr-discourse/plugins/chat/app/services/base.rb:411:in `run'
       	from <internal:kernel>:90:in `tap'
       	from /Users/joffreyjaffeux/Code/pr-discourse/plugins/chat/app/services/base.rb:302:in `call'
       	from /Users/joffreyjaffeux/Code/pr-discourse/plugins/chat/spec/services/update_age_spec.rb:15:in `block (3 levels) in <main>'
```
2023-02-13 13:09:57 +01:00
Gerhard Schlager 71658e63f7 DEV: Fix typo
@discourse-translator-bot keep_translations_and_approvals
2023-02-13 00:46:33 +01:00
Joffrey JAFFEUX e4738cb1bc
FIX: correctly listens to chat notifications (#20246)
This change will ensure we enter and subscribe to presence channels on start and will use the correct "change" events from presence channel to update state.
2023-02-12 23:26:11 +01:00