Commit Graph

885 Commits

Author SHA1 Message Date
chapoi
a846226e92
UX: micro animations chat input (#23030) 2023-08-09 12:58:36 +02:00
Joffrey JAFFEUX
3a3346c95a
FIX: correctly applies aria-expanded/aria-controls (#23029) 2023-08-09 11:51:28 +02:00
Joffrey JAFFEUX
5de86ad7ed
FIX: removes useless model reload (#23016)
I suspect it was moreover possibly related to a flaky spec:

```
  1) Chat::AutoJoinChannelBatch.call when arguments are valid when channel is found when more than one membership is created publishes an event
     Failure/Error: subject(:result) { described_class.call(params) }

     Mocha::ExpectationError:
       unexpected invocation: Chat::Publisher.publish_new_channel(#<Chat::CategoryChannel:0x401f28>, #<User::ActiveRecord_Relation:0x401f50>)
       unsatisfied expectations:
       - expected exactly once, invoked never: Chat::Publisher.publish_new_channel(#<Chat::CategoryChannel:0x401f78>, [#<User:0x401fa0>, #<User:0x401fc8>])
       satisfied expectations:
       - allowed any number of times, invoked once: Chat::Action::CreateMembershipsForAutoJoin.call(has_entries({:channel => #<Chat::CategoryChannel:0x401f78>, :contract => instance_of(Chat::AutoJoinChannelBatch::Contract)}))
       - allowed any number of times, invoked never: Chat::ChannelMembershipManager.new(#<Chat::CategoryChannel:0x401f78>)
       - allowed any number of times, invoked never: #<Mock:0x402018>.recalculate_user_count(any_parameters)
     # ./plugins/chat/app/services/chat/auto_join_channel_batch.rb:65:in `publish_new_channel'
     # ./plugins/chat/app/services/service/base.rb:118:in `instance_exec'
     # ./plugins/chat/app/services/service/base.rb:118:in `call'
     # ./plugins/chat/app/services/service/base.rb:368:in `block in run!'
     # ./plugins/chat/app/services/service/base.rb:368:in `each'
     # ./plugins/chat/app/services/service/base.rb:368:in `run!'
     # ./plugins/chat/app/services/service/base.rb:361:in `run'
     # ./plugins/chat/app/services/service/base.rb:229:in `call'
     # ./plugins/chat/spec/services/chat/auto_join_channel_batch_spec.rb:50:in `block (3 levels) in <main>'
     # ./plugins/chat/spec/services/chat/auto_join_channel_batch_spec.rb:110:in `block (6 levels) in <main>'
     # ./spec/rails_helper.rb:393:in `block (2 levels) in <top (required)>'
```
2023-08-08 22:44:30 +02:00
Discourse Translator Bot
5b6493ff4b
Update translations (#23013) 2023-08-08 15:42:28 +02:00
Jan Cernik
b7953b2562
FIX: Don't create a reviewable when sending PM to user in chat (#22914)
The change is mainly to improve the consistency between flagging a chat message and flagging a post. This, in particular skips creating a reviewable when sending a PM to the user using the option "Send @user a message" from the flag menu.

Context: https://meta.discourse.org/t/send-message-to-user-flags-create-review-item-in-chat/272362
2023-08-08 13:18:34 +02:00
David Taylor
edb276b9a9
DEV: Raise exception when capybara finder times out (#22686)
If a selenium finder takes the full wait duration to resolve, that means it has been written inefficiently. Most likely a matcher has been negated incorrectly.

This commit introduces a patch which will raise an error in this situation so that we can catch the issues while developing specs.

This commit also fixes chat's visit_thread helper. It was spinning on `has_css?(".chat-skeleton")` for the full selenium wait duration, and then returns false. That's because the thread is often already fully loaded before `has_css?` is even called. It's now updated to only look for the final expected state.
2023-08-08 10:16:09 +01:00
Martin Brennan
09223e5ae7
DEV: Remove enable_experimental_hashtag_autocomplete logic (#22820)
This commit removes any logic in the app and in specs around
enable_experimental_hashtag_autocomplete and deletes some
old category hashtag code that is no longer necessary.

It also adds a `slug_ref` category instance method, which
will generate a reference like `parent:child` for a category,
with an optional depth, which hashtags use. Also refactors
PostRevisor which was using CategoryHashtagDataSource directly
which is a no-no.

Deletes the old hashtag markdown rule as well.
2023-08-08 11:18:55 +10:00
Joffrey JAFFEUX
c996b7fe4b
FIX: prevents readonly mode to crash channel_messages#index (#22987)
Prior to this fix `context.membership&.update!(last_viewed_at: Time.zone.now)` would generate an update statement from a GET request which is not permitted by default when in readonly mode.

The usual fix in this case is to check for readonly or rescue an error, however, this common pattern of updating "last seen" or similar can be better handled in a `Schedule::Defer` block, which won't raise the `ActiveRecord::ReadOnlyError` when in readonly and will also prevent the controller to wait for this operation.
2023-08-07 16:34:22 +02:00
Martin Brennan
3e44f04ff5
DEV: Unskip chat delete message spec (#22951)
Skipped in https://github.com/discourse/discourse/pull/22862 but
it seems like that may have been a sidebar error, unskipping to
see if it's ok now
2023-08-07 11:04:10 +10:00
David Taylor
b7e642d99d
DEV: Introduce decorator-position lint rule (#22937) 2023-08-04 12:26:06 +01:00
Jarek Radosz
c5c786b4ac
DEV: Fix array-related linting issues in templates (#22935)
and remove more linting exemptions
2023-08-02 19:43:37 +02:00
Jarek Radosz
09502cf627
DEV: Reduce the number of IntersectionObservers (#22933)
…by adding the `chat/track-message` modifier only to the last thread rather than all of them

(plus: don't use Ember's `lastObject`)
2023-08-02 15:24:30 +02:00
Martin Brennan
d32e90a8d3
DEV: Remove unused chat translations (#22925)
Both placeholder_start_conversation and
placeholder_start_conversation_users are no
longer used.
2023-08-02 17:15:49 +10:00
Discourse Translator Bot
d5f4b8e02c
Update translations (#22904) 2023-08-01 16:05:44 +02:00
Martin Brennan
f79f43ddf9
FIX: Chat translation minor issues (#22869) 2023-07-31 11:44:32 +10:00
Joffrey JAFFEUX
1d2cb3abdc
DEV: skip flakey spec in deleted messages (#22862) 2023-07-28 20:37:41 +02:00
Joffrey JAFFEUX
891aabde19
FIX: when using arrow to bottom fetch from newest (#22860)
We were attempting to fetch from last read but this is actually complicated to get right when you have a lot unread, as we might still have more to load after this but the last unread id is still the same and would make the user end up in a loop.
2023-07-28 19:31:28 +02:00
Andrei Prigorshnev
7c67360d4a
DEV: a better way of picking of the earliest date (#22858)
See https://github.com/discourse/discourse/pull/22854#discussion_r1277542736.
2023-07-28 20:17:04 +04:00
Andrei Prigorshnev
cd45f33430
FEATURE: Remove restrictions from the chat messages export (#22854)
Now, when we took care of performance in fbe0e4c and ad05924 
there is no need anymore to restrict the export to
- 6 months
- 10000 rows
2023-07-28 17:04:57 +04:00
Alan Guo Xiang Tan
bfc3132bb2
SECURITY: Impose a upper bound on limit params in various controllers
What is the problem here?

In multiple controllers, we are accepting a `limit` params but do not
impose any upper bound on the values being accepted. Without an upper
bound, we may be allowing arbituary users from generating DB queries
which may end up exhausing the resources on the server.

What is the fix here?

A new `fetch_limit_from_params` helper method is introduced in
`ApplicationController` that can be used by controller actions to safely
get the limit from the params as a default limit and maximum limit has
to be set. When an invalid limit params is encountered, the server will
respond with the 400 response code.
2023-07-28 12:53:46 +01:00
Martin Brennan
3c8cc0c73e
DEV: Remove chat TODO (#22846)
This is unnecessary, I already fixed this problem
2023-07-28 09:10:14 +08:00
Andrei Prigorshnev
ad05924bdf
DEV: Do one query per month when exporting chat messages (#22746)
We did some testing and saw that making one query per month is 
cheaper than querying all chat messages at ones. Note that even 
though the export job will be performing one query per month, 
the exported messages will be streamed into a single CSV file, so 
nothing changes from the user's point of view.
2023-07-27 21:56:32 +04:00
chapoi
7b3f9dc86b
UX: different way of centering chat notice to accommodate longer texts (#22779)
* UX: different way of centering chat notice to accommodate longer

* linting

* UX: keep close button in top right corner
2023-07-27 15:53:43 +02:00
Jan Cernik
807390bb93
DEV: Remove experimental setting row for chat threads (#22730) 2023-07-27 15:29:28 +02:00
Joffrey JAFFEUX
0aa524821e
DEV: skip flaky spec (#22825)
An attempt to make this spec more stable has been made in f76a9aab22 which doesn’t seem to workout: https://github.com/discourse/discourse/actions/runs/5679336462/job/15391318065#step:31:1128
2023-07-27 15:12:22 +02:00
chapoi
d10fd697b4
UX: responsive oneboxing with images in chat (#22824)
* UX: fix narrow oneboxing with images in chat

* UX: more responsive oneboxing

* UX: onebox-avatar limits

* ony flex non onebox-avatars
2023-07-27 13:57:30 +02:00
Loïc Guitaut
1377186d38 DEV: Refactor chat channel fetching
This is extracted from #22390.

This patch introduces a scope to avoid duplication and a new method,
`Chat::Channel.find_by_id_or_slug` to allow finding a channel either by
its id or by its slug (or its category slug).
2023-07-27 11:55:17 +02:00
Joffrey JAFFEUX
05aa55e172
DEV: moves logic from job to a service (#22691)
`Jobs::AutoJoinChannelBatch` was holding a lot of logic which should be in a service. Moreover, this refactoring is the opportunity to address a bug which could cause a duplicate key error.

From now when trying to insert a new membership it won't fail if a membership is already present.

Example error:

```
Job exception: ERROR:  duplicate key value violates unique constraint "user_chat_channel_unique_memberships"
DETAIL:  Key (user_id, chat_channel_id)=(1, 2) already exists.

Backtrace
rack-mini-profiler-3.1.0/lib/patches/db/pg.rb:110:in `exec'
rack-mini-profiler-3.1.0/lib/patches/db/pg.rb:110:in `async_exec'
(eval):29:in `async_exec'
mini_sql-1.4.0/lib/mini_sql/postgres/connection.rb:209:in `run'
mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:38:in `block in run'
mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:34:in `block in with_lock'
activesupport-7.0.5.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
activesupport-7.0.5.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
activesupport-7.0.5.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
activesupport-7.0.5.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:34:in `with_lock'
mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:38:in `run'
mini_sql-1.4.0/lib/mini_sql/postgres/connection.rb:64:in `query_single'
/var/www/discourse/plugins/chat/app/jobs/regular/chat/auto_join_channel_batch.rb:38:in `execute'
```

Note this commit is also using main branch of `shoulda-matchers` as the gem has not been released yet.

Co-authored-by: Loïc Guitaut <5648+Flink@users.noreply.github.com>
2023-07-27 10:25:41 +02:00
Joffrey JAFFEUX
2d567cee26
FEATURE: thread pagination (#22624)
Prior to this commit we were loading a large number of thread messages without any pagination. This commit attempts to fix this and also improves the following points:

- code sharing between channels and threads:
Attempts to reuse/share the code use in channels for threads. To make it possible part of this code has been extracted in dedicated helpers or has been improved to reduce the duplication needed.

Examples of extracted helpers:
- `stackingContextFix`: the ios hack for rendering bug when momentum scrolling is interrupted
- `scrollListToMessage`, `scrollListToTop`, `scrollListToBottom`:  a series of helper to correctly scroll to a specific position in the list of messages

- better general performance of listing messages:
One of the main changes which has been made is to remove the computation of visible message during scroll, it will only happen when needed (update last read for example). This constant recomputation of `message.visible` on intersection observer event while scrolling was consuming a lot of CPU time.
2023-07-27 09:57:03 +02:00
Jarek Radosz
92d2ea008e
DEV: Fix no-negated-condition linting issues (#22808) 2023-07-26 19:53:37 +02:00
Jan Cernik
a2eb2b0490
DEV: Remove experimental site setting for chat threads (#22720)
We are removing the experimental site setting. Admins can now decide on a per channel basis to enable/disable threading. It's disabled by default.
2023-07-26 12:46:23 +02:00
Jarek Radosz
d06431ba9b
DEV: Fix random typos (#22804)
A fresh batch of stashed changes :P
2023-07-26 12:45:35 +02:00
Jan Cernik
c43271eb9b
FIX: Chat emoji picker focus offset (#22795) 2023-07-26 12:18:10 +02:00
Joffrey JAFFEUX
5346e7f693
FIX: attempt to fix multi sessions reaction spec (#22797)
I was only able to get one failure out of 100 tries, this failure didn't get me more info. My best guess  ATM is  that sometimes, the first session was still loading while receiving the reaction and created some unexpected situation.

The commit attempts to start the "check" session before the session making the reaction hoping that will be enough to prevent this case, if this is the issue.
2023-07-26 11:58:35 +02:00
Loïc Guitaut
25138db433 DEV: Promote historic post_deploy migrations
This commit promotes all post_deploy migrations which existed in
Discourse v3.0.0 (timestamp <= 20221212234948)
2023-07-26 10:36:37 +02:00
Discourse Translator Bot
ad9ad55870
Update translations (#22664) 2023-07-25 17:57:48 +02:00
David Battersby
f7353e7bfa
FIX: Prevent lightbox from loading onebox embed icons in chat uploads (#22776)
Sharing a link in chat will create a onebox embed with a source that includes a site icon and title.

This change prevents loading the site icon into lightbox.
2023-07-25 15:56:26 +08:00
Roman Rizzi
3389b3eeb0
FIX: Use base 10 when gettings allowed group IDs from settings. (#22761)
Same as discourse/discourse-ai#113
2023-07-24 12:05:04 -03:00
chapoi
5a36abd073
UX: category hashtag colors order fix (#22758)
* UX: revert gradient of category hashtag colours

* tests
2023-07-24 14:36:56 +02:00
Loïc Guitaut
5d2ec6461d DEV: Refactor a little chat uploads
This is extracted from #22390.

This patch simplifies a little how we handle uploads in chat, relying on
ActiveRecord mechanisms instead of calling custom methods.

This also makes `Chat::Message#validate_message` a “real” AR validation,
meaning it will run automatically when `#valid?` is called.
2023-07-24 11:13:57 +02:00
Andrei Prigorshnev
3349ce2c79
DEV: extract channel. joined_by method (#21752)
This only moves code around and doesn't change any behavior. This does two things:

1. Extracts the `channel.joined_by?` methods
2. Uses term "members" instead of "participants" for chat members
2023-07-20 22:06:36 +04:00
Loïc Guitaut
050828d1de DEV: Allow chat services to have optional models
This is extracted from #22390.

This patch adds a new `optional` option to the `model` step. This
means if an optional model returns something blank (`nil` or an empty
collection) then the service won’t fail and will execute the next step.
However if a model is properly returned, the step will try to check if
it is valid or not (if it responds to `#invalid?`). If the model isn’t
valid, then the step will fail (so no change here).
2023-07-20 17:27:44 +02:00
Jarek Radosz
6c8dcdb30c
DEV: Consistently use html5 loofah (#22711)
Turns out making a html4 fragment and then operating on parts of it using html5 fragments is a bad idea. ;)
This seems to fix the issue with occasionally missing GH icons in oneboxes.
2023-07-20 12:01:45 +02:00
Andrei Prigorshnev
d1760727cf
DEV: check if user can_chat inside the can_join_chat_channel guardian (#21812)
Someone who cannot chat is also not able to join chat channels, 
so we may not check all the time user.can_chat? && user.can_join_chat_channel? 
and just call user.can_join_chat_channel? instead.
2023-07-19 21:55:00 +04:00
Isaac Janzen
1561e51a13
DEV: Revert "DEV: Update replaceWith on Route (#22645)" (#22693)
This reverts commit 33db93c9b2.
2023-07-19 10:47:31 -05:00
Martin Brennan
a6956af902
FIX: Show mention count for channel list on mobile (#22682)
Followup to 07c3782e51

The above incorrectly removed the channel unread count in
the mobile/drawer channel list when the user has mentions
(meaning the unreads are urgent). This commit adds it
back and refactors system specs a little.
2023-07-19 16:24:01 +10:00
Krzysztof Kotlarek
20ec7ac174
FEATURE: new API to add panels to sidebar (#22534)
Define new concept of panels in sidebar. Panels are wrappers around sidebar sections. In the future, it allows creating full focus mode by switching between panels.

A new API method called addSidebarPanel was added. Default main panel is already registered and by default all API sections are mounted to main.
2023-07-19 11:31:45 +10:00
Alan Guo Xiang Tan
7cee80d699
DEV: Use the main default session for main test assertions (#22677)
Why this change?

The test being changed in question has been flaky on our CI. However, we
are unable to view the screenshot of why it failed because
ActionDispatch will only take a screenshot of the default session upon
failure. At the same time, taking screenshot of all sessions
automatically upon failure is not possible via the official Capybara or
Rails APIs at the moment. Therefore, we're changing this system test to
avoid using two custom session and instead have the main assertion use
the default session such that any failures will provide us with a
screenshot.
2023-07-19 08:21:31 +08:00
Martin Brennan
6efae69c61
FIX: Doubled up or not tracked threads in thread list (#22631)
This commit fixes two issues with the thread list:

1. All threads were being shown regardless of whether the user had
   a membership in the thread. This was happening because the list
   and the channel share the same thread store, so if the channel
   had OMs with threads we would load them and they showed in the list.
2. Threads created by the user from a staged thread would double up.
   This is because the _cache in the channel threadsManager would use
   the staged thread ID even after we'd replaced the object's ID with
   the actual thread from the DB. The answer to this is to remove and
   re-add the thread to the local cache with the actual ID.
2023-07-19 10:09:22 +10:00
Isaac Janzen
33db93c9b2
DEV: Update replaceWith on Route (#22645)
Per https://deprecations.emberjs.com/v3.x/#toc_routing-transition-methods

We are upgrading all `this.replaceWith` calls on routes to directly call the router service (`this.router.replaceWith`)
2023-07-18 15:05:53 -05:00