Commit Graph

446 Commits

Author SHA1 Message Date
Joffrey JAFFEUX
c5ac500181
UX: minor tweaks to thread list item (#23259)
- drop @
- prevents +X  (participants) to show on next line
- few spacing/fonts adjustments

Note that this commit is also stripping links from chat excerpts.
2023-08-25 11:20:03 +02:00
Joffrey JAFFEUX
39b598f304
UI: refines thread list item (#23207)
It will now replies count and participants list. Also the title will be OM excerpt or user defined title, no more default "Thread" title. Lastly, the author of the last reply is also shown as prefix of it.
2023-08-24 18:45:20 +02:00
Joffrey JAFFEUX
46c7e47f50
FIX: prevents setPanel to also set separated mode (#23227)
This could happen after you had already change the separation mode and would cause unexpected bugs.

This PR also adds more tests around using switch buttons with chat.
2023-08-24 18:21:28 +02:00
Joffrey JAFFEUX
fc93604b9e
FIX: correctly resets editing state when done (#23209)
Prior to this fix, attempting to reply to a recently edited message would show the edit icon instead of the reply icon.
2023-08-24 09:41:37 +02:00
Joffrey JAFFEUX
fef0225a22
FIX: correctly check chat tab is present (#23200)
Prior to this fix we would test by visiting the tab which could create a false positive, as the tab could not be present but we could still access the tab, the implementation and tests have been changed to correctly ensure this.
2023-08-23 13:06:29 +02:00
Joffrey JAFFEUX
a008f61f8f
FIX: correctly closes panel when exiting chat (#23201)
We don't use activate/deactivate as it would cause: close/open in short succession when going from threads to thread for example.
2023-08-23 13:05:15 +02:00
Mark VanLandingham
68eba53e09
FEATURE: Chat global mention warnings (pre-send & post-send) (#22764)
This is also fixes the issue of chat composer warnings persisting across channels. Currently if you try to mention more groups than is allowed for example, a mention warning pops up. When you change channels the mention warning will not disappear even if there is no text in the composer.

This adds a reset function to the chat-composer-warnings-tracker.js, which is called when the channel is changed and the message is empty. In the event that the message is not empty we call captureMentions to check the loaded drafts' mentions.

This PR would be nicer if the post-send notice used the new chat notices API to publish the mention warnings but we would have to change the existing ones and I thought that would be too much change for this PR. It'd be a good followup though.
2023-08-22 15:54:35 -05:00
Joffrey JAFFEUX
0e00784218
UX: do not show user tab preference when disabled (#23188)
Prior to this fix we would only check if the user is allowed to chat and not if chat is enabled.
2023-08-22 18:22:25 +02:00
Joffrey JAFFEUX
89259205d6
FIX: do not delete empty message with uploads (#23177)
Prior to this fix when editing a message containing only upload, if we would save it, it would delete it by considering it empty.
2023-08-22 15:21:21 +02:00
Joffrey JAFFEUX
687c6c7515
FIX: correctly display max users message error (#23178) 2023-08-22 12:42:35 +02:00
Joffrey JAFFEUX
3bb2f3a604
FIX: correctly recognizes URL with subfolder (#23173)
Prior to this fix minimizing a full page chat on a subfolder install would cause the drawer to not show.
2023-08-21 22:12:05 +02:00
Joffrey JAFFEUX
f179eef6ae
DEV: makes every spec use new messages helper (#23163)
It's been introduced months ago, but not everything was transitioned to it.
2023-08-21 16:31:58 +02:00
Joffrey JAFFEUX
b03c26ebf5
FIX: correctly handles mobile and default (#23152)
This commit ensures we have correct icon and title on mobile for the chat header icon.

It also fixes a bug where the site setting was not correctly used when the user has not yet set the user option.

Both cases are now correctly tested.
2023-08-18 22:32:43 +02:00
Joffrey JAFFEUX
b2b84cc957
FEATURE: implements user based sidebar mode (#23078) 2023-08-18 20:33:07 +02:00
Andrei Prigorshnev
052462a8f8
FIX: Don't fail when exporting chat messages from deleted channels (#23131) 2023-08-18 14:22:24 +04:00
Roman Rizzi
5683c90917
FIX: TopicSummarization workaround for Postgres' discrete range types (#23105)
Our code assumed the content_range interval was inclusive, but they are open-ended due to Postgres' [discrete range types](https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-DISCRETE), meaning [1,2] will be represented as [1,3).

It also fixes some flaky tests due to test data not being correctly setup and the registry not being resetted after each test.
2023-08-15 14:16:06 -03:00
Joffrey JAFFEUX
2d782c7b00
FIX: correctly deletes webhook_events with webhook (#23097)
Each time a message is created through a webhook, we create we webhook_event associated to this webhook.

When destroying a webhook, we were not destroying the webhook_events which was causing orphans records and more importantly errors in the app expecting to find and associated webhook.
2023-08-15 15:36:00 +02:00
Joffrey JAFFEUX
930b917295
DEV: fixes flakey spec from auto-join-channel-batch (#23044)
The specs were relying a lot on mock and stubs. I suspect that under certain circumstances it didn't play well with fabricators and we ended up with the stub of another spec causing this kind of error:

```
  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:0x39b840>, #<User::ActiveRecord_Relation:0x39b868>)
       unsatisfied expectations:
       - expected exactly once, invoked never: Chat::Publisher.publish_new_channel(#<Chat::CategoryChannel:0x39b890>, [#<User:0x39b8b8>, #<User:0x39b8e0>])
       satisfied expectations:
       - allowed any number of times, invoked once: Chat::Action::CreateMembershipsForAutoJoin.call(has_entries({:channel => #<Chat::CategoryChannel:0x39b890>, :contract => instance_of(Chat::AutoJoinChannelBatch::Contract)}))
       - allowed any number of times, invoked never: Chat::ChannelMembershipManager.new(#<Chat::CategoryChannel:0x39b890>)
       - allowed any number of times, invoked never: #<Mock:0x39b930>.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:412:in `block (2 levels) in <top (required)>'
```

The spec is now simplified and shouldn't have this issue anymore.
2023-08-09 22:37: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
Joffrey JAFFEUX
1d2cb3abdc
DEV: skip flakey spec in deleted messages (#22862) 2023-07-28 20:37:41 +02: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
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
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
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
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
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
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
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
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
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
Jan Cernik
d258bda2fe
FIX: Update last_read_message_id when moving chat messages (#22643) 2023-07-18 12:46:54 -03:00
Martin Brennan
f76a9aab22
DEV: Fix and re-enable chat flakys (#22653)
* DEV: Fix and re-enable chat flakys

The early return in JS was added to prevent an error
from channel being null, and it's better to use known
users for the message fabrications in the specs.

* DEV: Use travel_to in drawer spec for thread tracking

Sometimes in the system test the datetime that is last
viewed for the channel for the user and the datetime for
the last message created_at is only microseconds of difference,
and we do not provide that level of fidelity in the MessageBus
serializer, so unreadThreadsCountSinceLastViewed is not
accurate.

Better to just utilize travel_to and move forward 1 minute in
time before sending the new message to easily differentiate.
2023-07-18 15:45:52 +10:00
Martin Brennan
b583872eed
DEV: Introduce enabled? API to hashtag data sources (#22632)
We need a nice way to only return some hashtag data
sources based on various site settings. This commit
adds an enabled? method that every hashtag data source
must implement. If this returns false the data source
will not be used at all for hashtag lookups or search.
2023-07-18 09:39:01 +10:00
Alan Guo Xiang Tan
beb91e1707
DEV: Skip two flaky system tests (#22651)
Why this change?

These tests have shown to be flaky and are being skipped for now while
we look into it.
2023-07-18 07:26:12 +08:00
Joffrey JAFFEUX
c042978778
DEV: fix flaky spec temporarily (#22633)
We have a fix coming tomorrow.
2023-07-17 09:45:31 +02:00
Martin Brennan
07c3782e51
FEATURE: Show unread in sidebar for unread channel threads (#22342)
This commit makes it so that when the user has unread threads
for a channel we show a blue dot in the sidebar (or channel index
for mobile/drawer).

This blue dot is slightly different from the channel unread messages:

1. It will only show if the new thread messages were created since
   the user last viewed the channel
2. It will be cleared when the user views the channel, but the threads
   are still considered unread because we want the user to click into
   the thread list to view them

This necessitates a change to the current user serializer to also
include the unread thread overview, which is all unread threads
across all channels and their last reply date + time.
2023-07-17 13:00:49 +10:00
Alan Guo Xiang Tan
d916ff56b5
DEV: Use the main default session for main test assertion (#22627)
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-17 08:58:09 +08:00
Joffrey JAFFEUX
6e95c1af3f
FIX: incorrect selector in system specs (#22615)
This could lead to flakey specs, and was invalid anyways.
2023-07-14 11:01:35 +02:00
Joffrey JAFFEUX
ef21450be7
FIX: redirects to browse after removing last followed (#22563)
Prior to this change you might end up in a loop where removing a channel would redirect you to this channel and as we auto-follow opened direct message channels, you could never unfollow this last direct message channel.
2023-07-14 08:26:18 +02:00
Martin Brennan
10d155ea41
DEV: Further improve thread list query and add spec (#22610)
Followup to d7ef7b9c03,
this adds a spec to test the case where old threads are
still unread for the user and should show at the top regardless
of pagination, and fixes some issues/makes some slight refactors.
2023-07-14 16:08:35 +10:00
Martin Brennan
72bbc2fa8a
FIX: created_at datetime format inconsistencies in chat (#22611)
This commit attempts to fix an issue where we are ending
up with bad created_at date formats for last messages, which
is breaking the DM sort order and sometimes causing DM channels
to fall off the list, or show "Invalid date" on mobile.

I have not been able to consistently reproduce these issues
locally, however the serialzier for the channels index uses
MultiJSON.dump() and the Chat::Publisher uses .to_json, both of
which format created_at differently for messages.

The former is `2023-07-05T06:53:25.977Z` (iso8601).

The latter is `2023-07-14 03:59:22 UTC` (.to_s default).

Since we are doing comparison and sorting of these dates on the UI
we need consistent formatting for the JS Date parsers (and moment)
to deal with.

If the issue still occurs after this we can investigate further.
2023-07-14 16:05:01 +10:00
Joffrey JAFFEUX
32e32f43b5
FIX: prevents user to restore message deleted by staff (#22571)
It could only occur on message created by the user itself and deleted while the user was looking at the channel.

It more generally fix the trash service which was not correctly setting the author of the delete.
2023-07-13 10:16:15 +02:00
Joffrey JAFFEUX
c996e5502f
FEATURE: enable_public_channels site setting (#22565)
`SiteSetting.enable_public_channels` allows site admin to decide if public channels are available at all. There's no distinction between admins or not as we expect admins to create private category channels if they want to limit usage.
2023-07-13 10:00:25 +02:00