Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
xx messenger iOS
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile
iOS
xx messenger iOS
Commits
ee55cb34
Commit
ee55cb34
authored
Aug 15, 2022
by
Dariusz Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
Update banned list in LaunchViewModel
parent
e80652d9
No related branches found
No related tags found
3 merge requests
!71
Releasing v1.1.5 (214)
,
!69
Implemented filtering for banned/blocked users and reporting
,
!67
v1.1.5 b(203)
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Package.swift
+1
-1
1 addition, 1 deletion
Package.swift
Sources/LaunchFeature/LaunchViewModel.swift
+80
-81
80 additions, 81 deletions
Sources/LaunchFeature/LaunchViewModel.swift
with
81 additions
and
82 deletions
Package.swift
+
1
−
1
View file @
ee55cb34
...
...
@@ -516,8 +516,8 @@ let package = Package(
.
target
(
name
:
"Permissions"
),
.
target
(
name
:
"DropboxFeature"
),
.
target
(
name
:
"VersionChecking"
),
.
target
(
name
:
"ReportingFeature"
),
.
target
(
name
:
"DependencyInjection"
),
.
product
(
name
:
"SwiftCSV"
,
package
:
"SwiftCSV"
),
]
),
.
target
(
...
...
This diff is collapsed.
Click to expand it.
Sources/LaunchFeature/LaunchViewModel.swift
+
80
−
81
View file @
ee55cb34
import
HUD
import
Shared
import
Models
import
SwiftCSV
import
Combine
import
Defaults
import
XXModels
...
...
@@ -12,6 +10,7 @@ import Integration
import
Permissions
import
DropboxFeature
import
VersionChecking
import
ReportingFeature
import
CombineSchedulers
import
DependencyInjection
...
...
@@ -35,6 +34,9 @@ final class LaunchViewModel {
@Dependency
private
var
dropboxService
:
DropboxInterface
@Dependency
private
var
keychainHandler
:
KeychainHandling
@Dependency
private
var
permissionHandler
:
PermissionHandling
@Dependency
private
var
fetchBannedList
:
FetchBannedList
@Dependency
private
var
processBannedList
:
ProcessBannedList
@Dependency
private
var
session
:
SessionType
@KeyObject
(
.
username
,
defaultValue
:
nil
)
var
username
:
String
?
@KeyObject
(
.
biometrics
,
defaultValue
:
false
)
var
isBiometricsOn
:
Bool
...
...
@@ -55,8 +57,6 @@ final class LaunchViewModel {
DispatchQueue
.
global
()
.
eraseToAnyScheduler
()
}()
var
getSession
:
(
String
)
throws
->
SessionType
=
Session
.
init
private
var
cancellables
=
Set
<
AnyCancellable
>
()
private
let
routeSubject
=
PassthroughSubject
<
LaunchRoute
,
Never
>
()
private
let
hudSubject
=
CurrentValueSubject
<
HUDStatus
,
Never
>
(
.
none
)
...
...
@@ -83,22 +83,8 @@ final class LaunchViewModel {
}
func
versionApproved
()
{
Task
{
do
{
network
.
writeLogs
()
let
bannedUids
=
try
await
fetchBannedList
()
// TODO: Retry inifitely if fails
if
let
database
=
try
?
DependencyInjection
.
Container
.
shared
.
resolve
()
as
Database
{
if
let
bannedContacts
=
try
?
database
.
fetchContacts
(
Contact
.
Query
(
id
:
bannedUids
,
isBanned
:
false
))
{
bannedContacts
.
forEach
{
var
contact
=
$0
contact
.
isBanned
=
true
_
=
try
?
database
.
saveContact
(
contact
)
}
}
}
network
.
updateNDF
{
[
weak
self
]
in
guard
let
self
=
self
else
{
return
}
...
...
@@ -127,19 +113,23 @@ final class LaunchViewModel {
guard
let
self
=
self
else
{
return
}
do
{
let
session
=
try
self
.
get
Session
(
ndf
)
let
session
=
try
Session
(
ndf
:
ndf
)
DependencyInjection
.
Container
.
shared
.
register
(
session
as
SessionType
)
self
.
updateBannedList
{
DispatchQueue
.
main
.
async
{
self
.
hudSubject
.
send
(
.
none
)
self
.
checkBiometrics
()
}
catch
{
self
.
hudSubject
.
send
(
.
error
(
HUDError
(
with
:
error
)))
}
}
case
.
failure
(
let
error
):
}
catch
{
DispatchQueue
.
main
.
async
{
self
.
hudSubject
.
send
(
.
error
(
HUDError
(
with
:
error
)))
}
}
}
catch
{
}
case
.
failure
(
let
error
):
self
.
hudSubject
.
send
(
.
error
(
HUDError
(
with
:
error
)))
}
}
...
...
@@ -147,22 +137,12 @@ final class LaunchViewModel {
func
getContactWith
(
userId
:
Data
)
->
Contact
?
{
let
query
=
Contact
.
Query
(
id
:
[
userId
],
isBlocked
:
false
,
isBanned
:
false
)
guard
let
session
=
try
?
DependencyInjection
.
Container
.
shared
.
resolve
()
as
SessionType
,
let
contact
=
try
?
session
.
dbManager
.
fetchContacts
(
query
)
.
first
else
{
return
nil
}
return
contact
return
try!
session
.
dbManager
.
fetchContacts
(
query
)
.
first
}
func
getGroupInfoWith
(
groupId
:
Data
)
->
GroupInfo
?
{
guard
let
session
:
SessionType
=
try
?
DependencyInjection
.
Container
.
shared
.
resolve
(),
let
info
=
try
?
session
.
dbManager
.
fetchGroupInfos
(
.
init
(
groupId
:
groupId
))
.
first
else
{
return
nil
}
return
info
let
query
=
GroupInfo
.
Query
(
groupId
:
groupId
)
return
try!
session
.
dbManager
.
fetchGroupInfos
(
query
)
.
first
}
private
func
versionFailed
(
error
:
Error
)
{
...
...
@@ -220,31 +200,50 @@ final class LaunchViewModel {
}
}
private
func
fetchBannedList
()
async
throws
->
Set
<
Data
>
{
let
url
=
URL
(
string
:
"https://elixxir-bins.s3.us-west-1.amazonaws.com/client/bannedUsers/bannedTesting.csv"
)
return
try
await
withCheckedThrowingContinuation
{
continuation
in
URLSession
.
shared
.
dataTask
(
with
:
url
!
)
{
data
,
_
,
error
in
if
let
error
=
error
{
return
continuation
.
resume
(
throwing
:
error
)
private
func
updateBannedList
(
completion
:
@escaping
()
->
Void
)
{
fetchBannedList
{
result
in
switch
result
{
case
.
failure
(
_
):
DispatchQueue
.
main
.
asyncAfter
(
deadline
:
.
now
()
+
2
)
{
self
.
updateBannedList
(
completion
:
completion
)
}
case
.
success
(
let
data
):
self
.
processBannedList
(
data
,
completion
:
completion
)
}
}
guard
let
data
=
data
else
{
fatalError
(
"No data was downloaded as banned users csv"
)
}
guard
let
csvRaw
=
String
(
data
:
data
,
encoding
:
.
utf8
),
let
csv
=
try
?
CSV
<
Enumerated
>
(
string
:
csvRaw
)
else
{
fatalError
(
"CSV content couldn't be parsed correctly"
)
private
func
processBannedList
(
_
data
:
Data
,
completion
:
@escaping
()
->
Void
)
{
processBannedList
(
data
:
data
,
forEach
:
{
result
in
switch
result
{
case
.
success
(
let
userId
):
let
query
=
Contact
.
Query
(
id
:
[
userId
])
if
var
contact
=
try!
self
.
session
.
dbManager
.
fetchContacts
(
query
)
.
first
{
if
contact
.
isBanned
==
false
{
contact
.
isBanned
=
true
try!
self
.
session
.
dbManager
.
saveContact
(
contact
)
}
}
else
{
try!
self
.
session
.
dbManager
.
saveContact
(
.
init
(
id
:
userId
,
isBanned
:
true
))
}
guard
let
bannedUids
=
csv
.
columns
?[
0
]
.
rows
else
{
fatalError
(
"It wasn't possible to get CSV uid array"
)
case
.
failure
(
_
):
break
}
},
completion
:
{
result
in
switch
result
{
case
.
failure
(
_
):
DispatchQueue
.
main
.
asyncAfter
(
deadline
:
.
now
()
+
2
)
{
self
.
updateBannedList
(
completion
:
completion
)
}
return
continuation
.
resume
(
returning
:
Set
<
Data
>
(
bannedUids
.
compactMap
{
$0
.
data
(
using
:
.
utf8
)
}
))
}
.
resume
()
case
.
success
(
_
):
completion
()
}
}
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment