- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 859
[wip] [mentions] feat: tag mentions #3688
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
          
     Closed
      
      
    
  
     Closed
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            37 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      847db82
              
                wip: begin creating tag mention feature
              
              
                imorland b8914f7
              
                Apply fixes from StyleCI
              
              
                StyleCIBot fb29374
              
                chore: format js
              
              
                imorland 31fdba3
              
                implement relation sync
              
              
                imorland c7895b6
              
                Apply fixes from StyleCI
              
              
                StyleCIBot f1483ab
              
                use the new conditional migration
              
              
                imorland bd07106
              
                Adjust format of tag mentions
              
              
                imorland 7ab9085
              
                implement permission
              
              
                imorland bf86a45
              
                Apply fixes from StyleCI
              
              
                StyleCIBot 83558f0
              
                autocomplete working, but need to refactor out to use # for tagmentions
              
              
                imorland 574b281
              
                chore: deprecate getMentionText, replace with MentionTextGenerator
              
              
                imorland c70eedd
              
                typos
              
              
                imorland cce76da
              
                avoid code duplication
              
              
                imorland a28e7ea
              
                add missing return
              
              
                imorland 290c744
              
                compat
              
              
                imorland 0777d4f
              
                Merge branch 'main' into im/mention-tags
              
              
                imorland 3cf6908
              
                chore: move backend logic to tags ext
              
              
                imorland da751a7
              
                Apply fixes from StyleCI
              
              
                StyleCIBot 06ea4c2
              
                Merge branch 'main' into im/mention-tags
              
              
                imorland cbc6839
              
                Apply fixes from StyleCI
              
              
                StyleCIBot e48faac
              
                typo in class name
              
              
                imorland ad9b2f8
              
                move listener to tags ext
              
              
                imorland 132ca73
              
                Apply fixes from StyleCI
              
              
                StyleCIBot 158f06c
              
                Move remaining backend tagMention relations to tags ext
              
              
                imorland 2e01cf9
              
                cleanup extend
              
              
                imorland 070ed9d
              
                Move permission to tags ext
              
              
                imorland 6ef7a07
              
                move permission pt2
              
              
                imorland 5b218e9
              
                revert now unneeded userattributes class
              
              
                imorland ff23293
              
                move formatter for tag mentions to tags
              
              
                imorland 625eaed
              
                check for mentions enabled, not tags
              
              
                imorland ccc25ba
              
                Extract tagmention data for syncing
              
              
                imorland a90a2d2
              
                remove 2nd param
              
              
                imorland 7016f6d
              
                move import
              
              
                imorland 4ab9ba9
              
                Merge branch 'main' into im/mention-tags
              
              
                imorland eb11255
              
                move tag mention generator
              
              
                imorland 8bbc4f9
              
                composer autocomplete, remove permission
              
              
                imorland 15ea184
              
                remove mentions enabled check
              
              
                imorland 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
    
  
  
    
              
        
          
  
    
      
          
            67 changes: 67 additions & 0 deletions
          
          67 
        
  extensions/mentions/js/src/forum/utils/MentionTextGenerator.ts
  
  
      
      
   
        
      
      
    
  
    
      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,67 @@ | ||
| import getCleanDisplayName, { shouldUseOldFormat } from './getCleanDisplayName'; | ||
| import type User from 'flarum/common/models/User'; | ||
| import type Group from 'flarum/common/models/Group'; | ||
|  | ||
| /** | ||
| * Fetches the mention text for a specified model. | ||
| */ | ||
| export default class MentionTextGenerator { | ||
| /** | ||
| * Automatically determines which mention syntax to be used based on the option in the | ||
| * admin dashboard. Also performs display name clean-up automatically. | ||
| * | ||
| * @"Display name"#UserID or `@username` | ||
| * | ||
| * @example <caption>New display name syntax</caption> | ||
| * // '@"user"#1' | ||
| * forUser(User) // User is ID 1, display name is 'User' | ||
| * | ||
| * @example <caption>Using old syntax</caption> | ||
| * // '@username' | ||
| * forUser(user) // User's username is 'username' | ||
| * | ||
| * @param user | ||
| * @returns string | ||
| */ | ||
| forUser(user: User): string { | ||
| if (shouldUseOldFormat()) { | ||
| const cleanText = getCleanDisplayName(user, false); | ||
| return `@${cleanText}`; | ||
| } | ||
| const cleanText = getCleanDisplayName(user); | ||
| return `@"${cleanText}"#${user.id()}`; | ||
| } | ||
|  | ||
| /** | ||
| * Generates the syntax for mentioning of a post. Also cleans up the display name. | ||
| * | ||
| * @example <caption>Post mention</caption> | ||
| * // '@"User"#p13' | ||
| * // @"Display name"#pPostID | ||
| * forPostMention(user, 13) // User display name is 'User', post ID is 13 | ||
| * | ||
| * @param user | ||
| * @param postId | ||
| * @returns | ||
| */ | ||
| forPostMention(user: User, postId: number): string { | ||
| const cleanText = getCleanDisplayName(user); | ||
| return `@"${cleanText}"#p${postId}`; | ||
| } | ||
|  | ||
| /** | ||
| * Generates the mention syntax for a group mention. | ||
| * | ||
| * @"Name Plural"#gGroupID | ||
| * | ||
| * @example <caption>Group mention</caption> | ||
| * // '@"Mods"#g4' | ||
| * forGroup(group) // Group display name is 'Mods', group ID is 4 | ||
| * | ||
| * @param group | ||
| * @returns string | ||
| */ | ||
| forGroup(group: Group): string { | ||
| return `@"${group.namePlural()}"#g${group.id()}`; | ||
| } | ||
| } | 
  
    
      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,28 @@ | ||
| { | ||
| // Use Flarum's tsconfig as a starting point | ||
| "extends": "flarum-tsconfig", | ||
| // This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder | ||
| // and also tells your Typescript server to read core's global typings for | ||
| // access to `dayjs` and `$` in the global namespace. | ||
| "include": [ | ||
| "src/**/*", | ||
| "../../../framework/core/js/dist-typings/@types/**/*", | ||
| "@types/**/*" | ||
| ], | ||
| "compilerOptions": { | ||
| // This will output typings to `dist-typings` | ||
| "declarationDir": "./dist-typings", | ||
| "paths": { | ||
| "flarum/*": [ | ||
| "../../../framework/core/js/dist-typings/*" | ||
| ], | ||
| // TODO: remove after export registry system implemented | ||
| // Without this, the old-style `@flarum/core` import is resolved to | ||
| // source code in flarum/core instead of the dist typings. | ||
| // This causes an inaccurate "duplicate export" error. | ||
| "@flarum/core/*": [ | ||
| "../../../framework/core/js/dist-typings/*" | ||
| ], | ||
| } | ||
| } | ||
| } | 
  
    
      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 | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| .PostMention, .UserMention, .GroupMention { | ||||||
| .PostMention, .UserMention, .GroupMention, .TagMention { | ||||||
| background: @control-bg; | ||||||
| color: @control-color; | ||||||
| border-radius: @border-radius; | ||||||
|  | @@ -14,7 +14,7 @@ | |||||
| color: @link-color; | ||||||
| } | ||||||
| } | ||||||
| .UserMention, .PostMention, .GroupMention { | ||||||
| .UserMention, .PostMention, .GroupMention, .TagMention { | ||||||
| &--deleted { | ||||||
| opacity: 0.8; | ||||||
| filter: grayscale(1); | ||||||
|  | @@ -97,7 +97,7 @@ | |||||
| position: absolute; | ||||||
| .Button--color(@tooltip-color, @tooltip-bg); | ||||||
| } | ||||||
| .GroupMention { | ||||||
| .GroupMention, .TagMention { | ||||||
| & when (@config-dark-mode = false) { | ||||||
| &, | ||||||
| &:hover, | ||||||
|  | @@ -117,22 +117,30 @@ | |||||
| &, | ||||||
| &:hover, | ||||||
| &:active { | ||||||
| color: @text-on-light; | ||||||
| color: @text-on-dark; | ||||||
| } | ||||||
| } | ||||||
|  | ||||||
| &--dark { | ||||||
| &, | ||||||
| &:hover, | ||||||
| &:active { | ||||||
| color: @text-on-dark; | ||||||
| color: @text-on-light; | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and so on 
        Suggested change
       
 | ||||||
| } | ||||||
| } | ||||||
|  | ||||||
| .icon { | ||||||
| margin-left: 5px; | ||||||
| } | ||||||
| } | ||||||
| .TagMention { | ||||||
| padding-left: 8px; | ||||||
| padding-right: 8px; | ||||||
| .icon { | ||||||
| margin-left: 0; | ||||||
| margin-right: 5px; | ||||||
| } | ||||||
| } | ||||||
| .MentionsDropdown .Badge { | ||||||
| box-shadow: none; | ||||||
| } | ||||||
|  | ||||||
      
      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.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
following my previous comment