Commit Graph

16 Commits

Author SHA1 Message Date
Andrei Prigorshnev 69c7df2e56
DEV: do not fabricate a Notification when fabricating a ChatMention (#20450)
Initially, the chat_mention db table was created to support notifications. So when creating 
a `chat_mention` record we were always creating a related `notification` record. So did the
ChatMention fabricator. 

Now we want to use the chat_mention db table in other scenarios. So we started decoupling 
mentions from notification in 75b81b68.

This removes fabrication of Notifications from the ChatMention fabricator. We need to be able 
to fabricate a ChatMention without a Notification.
2023-02-27 14:41:28 +04: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
Martin Brennan 9a45b59fb5
FEATURE: Automatically create chat threads in background (#20206)
Whenever we create a chat message that is `in_reply_to` another
message, we want to lazily populate the thread record for the
message chain.

If there is no thread yet for the root message in the reply chain,
we create a new thread with the appropriate details, and use that
thread ID for every message in the chain that does not yet have
a thread ID.

* Root message (ID 1) - no thread ID
    * Message (ID 2, in_reply_to 1) - no thread ID
    * When I as a user create a message in reply to ID 2, we create a thread and apply it to ID 1, ID 2, and the new message

If there is a thread for the root message in the reply chain, we
do not create one, and use the thread ID for the newly created chat
message.

* Root message (ID 1) - thread ID 700
    * Message (ID 2, in_reply_to 1) - thread ID 700
    * When I as a user create a message in reply to ID 2, we use the existing thread ID 700 for the new message

We also support passing in the `thread_id` to `ChatMessageCreator`,
which will be used when replying to a message that is already part of
a thread, and we validate whether that `thread_id` is okay in the context
of the channel and also the reply chain.

This work is always done, regardless of channel `thread_enabled` settings
or the `enable_experimental_chat_threaded_discussions` site setting.

This commit does not include a large data migration to backfill threads for
all existing reply chains, its unnecessary to do this so early in the project,
we can do this later if necessary.

This commit also includes thread considerations in the `MessageMover` class:

* If the original message and N other messages of a thread is moved,
   the remaining messages in the thread have a new thread created in
   the old channel and are moved to it.
* The reply chain is not preserved for moved messages, so new threads are
   not created in the destination channel.

In addition to this, I added a fix to also clear the `in_reply_to_id` of messages
in the old channel which are moved out of that channel for data cleanliness.
2023-02-08 10:22:07 +10:00
Martin Brennan 1a6f6d1dc4
Revert "FEATURE: Automatically create chat threads in background (#20132)" (#20205)
This reverts commit 37e6e3be7f.
2023-02-08 09:59:18 +10:00
Martin Brennan 37e6e3be7f
FEATURE: Automatically create chat threads in background (#20132)
Whenever we create a chat message that is `in_reply_to` another
message, we want to lazily populate the thread record for the
message chain.

If there is no thread yet for the root message in the reply chain,
we create a new thread with the appropriate details, and use that
thread ID for every message in the chain that does not yet have
a thread ID.

* Root message (ID 1) - no thread ID
    * Message (ID 2, in_reply_to 1) - no thread ID
    * When I as a user create a message in reply to ID 2, we create a thread and apply it to ID 1, ID 2, and the new message

If there is a thread for the root message in the reply chain, we
do not create one, and use the thread ID for the newly created chat
message.

* Root message (ID 1) - thread ID 700
    * Message (ID 2, in_reply_to 1) - thread ID 700
    * When I as a user create a message in reply to ID 2, we use the existing thread ID 700 for the new message

We also support passing in the `thread_id` to `ChatMessageCreator`,
which will be used when replying to a message that is already part of
a thread, and we validate whether that `thread_id` is okay in the context
of the channel and also the reply chain.

This work is always done, regardless of channel `thread_enabled` settings
or the `enable_experimental_chat_threaded_discussions` site setting.

This commit does not include a large data migration to backfill threads for
all existing reply chains, its unnecessary to do this so early in the project,
we can do this later if necessary.

This commit also includes thread considerations in the `MessageMover` class:

* If the original message and N other messages of a thread is moved,
   the remaining messages in the thread have a new thread created in
   the old channel and are moved to it.
* The reply chain is not preserved for moved messages, so new threads are
   not created in the destination channel.

In addition to this, I added a fix to also clear the `in_reply_to_id` of messages
in the old channel which are moved out of that channel for data cleanliness.
2023-02-08 09:50:42 +10:00
Martin Brennan 0924f874bd
DEV: Use UploadReference instead of ChatUpload in chat (#19947)
We've had the UploadReference table for some time now in core,
but it was added after ChatUpload was and chat was just never
moved over to this new system.

This commit changes all chat code dealing with uploads to create/
update/delete/query UploadReference records instead of ChatUpload
records for consistency. At a later date we will drop the ChatUpload
table, but for now keeping it for data backup.

The migration + post migration are the same, we need both in case
any chat uploads are added/removed during deploy.
2023-01-24 13:28:21 +10:00
David Taylor 055310cea4
DEV: Apply syntax_tree formatting to `plugins/*` 2023-01-07 11:11:37 +00:00
Martin Brennan d147e92953
FIX: Do not duplicate check when editing chat message to remove uploads (#19432)
There is no need to duplicate check chat messages when they are being
edited but not having their message text changed. This was leading to
a validation error when adding/removing an upload but not changing the
message text.
2022-12-14 10:48:23 +10:00
Joffrey JAFFEUX 179d15d90e
FIX: webhook should touch channel’s last_message_sent_at (#19342) 2022-12-06 19:33:39 +01:00
Martin Brennan 3de765c895
SECURITY: Limit chat message char length (#19207)
Only allow maximum of 6000 characters for chat messages when they
are created or edited. A hidden setting can control this limit,
6000 is the default.

There is also a migration here to truncate any existing messages to
6000 characters if the message is already over that and if the
chat_messages table exists. We also set cooked_version to NULL
for those messages so we can identify them for rebake.
2022-11-28 10:48:30 +10:00
Roman Rizzi 698c3ced15
FIX: Deliver chat summaries when allowed groups include "everyone" (#18955)
The mailer in charge of sending chat summary emails applies a filter to ensure only members of groups listed in the `chat allowed groups` setting receive them. However, when you set it to `everyone`, nobody will be notified because
we treat this group differently and don't create `GroupUser` records for every user on the site.

This commit changes the mailer to skip the filter when the `everyone` ID is in the list.
2022-11-09 10:54:47 -03:00
Martin Brennan c66743ee3d
FIX: Make ChatMessageUpdater check editing access for guardian (#18902)
Follow up to 766bcbc684

This fixes a gaffe from that commit where I passed in the
guardian to ChatMessageUpdater but then forgot to remove
the old way of setting the guardian and user instance variables
from the chat_message that was passed in.

Also, it moves the ensure_can_edit_message! check from the
controller into ChatMessageUpdater so all the access
checks are in the same place.
2022-11-08 09:04:18 +10:00
Rafael dos Santos Silva 3174e8e60f
DEV: DiscourseEvents for chat messages (#18914) 2022-11-07 19:06:10 +01:00
Martin Brennan 766bcbc684
FIX: Add editing user ids to ChatMessage and ChatMessageRevision (#18877)
This commit adds last_editor_id to ChatMessage for parity with Post in
core, as well as adding user_id to the ChatMessageRevision record since
we need to know who is making edits and revisions to messages, in case
in future we want to allow more than just the current user to edit chat
messages. The backfill for data here simply uses the record's creating
user ID, but in future if we allow other people to edit the messages it
will use their ID.
2022-11-07 09:04:47 +10:00
Loïc Guitaut abcaa1a961 DEV: Rename direct message related models
This is a followup of the previous refactor where we created two new
models to handle all the dedicated logic that was present in the
`ChatChannel` model.

For the sake of consistency, `DMChannel` has been renamed to
`DirectMessageChannel` and the previous `DirectMessageChannel` model is
now named `DirectMessage`. This should help reasoning about direct
messages.
2022-11-03 14:39:23 +01:00
Roman Rizzi 0a5f548635
DEV: Move `discourse-chat` to the core repo. (#18776)
As part of this move, we are also renaming `discourse-chat` to `chat`.
2022-11-02 10:41:30 -03:00