-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Improve to manage notifications and proposals #2046
Changes from 5 commits
dfe9844
0f5d9c9
13f132d
8972c6a
3e83930
8b7de9c
9b77f81
8b8b101
fea1963
be2ceb8
67405c1
8e7d0d4
2e710b3
4c138d3
3be4f34
07f200c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -848,13 +848,16 @@ sbp('chelonia/defineContract', { | |
const payment = state.payments[data.paymentHash] | ||
|
||
if (loggedIn.identityContractID === payment.data.toMemberID) { | ||
sbp('gi.contracts/group/emitNotificationAfterSyncing', [contractID, innerSigningContractID], 'PAYMENT_RECEIVED', { | ||
createdDate: meta.createdDate, | ||
groupID: contractID, | ||
creatorID: innerSigningContractID, | ||
paymentHash: data.paymentHash, | ||
amount: getters.withGroupCurrency(payment.data.amount) | ||
}) | ||
sbp('gi.contracts/group/emitNotificationsAfterSyncing', [contractID, innerSigningContractID], [{ | ||
notificationName: 'PAYMENT_RECEIVED', | ||
notificationData: { | ||
createdDate: meta.createdDate, | ||
groupID: contractID, | ||
creatorID: innerSigningContractID, | ||
paymentHash: data.paymentHash, | ||
amount: getters.withGroupCurrency(payment.data.amount) | ||
} | ||
}]) | ||
} | ||
} | ||
} | ||
|
@@ -872,12 +875,15 @@ sbp('chelonia/defineContract', { | |
const { loggedIn } = sbp('state/vuex/state') | ||
|
||
if (data.toMemberID === loggedIn.identityContractID) { | ||
sbp('gi.contracts/group/emitNotificationAfterSyncing', [contractID, innerSigningContractID], 'PAYMENT_THANKYOU_SENT', { | ||
createdDate: meta.createdDate, | ||
groupID: contractID, | ||
fromMemberID: innerSigningContractID, | ||
toMemberID: data.toMemberID | ||
}) | ||
sbp('gi.contracts/group/emitNotificationsAfterSyncing', [contractID, innerSigningContractID], [{ | ||
notificationName: 'PAYMENT_THANKYOU_SENT', | ||
notificationData: { | ||
createdDate: meta.createdDate, | ||
groupID: contractID, | ||
fromMemberID: innerSigningContractID, | ||
toMemberID: data.toMemberID | ||
} | ||
}]) | ||
} | ||
} | ||
}, | ||
|
@@ -937,12 +943,15 @@ sbp('chelonia/defineContract', { | |
const myProfile = getters.groupProfile(loggedIn.identityContractID) | ||
|
||
if (isActionOlderThanUser(contractID, height, myProfile)) { | ||
sbp('gi.contracts/group/emitNotificationAfterSyncing', [contractID, innerSigningContractID], 'NEW_PROPOSAL', { | ||
createdDate: meta.createdDate, | ||
groupID: contractID, | ||
creatorID: innerSigningContractID, | ||
subtype: typeToSubTypeMap[data.proposalType] | ||
}) | ||
sbp('gi.contracts/group/emitNotificationsAfterSyncing', [contractID, innerSigningContractID], [{ | ||
notificationName: 'NEW_PROPOSAL', | ||
notificationData: { | ||
createdDate: meta.createdDate, | ||
groupID: contractID, | ||
creatorID: innerSigningContractID, | ||
subtype: typeToSubTypeMap[data.proposalType] | ||
} | ||
}]) | ||
} | ||
} | ||
}, | ||
|
@@ -1024,11 +1033,25 @@ sbp('chelonia/defineContract', { | |
} | ||
}, | ||
'gi.contracts/group/notifyExpiringProposals': { | ||
validate: actionRequireActiveMember(arrayOf(string)), | ||
validate: actionRequireActiveMember(objectOf({ | ||
proposalIds: arrayOf(string) | ||
})), | ||
process ({ data, meta, contractID }, { state }) { | ||
for (const proposalId of data) { | ||
for (const proposalId of data.proposalIds) { | ||
Vue.set(state.proposals[proposalId], 'notifiedBeforeExpire', true) | ||
} | ||
}, | ||
sideEffect ({ data, contractID }, { state }) { | ||
const notifications = [] | ||
for (const proposalId of data.proposalIds) { | ||
const proposal = state.proposals[proposalId] | ||
notifications.push({ | ||
notificationName: 'PROPOSAL_EXPIRING', | ||
notificationData: { groupID: contractID, proposal, proposalId } | ||
}) | ||
} | ||
|
||
sbp('gi.contracts/group/emitNotificationsAfterSyncing', contractID, notifications) | ||
} | ||
}, | ||
'gi.contracts/group/removeMember': { | ||
|
@@ -1197,11 +1220,14 @@ sbp('chelonia/defineContract', { | |
const myProfile = profiles[userID] | ||
|
||
if (isActionOlderThanUser(contractID, height, myProfile)) { | ||
sbp('gi.notifications/emit', 'MEMBER_ADDED', { // emit a notification for a member addition. | ||
createdDate: meta.createdDate, | ||
groupID: contractID, | ||
memberID: innerSigningContractID | ||
}) | ||
sbp('gi.contracts/group/emitNotificationsAfterSyncing', [], [{ | ||
notificationName: 'MEMBER_ADDED', | ||
notificationData: { | ||
createdDate: meta.createdDate, | ||
groupID: contractID, | ||
memberID: innerSigningContractID | ||
} | ||
}]) | ||
} | ||
}).catch((e) => { | ||
console.error(`Error subscribing to identity contract ${innerSigningContractID} of group member for group ${contractID}`, e) | ||
|
@@ -1687,9 +1713,10 @@ sbp('chelonia/defineContract', { | |
const { loggedIn } = sbp('state/vuex/state') | ||
const { createdDate } = meta | ||
if (isActionOlderThanUser(contractID, height, state.profiles[loggedIn.identityContractID])) { | ||
sbp('gi.contracts/group/emitNotificationAfterSyncing', contractID, 'PROPOSAL_CLOSED', { | ||
createdDate, groupID: contractID, proposal | ||
}) | ||
sbp('gi.contracts/group/emitNotificationsAfterSyncing', contractID, [{ | ||
notificationName: 'PROPOSAL_CLOSED', | ||
notificationData: { createdDate, groupID: contractID, proposal } | ||
}]) | ||
} | ||
}, | ||
'gi.contracts/group/sendMincomeChangedNotification': async function (contractID, meta, data, height, innerSigningContractID) { | ||
|
@@ -1732,13 +1759,16 @@ sbp('chelonia/defineContract', { | |
}) | ||
} | ||
|
||
sbp('gi.contracts/group/emitNotificationAfterSyncing', [contractID, innerSigningContractID], 'MINCOME_CHANGED', { | ||
groupID: contractID, | ||
creatorID: innerSigningContractID, | ||
to: toAmount, | ||
memberType, | ||
increased: mincomeIncreased | ||
}) | ||
sbp('gi.contracts/group/emitNotificationsAfterSyncing', [contractID, innerSigningContractID], [{ | ||
notificationName: 'MINCOME_CHANGED', | ||
notificationData: { | ||
groupID: contractID, | ||
creatorID: innerSigningContractID, | ||
to: toAmount, | ||
memberType, | ||
increased: mincomeIncreased | ||
} | ||
}]) | ||
} | ||
}, | ||
'gi.contracts/group/joinGroupChatrooms': async function (contractID, chatRoomID, memberID) { | ||
|
@@ -1884,12 +1914,10 @@ sbp('chelonia/defineContract', { | |
if (!proposalHash) { | ||
// NOTE: Do not make notification when the member is removed by proposal | ||
const memberRemovedThemselves = memberID === innerSigningContractID | ||
const notificationName = memberRemovedThemselves ? 'MEMBER_LEFT' : 'MEMBER_REMOVED' | ||
sbp('gi.contracts/group/emitNotificationAfterSyncing', memberID, notificationName, { | ||
createdDate: meta.createdDate, | ||
groupID: contractID, | ||
memberID | ||
}) | ||
sbp('gi.contracts/group/emitNotificationsAfterSyncing', memberID, [{ | ||
notificationName: memberRemovedThemselves ? 'MEMBER_LEFT' : 'MEMBER_REMOVED', | ||
notificationData: { createdDate: meta.createdDate, groupID: contractID, memberID } | ||
}]) | ||
} | ||
|
||
Promise.resolve() | ||
|
@@ -1948,13 +1976,15 @@ sbp('chelonia/defineContract', { | |
console.warn(`removeForeignKeys: ${e.name} error thrown:`, e) | ||
}) | ||
}, | ||
'gi.contracts/group/emitNotificationAfterSyncing': async (contractIDs, notificationName, notificationData) => { | ||
'gi.contracts/group/emitNotificationsAfterSyncing': async (contractIDs, notifications) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated function to be able to emit multiple notifications. |
||
const listOfIds = typeof contractIDs === 'string' ? [contractIDs] : contractIDs | ||
for (const id of listOfIds) { | ||
await sbp('chelonia/contract/wait', id) | ||
} | ||
|
||
sbp('gi.notifications/emit', notificationName, notificationData) | ||
notifications.forEach(({ notificationName, notificationData }) => { | ||
sbp('gi.notifications/emit', notificationName, notificationData) | ||
}) | ||
} | ||
} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,6 @@ export const CHATROOM_MEMBER_MENTION_SPECIAL_CHAR = '@' | |
export const CHATROOM_CHANNEL_MENTION_SPECIAL_CHAR = '#' | ||
|
||
// chatroom events | ||
export const CHATROOM_MESSAGE_ACTION = 'chatroom-message-action' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't use this action anymore unless we use the contracts of old versions. I remember this action was removed in the PR #1521 where @corrideat implemented E2E Protocol. |
||
export const MESSAGE_RECEIVE = 'message-receive' | ||
export const MESSAGE_SEND = 'message-send' | ||
|
||
|
@@ -98,15 +97,6 @@ export const MESSAGE_VARIANTS = { | |
FAILED: 'failed' | ||
} | ||
|
||
export const PROPOSAL_VARIANTS = { | ||
CREATED: 'created', | ||
EXPIRING: 'expiring', | ||
ACCEPTED: 'accepted', | ||
REJECTED: 'rejected', | ||
CANCELLED: 'cancelled', | ||
EXPIRED: 'expired' | ||
} | ||
|
||
export const MESSAGE_NOTIFY_SETTINGS = { | ||
ALL_MESSAGES: 'all-messages', | ||
DIRECT_MESSAGES: 'direct-messages', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,30 +210,36 @@ export function makeMentionFromUserID (userID: string): { | |
} | ||
} | ||
|
||
export function makeChannelMention (string: string): string { | ||
return `${CHATROOM_CHANNEL_MENTION_SPECIAL_CHAR}${string}` | ||
export function makeChannelMention (channelName: string): string { | ||
return `${CHATROOM_CHANNEL_MENTION_SPECIAL_CHAR}${channelName}` | ||
} | ||
|
||
export function swapMentionIDForDisplayname (text: string): string { | ||
export function swapMentionIDForDisplayname ( | ||
text: string, | ||
options: Object = { escaped: true, forChat: true } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add some inline comments to the code to explain what these parameters are along with some examples of which situations you would want to use one versus the other. |
||
): string { | ||
const { | ||
chatRoomsInDetail, | ||
ourContactProfilesById, | ||
getChatroomNameById, | ||
usernameFromID | ||
usernameFromID, | ||
userDisplayNameFromID | ||
} = sbp('state/vuex/getters') | ||
const possibleMentions = [ | ||
...Object.keys(ourContactProfilesById).map(u => makeMentionFromUserID(u).me).filter(v => !!v), | ||
...Object.values(chatRoomsInDetail).map((details: any) => makeChannelMention(details.id)) | ||
] | ||
|
||
return text | ||
.split(new RegExp(`(?<=\\s|^)(${possibleMentions.join('|')})(?=[^\\w\\d]|$)`)) | ||
.map(t => { | ||
return possibleMentions.includes(t) | ||
? t[0] === CHATROOM_MEMBER_MENTION_SPECIAL_CHAR | ||
? t[0] + usernameFromID(t.slice(1)) | ||
: t[0] + getChatroomNameById(t.slice(1)) | ||
: t | ||
}) | ||
.join('') | ||
const { escaped, forChat } = options | ||
const regEx = escaped | ||
? new RegExp(`(?<=\\s|^)(${possibleMentions.join('|')})(?=[^\\w\\d]|$)`) | ||
: new RegExp(`(${possibleMentions.join('|')})`) | ||
|
||
return text.split(regEx).map(t => { | ||
return possibleMentions.includes(t) | ||
? t[0] === CHATROOM_MEMBER_MENTION_SPECIAL_CHAR | ||
? forChat ? t[0] + usernameFromID(t.slice(1)) : userDisplayNameFromID(t.slice(1)) | ||
: (forChat ? t[0] : '') + getChatroomNameById(t.slice(1)) | ||
: t | ||
}).join('') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is written in a far more confusing manner now. Can you please add some parenthesis around the nested |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,8 @@ sbp('sbp/selectors/register', { | |
|
||
// Creates the notification object in a single step. | ||
const notification = { | ||
avatarUserID: template.avatarUserID || sbp('state/vuex/getters').ourIdentityContractId, | ||
...template, | ||
avatarUserID: template.avatarUserID || sbp('state/vuex/getters').ourIdentityContractId, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated order so that |
||
// Sets 'groupID' if this notification only pertains to a certain group. | ||
...(template.scope === 'group' ? { groupID: data.groupID } : {}), | ||
read: false, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make
data
meaningful, I've updated the type fromarray
toobject
.