This repository was archived by the owner on Oct 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2560 from withspectrum/2.1.3
2.1.3
- Loading branch information
Showing
54 changed files
with
1,405 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 8 additions & 42 deletions
50
athena/utils/push-notifications/send-web-push-notification.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,17 @@ | ||
// @flow | ||
const debug = require('debug')('athena:utils:web-push'); | ||
import webPush from 'web-push'; | ||
import sendWebPush from 'shared/send-web-push-notification'; | ||
import { removeSubscription } from '../../models/web-push-subscription'; | ||
|
||
try { | ||
webPush.setVapidDetails( | ||
'https://spectrum.chat', | ||
process.env.VAPID_PUBLIC_KEY, | ||
process.env.VAPID_PRIVATE_KEY | ||
); | ||
console.log('Web push notifications enabled!'); | ||
} catch (err) {} | ||
|
||
export const sendWebPushNotification = ( | ||
subscription: any, | ||
payload: Object | string, | ||
options?: ?Object | ||
): Promise<Object> => { | ||
if (!subscription || !payload) { | ||
debug( | ||
'No subscription or payload provided to sendWebPushNotification, not pushing anything.' | ||
); | ||
return Promise.resolve({}); | ||
} | ||
if (process.env.NODE_ENV === 'development') { | ||
debug('not sending web push notification in development'); | ||
return Promise.resolve({}); | ||
} else { | ||
debug('send web push notification'); | ||
} | ||
|
||
const pl = | ||
typeof payload === 'string' | ||
? payload | ||
: JSON.stringify({ | ||
...payload, | ||
raw: undefined, | ||
}); | ||
return webPush | ||
.sendNotification(subscription, pl, { | ||
TTL: 86400, // Default TTL: One day | ||
...options, | ||
}) | ||
.catch(err => { | ||
if (err.statusCode === 410 && err.endpoint) { | ||
debug(`old subscription found (${err.endpoint}), removing`, err); | ||
return removeSubscription(err.endpoint); | ||
} | ||
}); | ||
): Promise<?Object> => { | ||
return sendWebPush(subscription, payload, options).catch(err => { | ||
if (err.statusCode === 410 && err.endpoint) { | ||
debug(`old subscription found (${err.endpoint}), removing`, err); | ||
return removeSubscription(err.endpoint); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
iris/migrations/20180309144845-create-community-settings-table.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
exports.up = function(r, conn) { | ||
return r | ||
.tableCreate('communitySettings') | ||
.run(conn) | ||
.then(() => | ||
r | ||
.table('communitySettings') | ||
.indexCreate('communityId', r.row('communityId')) | ||
.run(conn) | ||
) | ||
.catch(err => { | ||
console.log(err); | ||
throw err; | ||
}); | ||
}; | ||
|
||
exports.down = function(r, conn) { | ||
return Promise.all([r.tableDrop('communitySettings').run(conn)]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// @flow | ||
const { db } = require('./db'); | ||
import type { DBCommunitySettings } from 'shared/types'; | ||
import { getCommunityById } from './community'; | ||
|
||
const defaultSettings = { | ||
brandedLogin: { | ||
isEnabled: false, | ||
message: null, | ||
}, | ||
}; | ||
|
||
export const getCommunitySettings = (id: string) => { | ||
return db | ||
.table('communitySettings') | ||
.getAll(id, { index: 'communityId' }) | ||
.run() | ||
.then(data => { | ||
if (!data || data.length === 0) { | ||
return defaultSettings; | ||
} | ||
return data[0]; | ||
}); | ||
}; | ||
|
||
export const getCommunitiesSettings = ( | ||
communityIds: Array<string> | ||
): Promise<?DBCommunitySettings> => { | ||
return db | ||
.table('communitySettings') | ||
.getAll(...communityIds, { index: 'communityId' }) | ||
.group('communityId') | ||
.run(); | ||
}; | ||
|
||
export const createCommunitySettings = (id: string) => { | ||
return db | ||
.table('communitySettings') | ||
.insert({ | ||
communityId: id, | ||
brandedLogin: { | ||
isEnabled: false, | ||
message: null, | ||
}, | ||
}) | ||
.run() | ||
.then(async () => await getCommunityById(id)); | ||
}; | ||
|
||
export const enableCommunityBrandedLogin = (id: string) => { | ||
return db | ||
.table('communitySettings') | ||
.getAll(id, { index: 'communityId' }) | ||
.update({ | ||
brandedLogin: { | ||
isEnabled: true, | ||
}, | ||
}) | ||
.run() | ||
.then(async () => await getCommunityById(id)); | ||
}; | ||
|
||
export const disableCommunityBrandedLogin = (id: string) => { | ||
return db | ||
.table('communitySettings') | ||
.getAll(id, { index: 'communityId' }) | ||
.update({ | ||
brandedLogin: { | ||
isEnabled: false, | ||
}, | ||
}) | ||
.run() | ||
.then(async () => await getCommunityById(id)); | ||
}; | ||
|
||
export const updateCommunityBrandedLoginMessage = ( | ||
id: string, | ||
message: ?string | ||
) => { | ||
return db | ||
.table('communitySettings') | ||
.getAll(id, { index: 'communityId' }) | ||
.update({ | ||
brandedLogin: { | ||
message: message, | ||
}, | ||
}) | ||
.run() | ||
.then(async () => await getCommunityById(id)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.