Skip to content

Commit

Permalink
Implement a way to set default groupId (#1773)
Browse files Browse the repository at this point in the history
* feat: set default group ID which is successfully joined

* fix: recovered package.json
  • Loading branch information
Silver-IT authored Oct 20, 2023
1 parent 5ce96a5 commit 293e12a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion contracts/0.2.0/group-slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -8409,7 +8409,7 @@ ${this.getErrorInfo()}`;
}
await (0, import_sbp6.default)("gi.contracts/group/removeArchivedProposals", contractID);
await (0, import_sbp6.default)("gi.contracts/group/removeArchivedPayments", contractID);
const groupIdToSwitch = Object.keys(contracts).find((cID) => contracts[cID].type === "gi.contracts/group" && cID !== contractID && rootState[cID].settings) || null;
const groupIdToSwitch = Object.keys(contracts).filter((cID) => contracts[cID].type === "gi.contracts/group" && cID !== contractID).sort((cID1, cID2) => rootState[cID1].profiles?.[username] ? -1 : 1)[0] || null;
(0, import_sbp6.default)("state/vuex/commit", "setCurrentChatRoomId", {});
(0, import_sbp6.default)("state/vuex/commit", "setCurrentGroupId", groupIdToSwitch);
(0, import_sbp6.default)("chelonia/contract/remove", contractID).catch((e) => {
Expand Down
2 changes: 1 addition & 1 deletion contracts/0.2.0/group.0.2.0.manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"head":{"manifestVersion":"1.0.0"},"body":"{\"version\":\"0.2.0\",\"contract\":{\"hash\":\"21XWnNVqB5fYNAa2mufrsDVWZUsdeW82snkcx4pa4yWjvfTk3c\",\"file\":\"group.js\"},\"authors\":[{\"cipher\":\"algo\",\"key\":\"<pubkey from deploy-key.json>\"},{\"cipher\":\"algo\",\"key\":\"<pubkey from alex.json>\"}],\"contractSlim\":{\"file\":\"group-slim.js\",\"hash\":\"21XWnNUmvc1AqRF86c4Wk9hixK64uyG7LHkNi8iNqVs1kXKKpg\"}}","signature":{"key":"<which of the 'authors' keys was used to sign 'body'>","signature":"<signature>"}}
{"head":{"manifestVersion":"1.0.0"},"body":"{\"version\":\"0.2.0\",\"contract\":{\"hash\":\"21XWnNFFQqoQ2fFncUoEPYCnKyaPuZKVYBxRdR6nY9MypMVyQu\",\"file\":\"group.js\"},\"authors\":[{\"cipher\":\"algo\",\"key\":\"<pubkey from deploy-key.json>\"},{\"cipher\":\"algo\",\"key\":\"<pubkey from alex.json>\"}],\"contractSlim\":{\"file\":\"group-slim.js\",\"hash\":\"21XWnNUobHkRALuMvw7jNjkr3o1sWc4YJufJhEg1wDo1ECuy8L\"}}","signature":{"key":"<which of the 'authors' keys was used to sign 'body'>","signature":"<signature>"}}
2 changes: 1 addition & 1 deletion contracts/0.2.0/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -17530,7 +17530,7 @@ ${this.getErrorInfo()}`;
}
await (0, import_sbp7.default)("gi.contracts/group/removeArchivedProposals", contractID);
await (0, import_sbp7.default)("gi.contracts/group/removeArchivedPayments", contractID);
const groupIdToSwitch = Object.keys(contracts).find((cID) => contracts[cID].type === "gi.contracts/group" && cID !== contractID && rootState[cID].settings) || null;
const groupIdToSwitch = Object.keys(contracts).filter((cID) => contracts[cID].type === "gi.contracts/group" && cID !== contractID).sort((cID1, cID2) => rootState[cID1].profiles?.[username] ? -1 : 1)[0] || null;
(0, import_sbp7.default)("state/vuex/commit", "setCurrentChatRoomId", {});
(0, import_sbp7.default)("state/vuex/commit", "setCurrentGroupId", groupIdToSwitch);
(0, import_sbp7.default)("chelonia/contract/remove", contractID).catch((e) => {
Expand Down
5 changes: 4 additions & 1 deletion frontend/controller/actions/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ export default (sbp('sbp/selectors/register', {
// NOTE: users could notice that they leave the group by someone else when they log in
if (!state.currentGroupId) {
const { contracts } = state
const gId = Object.keys(contracts).find(cID => contracts[cID].type === 'gi.contracts/group')
// grab the groupID of any group that we've successfully finished joining
const gId = Object.keys(contracts)
.filter(cID => contracts[cID].type === 'gi.contracts/group')
.sort((cID1, cID2) => state[cID1].profiles?.[state.loggedIn.username] ? -1 : 1)[0]
if (gId) {
sbp('gi.actions/group/switch', gId)
const router = sbp('controller/router')
Expand Down
5 changes: 3 additions & 2 deletions frontend/model/contracts/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,9 +917,10 @@ sbp('chelonia/defineContract', {
await sbp('gi.contracts/group/removeArchivedProposals', contractID)
await sbp('gi.contracts/group/removeArchivedPayments', contractID)

// grab the groupID of any group that we've successfully finished joining
const groupIdToSwitch = Object.keys(contracts)
.find(cID => contracts[cID].type === 'gi.contracts/group' &&
cID !== contractID && rootState[cID].settings) || null
.filter(cID => contracts[cID].type === 'gi.contracts/group' && cID !== contractID)
.sort((cID1, cID2) => rootState[cID1].profiles?.[username] ? -1 : 1)[0] || null
sbp('state/vuex/commit', 'setCurrentChatRoomId', {})
sbp('state/vuex/commit', 'setCurrentGroupId', groupIdToSwitch)
// we can't await on this in here, because it will cause a deadlock, since Chelonia processes
Expand Down
2 changes: 1 addition & 1 deletion frontend/model/contracts/manifests.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifests": {
"gi.contracts/chatroom": "21XWnNJr1tLQM1XwNVBUxVCuKADSSJmXVK3DWShAEt6HJeAvD8",
"gi.contracts/group": "21XWnNTihqK5Pwu1Fy9Bf3Eh4MN446oKu7QTSgnQD54q4R93Cy",
"gi.contracts/group": "21XWnNHZDdLhYw8tYLsEENxoPVTSa3PfAyJLyxk8WGspEiEzJe",
"gi.contracts/identity": "21XWnNSxNrVFTMBCUVcZV3CG833gTbJ9V8ZyX7Fxgmpj9rNy4r"
}
}

0 comments on commit 293e12a

Please sign in to comment.