diff --git a/contracts/0.2.0/group-slim.js b/contracts/0.2.0/group-slim.js index 81e95c38fd..22c7cbcb25 100644 --- a/contracts/0.2.0/group-slim.js +++ b/contracts/0.2.0/group-slim.js @@ -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) => { diff --git a/contracts/0.2.0/group.0.2.0.manifest.json b/contracts/0.2.0/group.0.2.0.manifest.json index dd9e3824ae..891513feca 100644 --- a/contracts/0.2.0/group.0.2.0.manifest.json +++ b/contracts/0.2.0/group.0.2.0.manifest.json @@ -1 +1 @@ -{"head":{"manifestVersion":"1.0.0"},"body":"{\"version\":\"0.2.0\",\"contract\":{\"hash\":\"21XWnNVqB5fYNAa2mufrsDVWZUsdeW82snkcx4pa4yWjvfTk3c\",\"file\":\"group.js\"},\"authors\":[{\"cipher\":\"algo\",\"key\":\"\"},{\"cipher\":\"algo\",\"key\":\"\"}],\"contractSlim\":{\"file\":\"group-slim.js\",\"hash\":\"21XWnNUmvc1AqRF86c4Wk9hixK64uyG7LHkNi8iNqVs1kXKKpg\"}}","signature":{"key":"","signature":""}} \ No newline at end of file +{"head":{"manifestVersion":"1.0.0"},"body":"{\"version\":\"0.2.0\",\"contract\":{\"hash\":\"21XWnNFFQqoQ2fFncUoEPYCnKyaPuZKVYBxRdR6nY9MypMVyQu\",\"file\":\"group.js\"},\"authors\":[{\"cipher\":\"algo\",\"key\":\"\"},{\"cipher\":\"algo\",\"key\":\"\"}],\"contractSlim\":{\"file\":\"group-slim.js\",\"hash\":\"21XWnNUobHkRALuMvw7jNjkr3o1sWc4YJufJhEg1wDo1ECuy8L\"}}","signature":{"key":"","signature":""}} \ No newline at end of file diff --git a/contracts/0.2.0/group.js b/contracts/0.2.0/group.js index 76337a0cbe..db17da0d8b 100644 --- a/contracts/0.2.0/group.js +++ b/contracts/0.2.0/group.js @@ -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) => { diff --git a/frontend/controller/actions/identity.js b/frontend/controller/actions/identity.js index c47b5cdadc..3bd3bddbc2 100644 --- a/frontend/controller/actions/identity.js +++ b/frontend/controller/actions/identity.js @@ -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') diff --git a/frontend/model/contracts/group.js b/frontend/model/contracts/group.js index ecb2b4ece5..c793f0f7ff 100644 --- a/frontend/model/contracts/group.js +++ b/frontend/model/contracts/group.js @@ -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 diff --git a/frontend/model/contracts/manifests.json b/frontend/model/contracts/manifests.json index b633da234d..9cde60e09c 100644 --- a/frontend/model/contracts/manifests.json +++ b/frontend/model/contracts/manifests.json @@ -1,7 +1,7 @@ { "manifests": { "gi.contracts/chatroom": "21XWnNJr1tLQM1XwNVBUxVCuKADSSJmXVK3DWShAEt6HJeAvD8", - "gi.contracts/group": "21XWnNTihqK5Pwu1Fy9Bf3Eh4MN446oKu7QTSgnQD54q4R93Cy", + "gi.contracts/group": "21XWnNHZDdLhYw8tYLsEENxoPVTSa3PfAyJLyxk8WGspEiEzJe", "gi.contracts/identity": "21XWnNSxNrVFTMBCUVcZV3CG833gTbJ9V8ZyX7Fxgmpj9rNy4r" } }