Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elixxir dApps SDK Swift
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile
iOS
Elixxir dApps SDK Swift
Commits
12770a2c
Commit
12770a2c
authored
2 years ago
by
Dariusz Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
Add GroupRequestHandler to messenger example
parent
24808135
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!153
Release 1.1.0
,
!148
[Messenger Example] Setup group chat
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Examples/xx-messenger/Sources/AppCore/Groups/GroupRequestHandler.swift
+99
-0
99 additions, 0 deletions
...essenger/Sources/AppCore/Groups/GroupRequestHandler.swift
with
99 additions
and
0 deletions
Examples/xx-messenger/Sources/AppCore/Groups/GroupRequestHandler.swift
0 → 100644
+
99
−
0
View file @
12770a2c
import
XXModels
import
XXClient
import
Foundation
import
XXMessengerClient
import
XCTestDynamicOverlay
public
struct
GroupRequestHandler
{
public
typealias
OnError
=
(
Error
)
->
Void
public
var
run
:
(
@escaping
OnError
)
->
Cancellable
public
func
callAsFunction
(
onError
:
@escaping
OnError
)
->
Cancellable
{
run
(
onError
)
}
}
extension
GroupRequestHandler
{
public
static
func
live
(
messenger
:
Messenger
,
db
:
DBManagerGetDB
)
->
GroupRequestHandler
{
GroupRequestHandler
{
onError
in
messenger
.
registerGroupRequestHandler
(
.
init
{
group
in
do
{
if
let
_
=
try
db
()
.
fetchGroups
(
.
init
(
id
:
[
group
.
getId
()]))
.
first
{
return
}
guard
let
leader
=
try
group
.
getMembership
()
.
first
else
{
return
// Failed to get group membership/leader
}
try
db
()
.
saveGroup
(
.
init
(
id
:
group
.
getId
(),
name
:
String
(
data
:
group
.
getName
(),
encoding
:
.
utf8
)
!
,
leaderId
:
leader
.
id
,
createdAt
:
Date
(
timeIntervalSince1970
:
TimeInterval
(
group
.
getCreatedMS
())
/
1_000
),
authStatus
:
.
pending
,
serialized
:
group
.
serialize
()
))
if
let
initialMessageData
=
group
.
getInitMessage
(),
let
initialMessage
=
String
(
data
:
initialMessageData
,
encoding
:
.
utf8
)
{
try
db
()
.
saveMessage
(
.
init
(
senderId
:
leader
.
id
,
recipientId
:
nil
,
groupId
:
group
.
getId
(),
date
:
Date
(
timeIntervalSince1970
:
TimeInterval
(
group
.
getCreatedMS
())
/
1_000
),
status
:
.
received
,
isUnread
:
true
,
text
:
initialMessage
))
}
let
members
=
try
group
.
getMembership
()
let
friends
=
try
db
()
.
fetchContacts
(
.
init
(
id
:
Set
(
members
.
map
(\
.
id
)),
authStatus
:
[
.
friend
,
.
hidden
,
.
confirming
,
.
verified
,
.
requested
,
.
requesting
,
.
verificationInProgress
,
.
requestFailed
,
.
verificationFailed
,
.
confirmationFailed
]))
let
strangers
=
Set
(
members
.
map
(\
.
id
))
.
subtracting
(
Set
(
friends
.
map
(\
.
id
)))
try
strangers
.
forEach
{
if
let
stranger
=
try
?
db
()
.
fetchContacts
(
.
init
(
id
:
[
$0
]))
.
first
{
print
(
stranger
)
}
else
{
try
db
()
.
saveContact
(
.
init
(
id
:
$0
,
username
:
"Fetching..."
,
authStatus
:
.
stranger
,
isRecent
:
false
,
isBlocked
:
false
,
isBanned
:
false
,
createdAt
:
Date
(
timeIntervalSince1970
:
TimeInterval
(
group
.
getCreatedMS
())
/
1_000
)
))
}
}
try
members
.
map
{
XXModels
.
GroupMember
(
groupId
:
group
.
getId
(),
contactId
:
$0
.
id
)
}
.
forEach
{
try
db
()
.
saveGroupMember
(
$0
)
}
let
lookupResult
=
try
messenger
.
lookupContacts
(
ids
:
strangers
.
map
{
$0
})
for
user
in
lookupResult
.
contacts
{
if
var
foo
=
try
?
db
()
.
fetchContacts
(
.
init
(
id
:
[
user
.
getId
()]))
.
first
,
let
username
=
try
?
user
.
getFact
(
.
username
)?
.
value
{
foo
.
username
=
username
_
=
try
?
db
()
.
saveContact
(
foo
)
}
}
}
catch
{
onError
(
error
)
}
})
}
}
}
extension
GroupRequestHandler
{
public
static
let
unimplemented
=
GroupRequestHandler
(
run
:
XCTestDynamicOverlay
.
unimplemented
(
"
\(
Self
.
self
)
"
,
placeholder
:
Cancellable
{})
)
}
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