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

fix(capabilities): implement a wrapper for capabilities #12208

Merged
merged 4 commits into from
Jun 14, 2024

Conversation

Antreesy
Copy link
Contributor

@Antreesy Antreesy commented Apr 25, 2024

☑️ Resolves

🖌️ UI Checklist

🖼️ Screenshots / Screencasts

No visual changes

🚧 Tasks

  • Implement logic to check if room is federated, to fetch remote capabilities
    • Think of a way to store/ retrive remote capabilities
      As it's a request to server, it should be asyncronous. That means we must in some case to wait for remote capabilities or re-render application based on response (which is now isn't happen and requires a reload, if capability has changed
      Reload as we do for dirty hash
  • Implement helpers like hasFeature to replace long getCapabilities()?.spreed?.features?.includes('capability')
  • Distinguish between whether to consider local/remote capability (see ref issue)

🏁 Checklist

@Antreesy Antreesy added this to the 💙 Next Major (30) milestone Apr 25, 2024
@Antreesy Antreesy self-assigned this Apr 25, 2024
@Antreesy Antreesy force-pushed the feat/11850/capabilities-wrapper branch 2 times, most recently from e1c3b1f to 47bb67c Compare April 28, 2024 20:30
Copy link
Contributor

@DorraJaouad DorraJaouad left a comment

Choose a reason for hiding this comment

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

You can use store instead of browser storage. The purpose of keeping the last previous fetched capabilities is to check in case the new fetch renders a different list (on the same page) -> store is enough for that.

@Antreesy

This comment was marked as resolved.

@Antreesy Antreesy force-pushed the feat/11850/capabilities-wrapper branch from 47bb67c to 0bf4beb Compare May 8, 2024 16:53
@Antreesy Antreesy changed the base branch from main to feat/noid/add-local-capabilities May 8, 2024 16:54
@Antreesy Antreesy force-pushed the feat/11850/capabilities-wrapper branch from 0bf4beb to 77bc7dd Compare May 10, 2024 08:40
Base automatically changed from feat/noid/add-local-capabilities to main May 10, 2024 10:28
@Antreesy Antreesy force-pushed the feat/11850/capabilities-wrapper branch from 77bc7dd to 326799e Compare May 15, 2024 09:16
@Antreesy Antreesy force-pushed the feat/11850/capabilities-wrapper branch from 326799e to 30650ac Compare May 29, 2024 14:09
@Antreesy Antreesy marked this pull request as ready for review May 29, 2024 14:12
Comment on lines 40 to 45
public hasTalkFeature(token: 'local'|string, feature: string): boolean {
if (this.localCapabilities.spreed['features-local'].includes(feature)) {
return this.localCapabilities?.spreed?.features?.includes(feature) ?? false
}
return this.getCapabilities(token)?.spreed?.features?.includes(feature) ?? false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If the feature is local, we don't need to check remote server at all because those features are usually not affecting the chat, call etc (e.g: note-to-self)
If the feature is not flagged as local, both remote and local capabilities should be checked using AND (if any of the server doesn't have that feature, it should not be there).

Note: we need to be careful when flagging feature/config with local, I noticed that config => attachments => allowed is local whereas it is affecting the chat.

Copy link
Contributor Author

@Antreesy Antreesy Jun 6, 2024

Choose a reason for hiding this comment

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

I'd agree that feature should be respected from both local / remote, if that's related to the conversation; remote user shouldn't have more possibilities, than he already has locally, and more than a local user:

Remote cap. Local cap. Resulting Example
🔴 🔴 🔴 Not conflicting
🟢 🟢 🟢 Not conflicting
🟢 🔴 🔴 "Moderator" from 29 can't ban participants, because he isn't aware of the feature
🔴 🟢 🔴 Can't upload attachments, if not allowed on remote server

But for the config, i think remote should be respected, unless we define it in config-local: as we have numeric and string values there, not only boolean

Copy link
Contributor

Choose a reason for hiding this comment

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

But for the config, i think remote should be respected, unless we define it in config-local: as we have numeric and string values there, not only boolean

For config, it's a bit tricky, maybe min(remote, local) for numeric config and for not measurable numeric (like integers to reflect modes), use remote, right ?
For now, chat-read-status (local) which should be following remote server, no ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or we treat each config individually for now.
chat-read-status differs per user and set up by him, if I'm not mistaken, so should be from local

Copy link
Contributor

Choose a reason for hiding this comment

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

  • chat-read-status (local) - On conversation API v3 and the chat API the last common read message is exposed which can be used to update the "read status" flag of own chat messages. The info should be shown only when the user also shares their read status. The user's value can be found in config => chat => read-privacy.

That means it is first configured by server (expose the last common read message) and then enabled/disabled by user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

chat-read-status isn't used in frontend code, so consider this out of scope of this PR. Let's stick with:

  • features should be respected on both
  • configs should be respected from remote, unless we don't define them as local || unless we don't set code to respect both individually for each case

Speaking of which, @nickvergessen :
config => attachments => allowed, shouldn't we respect both local and remote?
features => avatar, aren't we proxying the same local endpoint for avatar, so only local is enough?

Copy link
Member

Choose a reason for hiding this comment

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

yeah the docs might be from before we decided to proxy avatars.

As for attachments, I guess we should check both, but we can clarify once we implement them

Copy link
Contributor

@ShGKme ShGKme left a comment

Choose a reason for hiding this comment

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

Looks very cool!

Just some implementation nitpicks and questions.

src/services/CapabilitiesManager.ts Outdated Show resolved Hide resolved
src/services/CapabilitiesManager.ts Outdated Show resolved Hide resolved
src/services/CapabilitiesManager.ts Outdated Show resolved Hide resolved
src/services/CapabilitiesManager.ts Outdated Show resolved Hide resolved
src/services/CapabilitiesManager.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@ShGKme ShGKme left a comment

Choose a reason for hiding this comment

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

Looks good to me ✨

- check talk-hash when joining federated conversation
- keep and retrieve capabilities from BrowserStorage
- distinguish cases for local and remote capabilities
- implement 'hasTalkFeature' and 'getTalkConfig' helpers
- respect local-only features and configs

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
…with conversation switch)

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
…ion related)

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
@Antreesy Antreesy force-pushed the feat/11850/capabilities-wrapper branch from 36dff6f to e3bdf72 Compare June 14, 2024 08:27
@Antreesy
Copy link
Contributor Author

Rebased onto main and resolved conflicts (message components and composables)

Copy link
Contributor

@DorraJaouad DorraJaouad left a comment

Choose a reason for hiding this comment

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

Tested 🦅

@Antreesy Antreesy merged commit 617aa3a into main Jun 14, 2024
46 checks passed
@Antreesy Antreesy deleted the feat/11850/capabilities-wrapper branch June 14, 2024 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ☑️ Done
Development

Successfully merging this pull request may close these issues.

Check capabilities of remote server in federated conversations
4 participants