-
Notifications
You must be signed in to change notification settings - Fork 7
/
Session.4dm
262 lines (146 loc) · 6.77 KB
/
Session.4dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
Construct a Session object.
If you have only one application in your Session files (`MobileApps/`),
you can call the constructor with no parameter.
However, if you have more than one, you will need to provide parameters
to identify which application you want to send push notifications to.
MobileAppServer .Session.new() -> session // only if one application
MobileAppServer .Session.new( "TEAM123456.com.sample.myappname" ) -> session
MobileAppServer .Session.new( "com.sample.myappname" ) -> session
MobileAppServer .Session.new( "myappname" ) -> session
*/
Class constructor($appID : Text) // Application ID (teamID.bundleID) or Bundle ID or Application name or empty entry
var $folder_indx : Integer
var $emptyParameter : Boolean
var $appFoldersList : Collection
var $skipAssert : Boolean
$skipAssert:=False:C215
var $Dir_mobileApps; $appFolder : 4D:C1709.Folder
$Dir_mobileApps:=Folder:C1567(fk mobileApps folder:K87:18; *)
If ($Dir_mobileApps.exists)
// Each folder corresponds to an application
$appFoldersList:=$Dir_mobileApps.folders()
Case of
: (Count parameters:C259=0)
$emptyParameter:=True:C214
: (Length:C16(String:C10($appID))=0)
$emptyParameter:=True:C214
Else
$emptyParameter:=False:C215
End case
If (Bool:C1537($emptyParameter)) // Empty entry
Case of
: ($appFoldersList.length=0)
ASSERT:C1129(False:C215; "There is no application folder found")
: ($appFoldersList.length=1)
$appFolder:=$appFoldersList[0]
This:C1470.sessionDir:=$appFolder
Else
ASSERT:C1129(False:C215; "There are several application folders, can't select appropriate application")
End case
Else // Application ID (teamID.bundleID) or Bundle ID or Application name
var $Col_app : Collection
$Col_app:=Split string:C1554($appID; ".")
Case of
: ($Col_app.count()=1) // app name
For each ($appFolder; $appFoldersList) Until (This:C1470.sessionDir#Null:C1517)
$Col_app:=Split string:C1554($appFolder.fullName; ".")
If ($Col_app[$Col_app.length-1]=$appID)
If ($appFolder.exists)
This:C1470.sessionDir:=$appFolder
// Else : application directory doesn't exist (not possible or just deleted)
End if
// Else : Application name not found
End if
End for each
: ($Col_app.count()=3) // bundleId
var $pos : Integer
For each ($appFolder; $appFoldersList) Until (This:C1470.sessionDir#Null:C1517)
$pos:=Position:C15($appID; $appFolder.fullName)
If ($pos>0)
If ($appFolder.exists)
This:C1470.sessionDir:=$appFolder
// Else : application directory doesn't exist
End if
// Else : BundleId found
End if
End for each
: ($Col_app.count()=4) // teamId.bundleId
For each ($appFolder; $appFoldersList) Until (This:C1470.sessionDir#Null:C1517)
If ($appFolder.fullName=$appID)
If ($appFolder.exists)
This:C1470.sessionDir:=$appFolder
End if
End if
End for each
If (This:C1470.sessionDir=Null:C1517)
var $bundleId; $prefix : Text
$prefix:=Substring:C12($appID; 1; 4)
$bundleId:=Substring:C12($appID; 5; Length:C16($appID)-1)
If ($prefix="___.")
$skipAssert:=True:C214
For each ($appFolder; $appFoldersList) Until (This:C1470.sessionDir#Null:C1517)
$pos:=Position:C15($bundleId; $appFolder.fullName)
If ($pos>1) // we don't want folder that starts with an unknown teamId so the condition is not '$pos>0'
If ($appFolder.exists)
This:C1470.sessionDir:=$appFolder
// Else : application directory doesn't exist
End if
// Else : BundleId found
End if
End for each
End if
End if
: ($Col_app.count()=5) // ___.teamId.bundleId
$skipAssert:=True:C214
End case
End if
// Else : couldn't find MobileApps folder in host database
End if
If (This:C1470.sessionDir=Null:C1517)
If (Not:C34($skipAssert))
ASSERT:C1129(False:C215; "Session folder could not be found")
End if
End if
//-------------------------------------------------------------------------
Function getAllDeviceTokens()->$tokens : Object
If (This:C1470.sessionDir=Null:C1517)
ASSERT:C1129(False:C215; "Session folder could not be found")
End if
$tokens:=MOBILE APP Get all deviceTokens(This:C1470.sessionDir)
//-------------------------------------------------------------------------
Function getAllMailAddresses()->$mailAddresses : Object
If (This:C1470.sessionDir=Null:C1517)
ASSERT:C1129(False:C215; "Session folder could not be found")
End if
$mailAddresses:=MA Get all mailAddresses(This:C1470.sessionDir)
//-------------------------------------------------------------------------
Function getSessionInfoFromMail($mail : Text)->$sessionInfo : Object
If (This:C1470.sessionDir=Null:C1517)
ASSERT:C1129(False:C215; "Session folder could not be found")
End if
If (Asserted:C1132(Count parameters:C259>=1; "Missing mail address parameter"))
ASSERT:C1129(Value type:C1509($mail)=Is text:K8:3; "The function requires a mail address, a text is expected")
End if
$sessionInfo:=MOBILE APP Get session info(This:C1470.sessionDir; $mail)
//-------------------------------------------------------------------------
Function getSessionInfoFromDeviceToken($deviceToken : Text)->$sessionInfo : Object
If (This:C1470.sessionDir=Null:C1517)
ASSERT:C1129(False:C215; "Session folder could not be found")
End if
If (Asserted:C1132(Count parameters:C259>=1; "Missing device token parameter"))
ASSERT:C1129(Value type:C1509($deviceToken)=Is text:K8:3; "The function requires a device token, a text is expected")
End if
$sessionInfo:=MA Get session info deviceToken(This:C1470.sessionDir; $deviceToken)
//-------------------------------------------------------------------------
Function getSessionObjects()->$sessionObjects : Collection
$sessionObjects:=New collection:C1472()
If (This:C1470.sessionDir=Null:C1517)
ASSERT:C1129(False:C215; "Session folder could not be found")
End if
var $sessionFile : 4D:C1709.File
For each ($sessionFile; This:C1470.sessionDir.files())
If ($sessionFile.extension="")
$sessionObjects.push(cs:C1710.SessionObject.new($sessionFile))
End if
End for each