Skip to content
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

Implement message link inside message #2005

Merged
merged 30 commits into from
Jun 19, 2024

Conversation

Silver-IT
Copy link
Member

@Silver-IT Silver-IT commented May 22, 2024

@Silver-IT Silver-IT requested a review from taoeffect May 22, 2024 01:56
@Silver-IT Silver-IT self-assigned this May 22, 2024
@Silver-IT Silver-IT linked an issue May 22, 2024 that may be closed by this pull request
Copy link

cypress bot commented May 22, 2024

Passing run #2428 ↗︎

0 106 8 0 Flakiness 0

Details:

Merge e80605d into 461b76f...
Project: group-income Commit: c3522570ff ℹ️
Status: Passed Duration: 09:45 💡
Started: Jun 18, 2024 11:38 PM Ended: Jun 18, 2024 11:48 PM

Review all test suite changes for PR #2005 ↗︎

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, it seems to work really well on Desktop, but on mobile it doesn't work at all.

Please try with grunt dev --tunnel and then with a cellphone + Desktop.

On desktop you'll have URLs that look like this: http://localhost:3000/....

You'll need to replace that with the URL that localtunnel gives you, e.g. https://gi5209.loca.lt/... in order to test on mobile.

@Silver-IT
Copy link
Member Author

Silver-IT commented May 28, 2024

Nice, it seems to work really well on Desktop, but on mobile it doesn't work at all.

Having tested in mobile, it works fine to me. Both in browser and PWA. @SebinSong, can you please try to review this PR? Especially, test how message link works in mobile.

@taoeffect taoeffect assigned SebinSong and unassigned SebinSong May 28, 2024
@taoeffect taoeffect requested a review from SebinSong May 28, 2024 16:49
@SebinSong
Copy link
Collaborator

SebinSong commented May 28, 2024

@Silver-IT I will review this PR once I have time this week.

Especially, test how message link works in mobile.

you can test it yourself using grunt dev --tunnel btw.

EDIT: I just realised you mentioned you already did. ;)

@Silver-IT
Copy link
Member Author

Silver-IT commented May 28, 2024

I will review this PR once I have time this week.

Thanks, @SebinSong. When you test this PR, do not make mistake in creating message links.
In order to test message link in mobile, you should create link in mobile.
And in order to test it in desktop, you should create link in desktop browser.

That's because hostnames would be different; one would be http://localhost:8000 (Of course, when you do not use tunnel to test this PR in your desktop), and the other would be like https://gi5209.local.lt.

cc: @taoeffect

@SebinSong
Copy link
Collaborator

@taoeffect

That's because hostnames would be different; one would be http://localhost:8000 (Of course, when you do not use tunnel to test this PR in your desktop), and the other would be like https://gi5209.local.lt.

That's too obvious... but thnx for a reminder.

@Silver-IT
Copy link
Member Author

I will mark this PR as draft, and I am going to fix the Issue #1945 inside this PR. That issue is very much similar to the current issue #1949.

@Silver-IT Silver-IT marked this pull request as ready for review May 31, 2024 09:32
@Silver-IT
Copy link
Member Author

Need to consider the Issue #2041 too. This is the comment to me.

@Silver-IT Silver-IT requested a review from taoeffect June 6, 2024 10:50
Copy link
Member Author

@Silver-IT Silver-IT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready for the review!

Comment on lines 786 to 790
this.updateScroll(messageHashToScroll, Boolean(mhash)).then(() => {
if (mhash) {
this.$router.replace({ query: {} })
}
})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to remove mhash in queries after scroll to and highlight the message with mhash. Since we use only mhash as query in the Chat page, so just made query empty.

Comment on lines 26 to 52
if (entry.tagName === 'ROUTER') {
const hasChildren = Array.isArray(entry.children)
const route = entry.attributes.route && JSON.parse(entry.attributes.route)
const href = route && this.$router.resolve(route).href
return createElement(
'a',
{
class: 'link',
attrs: {
href
},
on: {
click: (e) => {
route && this.$router.push(route)
e?.preventDefault()
},
touchhold: (e) => {
href && sbp('okTurtles.events/emit', OPEN_TOUCH_LINK_HELPER, href)
e?.preventDefault()
}
}
},
hasChildren
? entry.children.map(child => recursiveCall(child))
: undefined
)
} else if (entry.tagName) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to find in-app links which are created by makeInAppLinkElement function and create elements in real.

Copy link
Collaborator

@SebinSong SebinSong Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Silver-IT , it looks like this additional block has some duplicate codes with the else if (entry.tagName) { ... } below.
I would DRY this by including the logic in there like,

if (entry.tagName) {
  const hasChildren = Array.isArray(entry.children)
  const isRouter = entry.tagName === 'ROUTER'

  const elName =  isRouter ? 'a' : entry.tagName.toLowerCase()
  const opts = isRouter
    ? {
          // options you created above
       }
    :  {
          // default options
        }
    
  ....
  
   return createElement(
     elName,
     opts,
     hasChildren
        ? entry.children.map(child => recursiveCall(child))
        : undefined
   )
}

Comment on lines 218 to 221
} else if (mhash) {
this.$refs.chatMain?.scrollToMessage(mhash).then(() => {
this.$router.replace({ query: {} })
})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When user clicks the link to the message of the current chatroom, it is handled in here.

frontend/views/utils/markdown-utils.js Outdated Show resolved Hide resolved
frontend/views/utils/markdown-utils.js Outdated Show resolved Hide resolved
@SebinSong
Copy link
Collaborator

Hi @Silver-IT , Just roughly read through this PR and (correct me if I'm wrong) what some of logics here does is apparently, it intercepts the link markdown and

  1. check if hostname in the href is the same as the app.
  2. if so, turns this into <router> ... </router>
  3. But then, this again is turned back into <a>..</a> tag later on down the line.

could you give some explanation on why adding step 2. & 3. here was necessary?

Cuz below block added in this PR feels redundant (Or it's that I don't have a full understanding on the context of the issue.)

    on: {
      click: (e) => {
        route && this.$router.push(route)
        e?.preventDefault()
      },
      touchhold: (e) => {
        href && sbp('okTurtles.events/emit', OPEN_TOUCH_LINK_HELPER, href)
        e?.preventDefault()
      }
    }

$router.push(...) can be achieved via <a href='app-hostname/path'></a> too and sbp('okTurtles.events/emit', OPEN_TOUCH_LINK_HELPER, href) here is already handled by the ancestor component which is MessageBase.vue (here).

@Silver-IT
Copy link
Member Author

Could you give some explanation on why adding step 2. & 3. here was necessary?

@SebinSong, that's very nice catch. I've just realised those two steps seems not be necessary. Actually, the logic was implemented before you finished improving the way to render messages which contains markdown and mentions. But now, when your code is already implemented, I don't think those two steps are needed any more. 👍

And also I think we can use the RenderMessageWithMarkdown component for BannerGeneral and BannerScoped component either. Do you think it's fine too?

@SebinSong
Copy link
Collaborator

SebinSong commented Jun 11, 2024

@Silver-IT I just tried your fix in both desktop and in my mobile phone and it works well for both.

And also I think we can use the RenderMessageWithMarkdown component for BannerGeneral and BannerScoped component either. Do you think it's fine too?

And yes, for anywhere it can be useful and also pls feel free to enhance the component to suit your need.

SebinSong
SebinSong previously approved these changes Jun 13, 2024
Copy link
Collaborator

@SebinSong SebinSong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @Silver-IT

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @Silver-IT!

I tested this and it seems to work almost perfectly.

A few remaining issues:

On mobile, clicking "report the error" shows wrong view

Screenshot 2024-06-14 at 1 18 31 PM

Flow errors

Running "exec:flow" (exec) task
Error ------------------------------ frontend/views/containers/chatroom/chat-mentions/RenderMessageWithMarkdown.js:40:27

Cannot assign object literal to `routerOptions.route` because property `route` is missing in object literal [1].
[prop-missing]

   frontend/views/containers/chatroom/chat-mentions/RenderMessageWithMarkdown.js:40:27
   40|             routerOptions.route = { path, query }
                                 ^^^^^

References:
   frontend/views/containers/chatroom/chat-mentions/RenderMessageWithMarkdown.js:30:31
   30|         const routerOptions = { isInAppRouter: false }
                                     ^^^^^^^^^^^^^^^^^^^^^^^^ [1]


Error ------------------------------ frontend/views/containers/chatroom/chat-mentions/RenderMessageWithMarkdown.js:41:27

Cannot assign `this.$router.resolve(...).href` to `routerOptions.href` because property `href` is missing in object
literal [1]. [prop-missing]

   frontend/views/containers/chatroom/chat-mentions/RenderMessageWithMarkdown.js:41:27
   41|             routerOptions.href = this.$router.resolve(routerOptions.route).href
                                 ^^^^

References:
   frontend/views/containers/chatroom/chat-mentions/RenderMessageWithMarkdown.js:30:31
   30|         const routerOptions = { isInAppRouter: false }
                                     ^^^^^^^^^^^^^^^^^^^^^^^^ [1]



Found 2 errors
The Flow check failed!

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost ready to merge, still a flow error:

Running "exec:flow" (exec) task
Error ------------------------------------------------------------------ frontend/controller/actions/identity.js:801:102

Cannot call `deleteResult.map` because property `map` is missing in possibly uninitialized variable [1].
[incompatible-use]

   frontend/controller/actions/identity.js:801:102
   801|       console.error('[gi.actions/identity/removeFiles] Some CIDs could not be deleted', deleteResult.map((r, i) => r.status === 'rejected' && toDelete[i]).filter(Boolean))
                                                                                                             ^^^

References:
   frontend/controller/actions/identity.js:766:9
   766|     let deleteResult, toDelete
                ^^^^^^^^^^^^ [1]



Found 1 error
The Flow check failed!

Copy link
Member

@taoeffect taoeffect left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that flow error is from master, and @SebinSong fixes it in #2090

@taoeffect taoeffect merged commit 8e35f72 into master Jun 19, 2024
4 checks passed
@taoeffect taoeffect deleted the 1949-linking-to-messages-doesnt-work branch June 19, 2024 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linking to messages doesn't work Clicking "report the error" in the emergency banner doesn't work
3 participants