Commit Graph

2227 Commits

Author SHA1 Message Date
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