Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Sep 5, 2024
1 parent 9d0de13 commit 26fc6b0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion frontend/controller/actions/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ export default (sbp('sbp/selectors/register', {
...encryptedAction('gi.actions/group/updateSettings', L('Failed to update group settings.')),
...encryptedAction('gi.actions/group/updateAllVotingRules', (params, e) => L('Failed to update voting rules. {codeError}', { codeError: e.message })),
...encryptedAction('gi.actions/group/updateDistributionDate', L('Failed to update group distribution date.')),
...encryptedAction('gi.actions/group/upgradeFrom1.0.6', L('Failed to upgrade from version 1.0.6')),
...encryptedAction('gi.actions/group/upgradeFrom1.0.7', L('Failed to upgrade from version 1.0.6')),
...((process.env.NODE_ENV === 'development' || process.env.CI) && {
...encryptedAction('gi.actions/group/forceDistributionDate', L('Failed to force distribution date.'))
})
Expand Down
4 changes: 2 additions & 2 deletions frontend/controller/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import Vue from 'vue'
sbp('sbp/selectors/register', {
'namespace/lookupCached': (name: string) => {
const cache = sbp('state/vuex/state').namespaceLookups
return cache?.[name] ?? null
return cache[name] ?? null
},
'namespace/lookupReverseCached': (id: string) => {
const cache = sbp('state/vuex/state').reverseNamespaceLookups
return cache?.[id] ?? null
return cache[id] ?? null
},
'namespace/lookup': (name: string, { skipCache }: { skipCache: boolean } = { skipCache: false }) => {
if (!skipCache) {
Expand Down
19 changes: 6 additions & 13 deletions frontend/model/contracts/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,10 @@ function updateGroupStreaks ({ state, getters }) {
}
}

const removeGroupChatroomProfile = (state, chatRoomID, member, ourselvesLeaving) => {
state.chatRooms[chatRoomID].members =
Object.fromEntries(
Object.entries(state.chatRooms[chatRoomID].members)
.map(([memberKey, profile]) => {
if (memberKey === member && (profile: any)?.status === PROFILE_STATUS.ACTIVE) {
return [memberKey, { ...profile, status: ourselvesLeaving ? PROFILE_STATUS.LEFT_GROUP : PROFILE_STATUS.REMOVED }]
}
return [memberKey, profile]
})
)
const removeGroupChatroomProfile = (state, chatRoomID, memberID, ourselvesLeaving) => {
if (!state.chatRooms[chatRoomID].members[memberID]) return

state.chatRooms[chatRoomID].members[memberID].status = PROFILE_STATUS.REMOVED
}

const leaveChatRoomAction = async (groupID, state, chatRoomID, memberID, actorID, leavingGroup) => {
Expand Down Expand Up @@ -1358,7 +1351,7 @@ sbp('chelonia/defineContract', {
}
}
},
'gi.contracts/group/upgradeFrom1.0.6': {
'gi.contracts/group/upgradeFrom1.0.7': {
validate: actionRequireActiveMember(optional),
process ({ height }, { state }) {
let changed = false
Expand All @@ -1371,7 +1364,7 @@ sbp('chelonia/defineContract', {
})
})
if (!changed) {
throw new Error('[gi.contracts/group/upgradeFrom1.0.6/process] Invalid or duplicate upgrade action')
throw new Error('[gi.contracts/group/upgradeFrom1.0.7/process] Invalid or duplicate upgrade action')
}
}
},
Expand Down
3 changes: 1 addition & 2 deletions frontend/model/contracts/shared/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export const INVITE_INITIAL_CREATOR = 'invite-initial-creator'
export const PROFILE_STATUS = {
ACTIVE: 'active', // confirmed group join
PENDING: 'pending', // shortly after being approved to join the group
REMOVED: 'removed',
LEFT_GROUP: 'left-group'
REMOVED: 'removed'
}
export const GROUP_NAME_MAX_CHAR = 50 // https://github.com/okTurtles/group-income/issues/2196
export const GROUP_DESCRIPTION_MAX_CHAR = 500
Expand Down
13 changes: 12 additions & 1 deletion frontend/model/contracts/shared/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,19 @@ export const referenceTally = (selector: string): Object => {
sbp('okTurtles.data/delete', key)
if (count && count !== Math.sign(count)) {
console.warn(`[${selector}] Unexpected value`, parentContractID, childContractID, count)
// If we're running tests, we enforce checking that the temporary
// count _must_ be either of 0, 1 or -1. This is a correct
// assumption, based on the fact that a single contract should only
// call retain or release at most once after all operations are
// processed, per chunk of operations (e.g., there is no valid
// reason for a group contract to call `retain` twice on the same
// contract ID, without having called `release` first).
// This rule (or assumption) also applies to non-CI environments,
// but we are more lax in this case to allow for more leniency when
// running contracts with real users. However, this type of error
// indicates faulty reference bookkeeping that must be corrected.
if (process.env.CI) {
Promise.reject(new Error(`Unexpected value ${parentContractID} ${childContractID}: ${count}`))
Promise.reject(new Error(`[${selector}] Unexpected value ${parentContractID} ${childContractID}: ${count}`))
}
}
switch (Math.sign(count)) {
Expand Down
10 changes: 7 additions & 3 deletions frontend/model/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ sbp('sbp/selectors/register', {
if (!state.preferences) {
state.preferences = {}
}
if (!state.reverseNamespaceLookups) {
// $FlowFixMe[incompatible-call]
Vue.set(state, 'reverseNamespaceLookups', Object.fromEntries(Object.entries(state.namespaceLookups).map(([k, v]: [string, string]) => [v, k])))
}
(() => {
// Upgrade from version 1.0.6 to a newer version
// Upgrade from version 1.0.7 to a newer version
// The new group chatroomo contract introduces a breaking change: the
// `state[groupID].chatRooms[chatRoomID].members[memberID].joinedHeight`
// attribute.
Expand All @@ -104,8 +108,8 @@ sbp('sbp/selectors/register', {
}, false)
})
if (!upgradeRequired) return
sbp('gi.actions/group/upgradeFrom1.0.6').catch(e => {
console.error('[state/vuex/postUpgradeVerification] Error during gi.actions/group/upgradeFrom1.0.6', e)
sbp('gi.actions/group/upgradeFrom1.0.7').catch(e => {
console.error('[state/vuex/postUpgradeVerification] Error during gi.actions/group/upgradeFrom1.0.7', e)
})
})()
},
Expand Down

0 comments on commit 26fc6b0

Please sign in to comment.