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

Chelonia in SW #2357

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open

Chelonia in SW #2357

wants to merge 41 commits into from

Conversation

corrideat
Copy link
Member

No description provided.

@corrideat corrideat force-pushed the feature/chelonia-in-service-worker branch from 45eccd8 to 9b89d48 Compare September 19, 2024 17:43
@corrideat
Copy link
Member Author

Tests currently passing:

  • signup-and-login.spec.js

For the non-passing tests, a common theme seems to be that document is undefined. I believe this to be related to DOMPurify, and the best solution seems to be removing it from contracts and the service worker.

Other things that are broken, but which should be easier to fix:

  • Attachments

@corrideat corrideat force-pushed the feature/chelonia-in-service-worker branch from a9068b1 to 4601d99 Compare September 29, 2024 21:06
@corrideat corrideat force-pushed the feature/chelonia-in-service-worker branch from 068c8c1 to ba57fb4 Compare October 9, 2024 18:32
Copy link

cypress bot commented Oct 9, 2024

group-income    Run #3379

Run Properties:  status check passed Passed #3379  •  git commit 5db201867e ℹ️: Merge 74b2dfa934cc1b396de829d72edfdee73deb751f into 3b142e94445de8ab49b435e8d4bd...
Project group-income
Branch Review feature/chelonia-in-service-worker
Run status status check passed Passed #3379
Run duration 10m 45s
Commit git commit 5db201867e ℹ️: Merge 74b2dfa934cc1b396de829d72edfdee73deb751f into 3b142e94445de8ab49b435e8d4bd...
Committer Ricardo Iván Vieitez Parra
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 10
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 111
View all changes introduced in this branch ↗︎

Comment on lines +46 to +49
isDMOrMention: isMentionedMe || state.attributes?.type === CHATROOM_TYPES.DIRECT_MESSAGE,
messageType: !newMessage ? MESSAGE_TYPES.TEXT : data.type,
memberID: innerSigningContractID,
chatRoomName: getters.chatRoomAttributes.name
chatRoomName: state.attributes?.name
Copy link
Member

Choose a reason for hiding this comment

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

What is preventing us from moving the getter definitions into a file that is shared by the frontend and the SW?

That would be much preferable to this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Chatroom getters are a Vuex module, which are harder to emulate without Vuex because of state partitioning. In addition, those getters rely on currentGroupId and currentChatroomId which can't be used in contracts.

Copy link
Member

@taoeffect taoeffect Oct 10, 2024

Choose a reason for hiding this comment

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

Is there nothing creative that's possible here? We can't define getters in a way that has them referring to the "the chatroom that corresponds to this state"?

i.e. "state paritioned getters" ala gettersProxy? (see bottom of chelonia.js)

Copy link
Member Author

@corrideat corrideat Oct 10, 2024

Choose a reason for hiding this comment

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

the chatroom that corresponds to this state

How would that even be possible the way getters are defined? I don't really see an issue with the lines highlighted, and I'm not even sure why we'd need a getter that returns a single property.

But going to the definition:

  chatRoomAttributes (state, getters) {
    return getters.currentChatRoomState.attributes || {}
  },

Sure, in this instance state corresponds to getters.currentChatRoomState, but I don't see how generically we can know what getters.currentChatRoomState should be (generically). In the app, it works because (remember this is a global getter) there is a currentChatRoomId. In contracts it works, because currentChatRoomState can be defined to return 'state'. In the SW, the situation is analogous to the app, but there's no currentChatRoomId.

Now, this could maybe work by having a getter that takes the contractID as a function parameter, but this requires refactoring and adds complexity. I also think such getters that are simply accessors should be avoided, as they increase code line count and complexity for no benefit.

Copy link
Member Author

@corrideat corrideat Oct 10, 2024

Choose a reason for hiding this comment

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

Thinking about it, another solution along the lines of what you suggested could be something like:

const getters = sbp('chelonia/contract/getters', 'gi.contracts/chatroom', state)
getters.currentChatRoomState

But honestly, for simple accessors such as these I don't see the benefit of adding this complexity. This also adds two other factors:

  1. If the getters are hardcoded (as in, statically imported), it increases bundle size
  2. If the getters are dynamic, they'll probably need to be async (in case the contract isn't loaded) and because of sandboxing (maybe).

Copy link
Member

Choose a reason for hiding this comment

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

@corrideat would it be possible to instantiate dynamically a new batch of getters where getters. currentChatRoomState returns a specific contract state in the SW using some sort of factory function?

I also think such getters that are simply accessors should be avoided, as they increase code line count and complexity for no benefit.

Getters are very important, as they solve a lot of DRY related problems. By using getters we can ensure that the way that data is accessed everywhere will have consistent return values (e.g. because it uses tricks like || {} etc.). Whereas those considerations would have to be thought of each time you access state data directly.

Copy link
Member

@taoeffect taoeffect Oct 10, 2024

Choose a reason for hiding this comment

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

const getters = sbp('chelonia/contract/getters', 'gi.contracts/chatroom', state)

Yeah, that's a great idea!

I'd make one slight modification: instead of passing in state, passing in contractID:

const getters = sbp('chelonia/contract/getters', contractID)

(EDIT: I don't think you need to pass in the name, that can be retrieved using contractID if needed)

Then yeah, at least we could reuse the contract getters that are already defined in the contracts!

Copy link
Member Author

Choose a reason for hiding this comment

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

Update based on today's conversation: we could use getters synchronously by importing the contract getters from this actions file. However, it'd have the downside of being 'statically hardcoded' based on whatever version is imported at build time and will increase bundle size. Doing it via Chelonia is potentially possible, but it'd need to be async in case the contract isn't cached and need to be loading and also maybe because of sandboxing.

@corrideat corrideat force-pushed the feature/chelonia-in-service-worker branch from 8167a3f to e5f8ed2 Compare October 14, 2024 18:08
@corrideat corrideat force-pushed the feature/chelonia-in-service-worker branch from 60603b0 to 286570a Compare October 16, 2024 16:05
@corrideat corrideat force-pushed the feature/chelonia-in-service-worker branch from b4579d2 to e6a31ed Compare October 19, 2024 19:17
@corrideat corrideat force-pushed the feature/chelonia-in-service-worker branch from e6a31ed to 17f3e77 Compare October 19, 2024 20:24
@corrideat corrideat marked this pull request as ready for review October 20, 2024 16:43
Comment on lines 32 to 33
// TODO: rootState.unreadMessages for SW
const isAlreadyAdded = rootState.chatroom?.unreadMessages?.[contractID]?.unreadMessages.find(m => m.messageHash === data.hash)
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to keep the getter?

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason that the getter isn't being used here is that although I added a wrapper for root getters, these are Vuex modules, which work a bit differently due to state partitioning. At the time, the separate state keys being used by the module weren't there. Now they are, and it would be feasible to similarly have this work.

While I think that in this instance it'd be possible to use a getter, many getters are written to rely on curentXXXId, which is problematic in the SW.

@taoeffect
Copy link
Member

taoeffect commented Oct 24, 2024

After signing up a new user, I got the last two errors:

Screenshot 2024-10-24 at 11 11 49 AM

service-worker.js:193:

Screenshot 2024-10-24 at 11 12 41 AM

Note: this happened twice in FFDev, once for u1, and once for u2 when joining using invite link.

@taoeffect
Copy link
Member

I'm also not hearing notification sounds upon @mention. Did you merge latest master that fixed this?

@taoeffect
Copy link
Member

In Safari, u3 joined, and u2 (in FFDev) made a proposal, then u3 switched form Chat to Dashboard to see proposal, then u1 approved proposal (in FFDev), then u3 (in Safari) switched back to Chatroom:

Screenshot 2024-10-24 at 11 18 17 AM

@corrideat
Copy link
Member Author

After signing up a new user, I got the last two errors:

I need some more background on what exactly you were doing (e.g., what you were doing before). The mismatch error indicates that the event received is for the wrong identity contract. For the pubsub error, I don't need additional information at this point.

I'm also not hearing notification sounds upon @mention. Did you merge latest master that fixed this?

Presumably not. I've just merged master.

In Safari, u3 joined, and u2 (in FFDev) made a proposal, then u3 switched form Chat to Dashboard to see proposal, then u1 approved proposal (in FFDev), then u3 (in Safari) switched back to Chatroom:

I see. This looks like an issue with structuredClone somewhere. I don't have Safari so testing this might be challenging if it's a Safari-only issue.

@corrideat corrideat force-pushed the feature/chelonia-in-service-worker branch from c15e05e to f7bc3d4 Compare October 25, 2024 16:10
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.

2 participants