Skip to content

Commit

Permalink
Updated new file share notification card
Browse files Browse the repository at this point in the history
  • Loading branch information
DaKingKong committed Apr 2, 2022
1 parent 1d35581 commit 2d3be46
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ringcentral-google-drive-notification-add-in",
"version": "0.0.7",
"version": "0.0.8",
"description": "RingCentral Add-In App",
"keywords": [
"RingCentral",
Expand Down
43 changes: 36 additions & 7 deletions src/server/adaptiveCardPayloads/newFileShareWithMeCard.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "TextBlock",
"size": "Large",
"weight": "Bolder",
"text": "New File Share"
"text": "**${username}** shared a ${fileType}"
},
{
"type": "ColumnSet",
Expand All @@ -30,7 +30,6 @@
"items": [
{
"type": "TextBlock",
"weight": "Bolder",
"text": "${username}",
"wrap": true
},
Expand All @@ -46,11 +45,6 @@
}
]
},
{
"type": "TextBlock",
"text": "**${username}** shared document:",
"wrap": true
},
{
"type": "ColumnSet",
"separator": true,
Expand Down Expand Up @@ -81,6 +75,41 @@
]
},
{
"separator": true,
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "Owner: ${ownerDisplayName}${ownerEmail}",
"wrap": true
}
],
"width": "stretch"
}
]
},
{
"separator": true,
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "Last edit: ${modifiedTime}",
"wrap": true
}
],
"width": "stretch"
}
]
},
{
"separator": true,
"type": "ActionSet",
"actions": [
{
Expand Down
31 changes: 26 additions & 5 deletions src/server/handlers/notificationHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function onReceiveNotification(googleUser) {
console.log(`Latest changes: ${JSON.stringify(latestChanges, null, 2)}`)
for (const change of latestChanges) {
const fileId = change.fileId;
const fileResponse = await drive.files.get({ fileId, fields: 'id,name,webViewLink,iconLink,owners,viewedByMe,sharedWithMeTime,ownedByMe', supportsAllDrives: true })
const fileResponse = await drive.files.get({ fileId, fields: 'id,name,webViewLink,iconLink,owners,viewedByMe,sharedWithMeTime,modifiedTime,ownedByMe,mimeType', supportsAllDrives: true })
const fileData = fileResponse.data;
const googleFile = await GoogleFile.findByPk(fileId);

Expand All @@ -68,7 +68,7 @@ async function onReceiveNotification(googleUser) {
name: fileData.name
});
}

// Case: New File Share With Me
if (!fileData.ownedByMe && googleUser.isReceiveNewFile && fileData.sharedWithMeTime && isEventNew(change.time, fileData.sharedWithMeTime)) {
console.log('===========NEW FILE============');
Expand All @@ -80,7 +80,11 @@ async function onReceiveNotification(googleUser) {
userEmail: owner.emailAddress ?? "",
fileIconUrl: fileData.iconLink,
fileName: fileData.name,
fileUrl: fileData.webViewLink
fileUrl: fileData.webViewLink,
fileType: getFileTypeFromMimeType(fileData.mimeType),
ownerEmail: fileData.owners[0].emailAddress,
ownerDisplayName: fileData.owners[0].displayName,
modifiedTime: fileData.modifiedTime
};
const card = cardBuilder.newFileShareCard(cardData);
// Send adaptive card to your channel in RingCentral App
Expand Down Expand Up @@ -141,7 +145,7 @@ async function onReceiveNotification(googleUser) {
await bot.sendAdaptiveCard(subscription.groupId, card);
}
// daily, weekly -> cache
else if (subscription.state === 'daily' || subscription.state === 'weekly'){
else if (subscription.state === 'daily' || subscription.state === 'weekly') {
const cachedInfo = subscription.cachedInfo;
cachedInfo.commentNotifications.push(cardData);
await subscription.update({
Expand All @@ -166,7 +170,7 @@ async function SendDigestNotification(subscriptions) {
groupIds.push(sub.groupId);
}
}

for (const groupId of groupIds) {
const subscriptionsInGroup = subscriptions.filter(s => s.groupId == groupId);
let cardData =
Expand Down Expand Up @@ -197,5 +201,22 @@ async function SendDigestNotification(subscriptions) {
}
}

function getFileTypeFromMimeType(mimeType) {
switch (mimeType) {
case 'application/vnd.google-apps.document':
return 'document';
case 'application/vnd.google-apps.folder':
return 'folder';
case 'application/vnd.google-apps.form':
return 'form';
case 'application/vnd.google-apps.presentation':
return 'slide';
case 'application/vnd.google-apps.spreadsheet':
return 'spreadsheet';
default:
return 'file';
}
}

exports.notification = notification;
exports.SendDigestNotification = SendDigestNotification;
8 changes: 6 additions & 2 deletions src/server/lib/cardBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function subscriptionListCard(botId, groupId) {
groupId
}
});

const activeSubscriptionList = [];;
const mutedSubscriptionList = [];;
for (const subscription of subscriptions) {
Expand Down Expand Up @@ -200,7 +200,11 @@ function newFileShareCard(rawCardData) {
userEmail: rawCardData.userEmail,
fileIconUrl: rawCardData.fileIconUrl,
fileName: rawCardData.fileName,
fileUrl: rawCardData.fileUrl
fileUrl: rawCardData.fileUrl,
fileType: rawCardData.fileType,
ownerEmail: rawCardData.ownerEmail ? `(${rawCardData.ownerEmail})` : '',
ownerDisplayName: rawCardData.ownerDisplayName,
modifiedTime: rawCardData.modifiedTime
};
const card = template.expand({
$root: cardData
Expand Down

0 comments on commit 2d3be46

Please sign in to comment.