diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
commit | 58cda9cc7fb79ca9df6746de7f9662bc08dc156a (patch) | |
tree | 1211600c2a5d3b5f81c435c6896618111a611720 /src/models | |
download | ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.gz ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.zst ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.zip |
initial commit
Diffstat (limited to 'src/models')
-rw-r--r-- | src/models/News.js | 19 | ||||
-rw-r--r-- | src/models/Order.js | 17 | ||||
-rw-r--r-- | src/models/Plan.js | 16 | ||||
-rw-r--r-- | src/models/Recipe.js | 52 | ||||
-rw-r--r-- | src/models/RecipePreview.js | 16 | ||||
-rw-r--r-- | src/models/Service.js | 132 | ||||
-rw-r--r-- | src/models/User.js | 41 |
7 files changed, 293 insertions, 0 deletions
diff --git a/src/models/News.js b/src/models/News.js new file mode 100644 index 000000000..e8953ff8c --- /dev/null +++ b/src/models/News.js | |||
@@ -0,0 +1,19 @@ | |||
1 | // @flow | ||
2 | |||
3 | export default class News { | ||
4 | id: string = ''; | ||
5 | message: string = ''; | ||
6 | type: string = 'primary'; | ||
7 | sticky: bool = false; | ||
8 | |||
9 | constructor(data: Object) { | ||
10 | if (!data.id) { | ||
11 | throw Error('News requires Id'); | ||
12 | } | ||
13 | |||
14 | this.id = data.id; | ||
15 | this.message = data.message || this.message; | ||
16 | this.type = data.type || this.type; | ||
17 | this.sticky = data.sticky !== undefined ? data.sticky : this.sticky; | ||
18 | } | ||
19 | } | ||
diff --git a/src/models/Order.js b/src/models/Order.js new file mode 100644 index 000000000..0e10b01d6 --- /dev/null +++ b/src/models/Order.js | |||
@@ -0,0 +1,17 @@ | |||
1 | export default class Order { | ||
2 | id = ''; | ||
3 | subscriptionId = ''; | ||
4 | name = ''; | ||
5 | invoiceUrl = ''; | ||
6 | price = ''; | ||
7 | date = ''; | ||
8 | |||
9 | constructor(data) { | ||
10 | this.id = data.id; | ||
11 | this.subscriptionId = data.subscriptionId; | ||
12 | this.name = data.name || this.name; | ||
13 | this.invoiceUrl = data.invoiceUrl || this.invoiceUrl; | ||
14 | this.price = data.price || this.price; | ||
15 | this.date = data.date || this.date; | ||
16 | } | ||
17 | } | ||
diff --git a/src/models/Plan.js b/src/models/Plan.js new file mode 100644 index 000000000..1f2a44902 --- /dev/null +++ b/src/models/Plan.js | |||
@@ -0,0 +1,16 @@ | |||
1 | // @flow | ||
2 | |||
3 | export default class Plan { | ||
4 | month: { | ||
5 | id: '', | ||
6 | price: 0, | ||
7 | } | ||
8 | year: { | ||
9 | id: '', | ||
10 | price: 0, | ||
11 | } | ||
12 | |||
13 | constructor(data: Object) { | ||
14 | Object.assign(this, data); | ||
15 | } | ||
16 | } | ||
diff --git a/src/models/Recipe.js b/src/models/Recipe.js new file mode 100644 index 000000000..43a3450b1 --- /dev/null +++ b/src/models/Recipe.js | |||
@@ -0,0 +1,52 @@ | |||
1 | export default class Recipe { | ||
2 | id = ''; | ||
3 | name = ''; | ||
4 | author = ''; | ||
5 | description = ''; | ||
6 | version = '1.0'; | ||
7 | path = ''; | ||
8 | |||
9 | serviceURL = ''; | ||
10 | |||
11 | hasDirectMessages = true; | ||
12 | hasIndirectMessages = false; | ||
13 | hasNotificationSound = false; | ||
14 | hasTeamId = false; | ||
15 | hasPredefinedUrl = false; | ||
16 | hasCustomUrl = false; | ||
17 | urlInputPrefix = ''; | ||
18 | urlInputSuffix = ''; | ||
19 | |||
20 | message = ''; | ||
21 | |||
22 | constructor(data) { | ||
23 | if (!data) { | ||
24 | throw Error('Recipe config not valid'); | ||
25 | } | ||
26 | |||
27 | if (!data.id) { | ||
28 | throw Error('Recipe requires Id'); | ||
29 | } | ||
30 | |||
31 | this.id = data.id || this.id; | ||
32 | this.name = data.name || this.name; | ||
33 | this.author = data.author || this.author; | ||
34 | this.description = data.description || this.description; | ||
35 | this.version = data.version || this.version; | ||
36 | this.path = data.path; | ||
37 | |||
38 | this.serviceURL = data.config.serviceURL || this.serviceURL; | ||
39 | |||
40 | this.hasDirectMessages = data.config.hasDirectMessages || this.hasDirectMessages; | ||
41 | this.hasIndirectMessages = data.config.hasIndirectMessages || this.hasIndirectMessages; | ||
42 | this.hasNotificationSound = data.config.hasNotificationSound || this.hasNotificationSound; | ||
43 | this.hasTeamId = data.config.hasTeamId || this.hasTeamId; | ||
44 | this.hasPredefinedUrl = data.config.hasPredefinedUrl || this.hasPredefinedUrl; | ||
45 | this.hasCustomUrl = data.config.hasCustomUrl || this.hasCustomUrl; | ||
46 | |||
47 | this.urlInputPrefix = data.config.urlInputPrefix || this.urlInputPrefix; | ||
48 | this.urlInputSuffix = data.config.urlInputSuffix || this.urlInputSuffix; | ||
49 | |||
50 | this.message = data.config.message || this.message; | ||
51 | } | ||
52 | } | ||
diff --git a/src/models/RecipePreview.js b/src/models/RecipePreview.js new file mode 100644 index 000000000..7b497edf3 --- /dev/null +++ b/src/models/RecipePreview.js | |||
@@ -0,0 +1,16 @@ | |||
1 | // @flow | ||
2 | |||
3 | export default class RecipePreview { | ||
4 | id: string = ''; | ||
5 | name: string = ''; | ||
6 | icon: string = ''; // TODO: check if this isn't replaced by `icons` | ||
7 | featured: bool = false; | ||
8 | |||
9 | constructor(data: Object) { | ||
10 | if (!data.id) { | ||
11 | throw Error('RecipePreview requires Id'); | ||
12 | } | ||
13 | |||
14 | Object.assign(this, data); | ||
15 | } | ||
16 | } | ||
diff --git a/src/models/Service.js b/src/models/Service.js new file mode 100644 index 000000000..7a0310ebc --- /dev/null +++ b/src/models/Service.js | |||
@@ -0,0 +1,132 @@ | |||
1 | import { computed, observable } from 'mobx'; | ||
2 | import path from 'path'; | ||
3 | import normalizeUrl from 'normalize-url'; | ||
4 | |||
5 | export default class Service { | ||
6 | id = ''; | ||
7 | recipe = ''; | ||
8 | webview = null; | ||
9 | events: {}; | ||
10 | |||
11 | isAttached = false; | ||
12 | |||
13 | @observable isActive = false; // Is current webview active | ||
14 | |||
15 | @observable name = ''; | ||
16 | @observable unreadDirectMessageCount = 0; | ||
17 | @observable unreadIndirectMessageCount = 0; | ||
18 | |||
19 | @observable order = 99; | ||
20 | @observable isEnabled = true; | ||
21 | @observable team = ''; | ||
22 | @observable customUrl = ''; | ||
23 | @observable isNotificationEnabled = true; | ||
24 | @observable isIndirectMessageBadgeEnabled = true; | ||
25 | @observable customIconUrl = ''; | ||
26 | |||
27 | constructor(data, recipe) { | ||
28 | if (!data) { | ||
29 | console.error('Service config not valid'); | ||
30 | return null; | ||
31 | } | ||
32 | |||
33 | if (!recipe) { | ||
34 | console.error('Service recipe not valid'); | ||
35 | return null; | ||
36 | } | ||
37 | |||
38 | this.id = data.id || this.id; | ||
39 | this.name = data.name || this.name; | ||
40 | this.team = data.team || this.team; | ||
41 | this.customUrl = data.customUrl || this.customUrl; | ||
42 | this.customIconUrl = data.customIconUrl || this.customIconUrl; | ||
43 | |||
44 | this.order = data.order !== undefined | ||
45 | ? data.order : this.order; | ||
46 | |||
47 | this.isEnabled = data.isEnabled !== undefined | ||
48 | ? data.isEnabled : this.isEnabled; | ||
49 | |||
50 | this.isNotificationEnabled = data.isNotificationEnabled !== undefined | ||
51 | ? data.isNotificationEnabled : this.isNotificationEnabled; | ||
52 | |||
53 | this.isIndirectMessageBadgeEnabled = data.isIndirectMessageBadgeEnabled !== undefined | ||
54 | ? data.isIndirectMessageBadgeEnabled : this.isIndirectMessageBadgeEnabled; | ||
55 | |||
56 | this.recipe = recipe; | ||
57 | } | ||
58 | |||
59 | @computed get url() { | ||
60 | if (this.recipe.hasCustomUrl && this.customUrl) { | ||
61 | let url = normalizeUrl(this.customUrl); | ||
62 | |||
63 | if (typeof this.recipe.buildUrl === 'function') { | ||
64 | url = this.recipe.buildUrl(url); | ||
65 | } | ||
66 | |||
67 | return url; | ||
68 | } | ||
69 | |||
70 | if (this.recipe.hasTeamId && this.team) { | ||
71 | return this.recipe.serviceURL.replace('{teamId}', this.team); | ||
72 | } | ||
73 | |||
74 | return this.recipe.serviceURL; | ||
75 | } | ||
76 | |||
77 | @computed get icon() { | ||
78 | if (this.hasCustomIcon) { | ||
79 | return this.customIconUrl; | ||
80 | } | ||
81 | |||
82 | return path.join(this.recipe.path, 'icon.svg'); | ||
83 | } | ||
84 | |||
85 | @computed get hasCustomIcon() { | ||
86 | return (this.customIconUrl !== ''); | ||
87 | } | ||
88 | |||
89 | @computed get iconPNG() { | ||
90 | return path.join(this.recipe.path, 'icon.png'); | ||
91 | } | ||
92 | |||
93 | @computed get userAgent() { | ||
94 | let userAgent = window.navigator.userAgent; | ||
95 | if (typeof this.recipe.overrideUserAgent === 'function') { | ||
96 | userAgent = this.recipe.overrideUserAgent(); | ||
97 | } | ||
98 | |||
99 | return userAgent; | ||
100 | } | ||
101 | |||
102 | initializeWebViewEvents(store) { | ||
103 | this.webview.addEventListener('ipc-message', e => store.actions.service.handleIPCMessage({ | ||
104 | serviceId: this.id, | ||
105 | channel: e.channel, | ||
106 | args: e.args, | ||
107 | })); | ||
108 | |||
109 | this.webview.addEventListener('new-window', (event, url, frameName, options) => store.actions.service.openWindow({ | ||
110 | event, | ||
111 | url, | ||
112 | frameName, | ||
113 | options, | ||
114 | })); | ||
115 | } | ||
116 | |||
117 | initializeWebViewListener() { | ||
118 | if (this.webview && this.recipe.events) { | ||
119 | Object.keys(this.recipe.events).forEach((eventName) => { | ||
120 | const eventHandler = this.recipe[this.recipe.events[eventName]]; | ||
121 | if (typeof eventHandler === 'function') { | ||
122 | this.webview.addEventListener(eventName, eventHandler); | ||
123 | } | ||
124 | }); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | resetMessageCount() { | ||
129 | this.unreadDirectMessageCount = 0; | ||
130 | this.unreadIndirectMessageCount = 0; | ||
131 | } | ||
132 | } | ||
diff --git a/src/models/User.js b/src/models/User.js new file mode 100644 index 000000000..94b579928 --- /dev/null +++ b/src/models/User.js | |||
@@ -0,0 +1,41 @@ | |||
1 | import { observable } from 'mobx'; | ||
2 | |||
3 | export default class User { | ||
4 | id = null; | ||
5 | @observable email = null; | ||
6 | @observable firstname = null; | ||
7 | @observable lastname = null; | ||
8 | @observable organization = null; | ||
9 | @observable accountType = null; | ||
10 | @observable emailIsConfirmed = true; // better assume it's confirmed to avoid noise | ||
11 | @observable subscription = {}; | ||
12 | @observable isSubscriptionOwner = false; | ||
13 | @observable isPremium = false; | ||
14 | @observable beta = false; | ||
15 | @observable donor = {}; | ||
16 | @observable isDonor = false; | ||
17 | @observable isMiner = false; | ||
18 | |||
19 | constructor(data: Object) { | ||
20 | if (!data.id) { | ||
21 | throw Error('User requires Id'); | ||
22 | } | ||
23 | |||
24 | this.id = data.id; | ||
25 | this.email = data.email || this.email; | ||
26 | this.firstname = data.firstname || this.firstname; | ||
27 | this.lastname = data.lastname || this.lastname; | ||
28 | this.organization = data.organization || this.organization; | ||
29 | this.accountType = data.accountType || this.accountType; | ||
30 | this.isPremium = data.isPremium || this.isPremium; | ||
31 | this.beta = data.beta || this.beta; | ||
32 | this.donor = data.donor || this.donor; | ||
33 | this.isDonor = data.isDonor || this.isDonor; | ||
34 | this.isSubscriptionOwner = data.isSubscriptionOwner || this.isSubscriptionOwner; | ||
35 | this.isMiner = data.isMiner || this.isMiner; | ||
36 | } | ||
37 | |||
38 | // @computed get isPremium() { | ||
39 | // | ||
40 | // } | ||
41 | } | ||