Skip to content

Commit

Permalink
feat: remove notifications when leave group (#1722)
Browse files Browse the repository at this point in the history
  • Loading branch information
Silver-IT authored Sep 24, 2023
1 parent b157774 commit 0b88e1d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions contracts/0.2.0/group-slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -7677,6 +7677,9 @@ ${this.getErrorInfo()}`;
var findKeyIdByName = (state, name) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).find((k) => k.name === name && k._notAfterHeight === void 0)?.id;
var findForeignKeysByContractID = (state, contractID) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).filter((k) => k._notAfterHeight === void 0 && k.foreignKey?.includes(contractID)).map((k) => k.id);

// frontend/model/notifications/mutationKeys.js
var REMOVE_NOTIFICATION = "removeNotification";

// frontend/model/contracts/group.js
function vueFetchInitKV(obj, key, initialValue) {
let value = obj[key];
Expand Down Expand Up @@ -8359,6 +8362,7 @@ ${this.getErrorInfo()}`;
},
sideEffect({ data, meta, contractID }, { state, getters }) {
const rootState = (0, import_sbp5.default)("state/vuex/state");
const rootGetters = (0, import_sbp5.default)("state/vuex/getters");
const contracts = rootState.contracts || {};
const { username } = rootState.loggedIn;
if (data.member === username) {
Expand All @@ -8383,6 +8387,9 @@ ${this.getErrorInfo()}`;
}).then(() => (0, import_sbp5.default)("gi.contracts/group/revokeGroupKeyAndRotateOurPEK", contractID)).catch((e) => {
console.error(`sideEffect(removeMember): ${e.name} thrown during revokeGroupKeyAndRotateOurPEK to ${contractID}:`, e);
});
for (const notification of rootGetters.notificationsByGroup(contractID)) {
(0, import_sbp5.default)("state/vuex/commit", REMOVE_NOTIFICATION, notification);
}
} else {
const myProfile = getters.groupProfile(username);
if (isActionYoungerThanUser(meta, myProfile)) {
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\":\"21XWnNGSYVApXW4hmgiXYWPdUKtuxZJNm5pwRfHe8yv7U4Ha7N\",\"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\":\"21XWnNMcAa3DGQh7Tnx4dVwvPLkHyJch2x284W4JwtDGGTCmNC\"}}","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\":\"21XWnNKa17QyRuGnsrSZnW5vjoi85LqzrRqvazGKAyRxMQ2hTv\",\"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\":\"21XWnNHPyeoQg8wvcp6RY48kSzvVmK71bZuBpjtsaL1tJ13maA\"}}","signature":{"key":"<which of the 'authors' keys was used to sign 'body'>","signature":"<signature>"}}
7 changes: 7 additions & 0 deletions contracts/0.2.0/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -16798,6 +16798,9 @@ ${this.getErrorInfo()}`;
var findKeyIdByName = (state, name) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).find((k) => k.name === name && k._notAfterHeight === void 0)?.id;
var findForeignKeysByContractID = (state, contractID) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).filter((k) => k._notAfterHeight === void 0 && k.foreignKey?.includes(contractID)).map((k) => k.id);

// frontend/model/notifications/mutationKeys.js
var REMOVE_NOTIFICATION = "removeNotification";

// frontend/model/contracts/group.js
function vueFetchInitKV(obj, key, initialValue) {
let value = obj[key];
Expand Down Expand Up @@ -17480,6 +17483,7 @@ ${this.getErrorInfo()}`;
},
sideEffect({ data, meta, contractID }, { state, getters }) {
const rootState = (0, import_sbp6.default)("state/vuex/state");
const rootGetters = (0, import_sbp6.default)("state/vuex/getters");
const contracts = rootState.contracts || {};
const { username } = rootState.loggedIn;
if (data.member === username) {
Expand All @@ -17504,6 +17508,9 @@ ${this.getErrorInfo()}`;
}).then(() => (0, import_sbp6.default)("gi.contracts/group/revokeGroupKeyAndRotateOurPEK", contractID)).catch((e) => {
console.error(`sideEffect(removeMember): ${e.name} thrown during revokeGroupKeyAndRotateOurPEK to ${contractID}:`, e);
});
for (const notification of rootGetters.notificationsByGroup(contractID)) {
(0, import_sbp6.default)("state/vuex/commit", REMOVE_NOTIFICATION, notification);
}
} else {
const myProfile = getters.groupProfile(username);
if (isActionYoungerThanUser(meta, myProfile)) {
Expand Down
7 changes: 7 additions & 0 deletions frontend/model/contracts/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import currencies, { saferFloat } from './shared/currencies.js'
import { inviteType, chatRoomAttributesType } from './shared/types.js'
import { arrayOf, objectOf, objectMaybeOf, optional, string, number, boolean, object, unionOf, tupleOf } from '~/frontend/model/contracts/misc/flowTyper.js'
import { findKeyIdByName, findForeignKeysByContractID } from '~/shared/domains/chelonia/utils.js'
import { REMOVE_NOTIFICATION } from '~/frontend/model/notifications/mutationKeys.js'

function vueFetchInitKV (obj: Object, key: string, initialValue: any): any {
let value = obj[key]
Expand Down Expand Up @@ -904,6 +905,7 @@ sbp('chelonia/defineContract', {
},
sideEffect ({ data, meta, contractID }, { state, getters }) {
const rootState = sbp('state/vuex/state')
const rootGetters = sbp('state/vuex/getters')
const contracts = rootState.contracts || {}
const { username } = rootState.loggedIn

Expand Down Expand Up @@ -946,6 +948,11 @@ sbp('chelonia/defineContract', {
console.error(`sideEffect(removeMember): ${e.name} thrown during revokeGroupKeyAndRotateOurPEK to ${contractID}:`, e)
})
// TODO - #828 remove other group members contracts if applicable

// NOTE: remove all notifications whose scope is in this group
for (const notification of rootGetters.notificationsByGroup(contractID)) {
sbp('state/vuex/commit', REMOVE_NOTIFICATION, notification)
}
} else {
const myProfile = getters.groupProfile(username)

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": "21XWnNSsVaBM6WsvYJBipiE4ckoSom4yBhPePrGS4m2UhhstBi",
"gi.contracts/group": "21XWnNUjCV9K5EhwSAgbSuperYRP8ozuqZqDzUfS66w2TKUZ8V",
"gi.contracts/group": "21XWnNH1aXSgHHMLXotE6jMGLBP6N3C4hkp4zt2Guj5G48wqAo",
"gi.contracts/identity": "21XWnNSxNrVFTMBCUVcZV3CG833gTbJ9V8ZyX7Fxgmpj9rNy4r"
}
}

0 comments on commit 0b88e1d

Please sign in to comment.