-
-
Notifications
You must be signed in to change notification settings - Fork 20
Add mention detection to update_message #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Abigayle-Mercer
wants to merge
11
commits into
jupyterlab:main
Choose a base branch
from
Abigayle-Mercer:add-mention-detection-update-message
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+116
−12
Open
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fb2393a
Add mention detection to update_message
abmercer 2e81dcb
added a is_done flag to make sure the full message is sent before men…
abmercer ac993e9
changed variable name
abmercer f6440ea
changed update_message with mentions tests to use sorted() instead of…
abmercer a461740
revert test_add_message_includes_mentions to use set()
abmercer eac0778
changed to a set of actions
abmercer b22ae4c
updated doc string
abmercer 751f5d9
changed trigger actions API to be a list of callbacks, not strings, a…
abmercer 1d7e914
updated name of callback to just be find_mentions
abmercer 8751260
fixed the test naming of callback
abmercer 559cd86
fixed one last import name from find_mentions_callback to just find_m…
abmercer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Copyright (c) Jupyter Development Team. | ||
| # Distributed under the terms of the Modified BSD License. | ||
|
|
||
| """Utility functions for jupyter-chat.""" | ||
|
|
||
| import re | ||
| from typing import TYPE_CHECKING, Set | ||
|
|
||
| if TYPE_CHECKING: | ||
| from .models import Message | ||
| from .ychat import YChat | ||
|
|
||
|
|
||
| def find_mentions_callback(message: "Message", chat: "YChat") -> None: | ||
| """ | ||
| Callback to extract and update mentions in a message. | ||
|
|
||
| Finds all @mentions in the message body and updates the message's mentions list | ||
| with the corresponding usernames. | ||
|
|
||
| Args: | ||
| message: The message object to update | ||
| chat: The YChat instance for accessing user data | ||
| """ | ||
| mention_pattern = re.compile(r"@([\w-]+):?") | ||
| mentioned_names: Set[str] = set(re.findall(mention_pattern, message.body)) | ||
| users = chat.get_users() | ||
| mentioned_usernames = [] | ||
| for username, user in users.items(): | ||
| if user.mention_name in mentioned_names and user.username not in mentioned_usernames: | ||
| mentioned_usernames.append(username) | ||
|
|
||
| message.mentions = mentioned_usernames | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.