-
Notifications
You must be signed in to change notification settings - Fork 292
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
ES6: Migrated "announce" #899
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
93e54d4
First migrations
bennycode f30ccea
Deleted AnnounceService
bennycode 7785415
IIFE
bennycode af5c52d
"check_announcements"
bennycode 01915fd
process_announce_list
bennycode 79ce6a0
dunno
bennycode f6e6b57
Bye coffee
bennycode 9165930
linting
bennycode 5929b5a
Linting
bennycode f7659bd
chore
bennycode 1d15171
chore
bennycode 6f95df4
Removed "this"
bennycode 9f3bf76
Merge branch 'dev' into announce
bennycode 30f1bd3
Added test case for "announce_service.get_version"
bennycode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
This file was deleted.
Oops, something went wrong.
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,133 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2016 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
(function() { | ||
window.z = window.z || {}; | ||
window.z.announce = z.announce || {}; | ||
|
||
const ANNOUNCE_CONFIG = { | ||
CHECK_INTERVAL: 3 * 60 * 60 * 1000, | ||
CHECK_TIMEOUT: 5 * 60 * 1000, | ||
UPDATE_INTERVAL: 6 * 60 * 60 * 1000, | ||
}; | ||
|
||
window.z.announce.AnnounceRepository = class AnnounceRepository { | ||
constructor(announce_service) { | ||
this.logger = new z.util.Logger('z.announce.AnnounceRepository', z.config.LOGGER.OPTIONS); | ||
this.announce_service = announce_service; | ||
} | ||
|
||
init() { | ||
return window.setTimeout(() => { | ||
this.check_announcements(); | ||
this.schedule_checks(); | ||
}, ANNOUNCE_CONFIG.CHECK_TIMEOUT); | ||
} | ||
|
||
check_announcements() { | ||
return this.announce_service.get_announcements().then(this.process_announce_list).catch((error) => { | ||
this.logger.error(`Failed to fetch announcements: ${error}`); | ||
}); | ||
} | ||
|
||
check_version() { | ||
return this.announce_service.get_version().then((server_version) => { | ||
this.logger.info(`Found new version ${server_version}`); | ||
|
||
if (server_version > z.util.Environment.version(false, true)) { | ||
amplify.publish(z.event.WebApp.LIFECYCLE.UPDATE, z.announce.UPDATE_SOURCE.WEBAPP); | ||
} | ||
}).catch((error) => { | ||
this.logger.error(`Failed to fetch version: ${error}`); | ||
}); | ||
} | ||
|
||
schedule_checks() { | ||
window.setInterval(() => { | ||
this.check_announcements(); | ||
}, ANNOUNCE_CONFIG.CHECK_INTERVAL); | ||
|
||
window.setInterval(() => { | ||
this.check_version(); | ||
}, ANNOUNCE_CONFIG.CHECK_INTERVAL); | ||
} | ||
|
||
process_announce_list(announcements_list) { | ||
if (announcements_list) { | ||
for (let announcement in announcements_list) { | ||
if (!z.util.Environment.frontend.is_localhost()) { | ||
if (announcement.version_max && z.util.Environment.version(false) > announcement.version_max) { | ||
continue; | ||
} | ||
|
||
if (announcement.version_min && z.util.Environment.version(false) < announcement.version_min) { | ||
continue; | ||
} | ||
} | ||
|
||
const key = `${z.storage.StorageKey.ANNOUNCE.ANNOUNCE_KEY}@${announcement.key}`; | ||
if (!z.util.StorageUtil.get_value(key)) { | ||
z.util.StorageUtil.set_value(key, 'read'); | ||
if (!z.util.Environment.browser.supports.notifications) { | ||
return; | ||
} | ||
|
||
if (window.Notification.permission === z.system_notification.PermissionStatusState.DENIED) { | ||
return; | ||
} | ||
|
||
if (z.localization.Localizer.locale !== 'en') { | ||
announcement.title = announcement[`title_${z.localization.Localizer.locale}`] || announcement.title; | ||
announcement.message = announcement[`message_${z.localization.Localizer.locale}`] || announcement.message; | ||
} | ||
|
||
const notification = new window.Notification(announcement.title, { | ||
body: announcement.message, | ||
icon: z.util.Environment.electron && z.util.Environment.os.mac ? '' : '/image/logo/notification.png', | ||
sticky: true, | ||
requireInteraction: true, | ||
}); | ||
|
||
amplify.publish(z.event.WebApp.ANALYTICS.EVENT, z.tracking.EventName.ANNOUNCE.SENT, {campaign: announcement.campaign}); | ||
this.logger.info(`Announcement '${announcement.title}' shown`); | ||
|
||
notification.onclick = () => { | ||
amplify.publish(z.event.WebApp.ANALYTICS.EVENT, z.tracking.EventName.ANNOUNCE.CLICKED, {campaign: announcement.campaign}); | ||
this.logger.info(`Announcement '${announcement.title}' clicked`); | ||
|
||
if (announcement.link) { | ||
z.util.safe_window_open(announcement.link); | ||
} | ||
|
||
if (announcement.refresh) { | ||
amplify.publish(z.event.WebApp.LIFECYCLE.REFRESH); | ||
} | ||
|
||
notification.close(); | ||
}; | ||
|
||
break; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
})(); |
This file was deleted.
Oops, something went wrong.
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,57 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2016 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
(function() { | ||
window.z = window.z || {}; | ||
window.z.announce = z.announce || {}; | ||
|
||
const ANNOUNCE_SERVICE_URL = 'api/v1/announce/'; | ||
|
||
window.z.announce.AnnounceService = class AnnounceService { | ||
constructor() { | ||
this.logger = new z.util.Logger('z.announce.AnnounceService', z.config.LOGGER.OPTIONS); | ||
this.url = `${z.util.Environment.backend.website_url()}${ANNOUNCE_SERVICE_URL}?order=created&active=true`; | ||
if (z.util.Environment.frontend.is_production()) { | ||
this.url += '&production=true'; | ||
} | ||
} | ||
|
||
get_announcements() { | ||
return new Promise((resolve, reject) => { | ||
$.get(this.url).done((data) => { | ||
resolve(data['result']); | ||
}).fail((jqXHR, textStatus, errorThrown) => { | ||
reject(new Error(errorThrown)); | ||
}); | ||
}); | ||
} | ||
|
||
get_version() { | ||
return new Promise((resolve, reject) => { | ||
$.get('version/').done((data) => { | ||
resolve(data['version']); | ||
}).fail((jqXHR, textStatus, errorThrown) => { | ||
reject(new Error(errorThrown)); | ||
}); | ||
}); | ||
} | ||
}; | ||
})(); |
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2016 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
window.z = window.z || {}; | ||
window.z.announce = z.announce || {}; | ||
|
||
window.z.announce.UPDATE_SOURCE = { | ||
DESKTOP: 'desktop', | ||
WEBAPP: 'webapp', | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
do we want to use fetch for this???
return fetch(this.url).then((response) => response.json()).then((json) => json.result)
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.
One thing at a time :D
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.
means touching it twice
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.
Tests fail if I use
return fetch(this.url).then((data) => data.result)
.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.
If there "easy" fixes we should do them in one go.. but of course if the tests fail and stuff then maybe have somewhere a list that we can track of the things that we spotted..
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.
It's a good time to have a complete review of the codebase!
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.
Ok, I will see what I can do here...
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.
window.fetch
returns aReadableStream
indata.body
. So the code needs some adjustments.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.
Looks like it needs a reader:
var reader = response.body.getReader();
(https://jakearchibald.com/2015/thats-so-fetch/)Maybe we should use a wrapper which wraps the fetch API. Like: https://github.com/typicode/fetchival
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.
This seems to do the trick: