Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F10384279
WriteFreelyModel.swift
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
WriteFreelyModel.swift
View Options
import
Foundation
import
WriteFreely
//
MARK:
- WriteFreelyModel
class
WriteFreelyModel
:
ObservableObject
{
@
Published
var
account
=
AccountModel
()
@
Published
var
preferences
=
PreferencesModel
()
@
Published
var
store
=
PostStore
()
@
Published
var
post
:
Post
?
@
Published
var
isLoggingIn
:
Bool
=
false
private
var
client
:
WFClient
?
init
()
{
#if
DEBUG
for
post
in
testPostData
{
store
.
add
(
post
)
}
#endif
}
}
//
MARK:
- WriteFreelyModel API
extension
WriteFreelyModel
{
func
login
(
to
server
:
URL
,
as
username
:
String
,
password
:
String
)
{
isLoggingIn
=
true
account
.
server
=
server
.
absoluteString
client
=
WFClient
(
for
:
server
)
client
?.
login
(
username
:
username
,
password
:
password
,
completion
:
loginHandler
)
}
func
logout
()
{
guard
let
loggedInClient
=
client
else
{
return
}
loggedInClient
.
logout
(
completion
:
logoutHandler
)
}
}
private
extension
WriteFreelyModel
{
func
loginHandler
(
result
:
Result
<
WFUser
,
Error
>)
{
isLoggingIn
=
false
do
{
let
user
=
try
result
.
get
()
account
.
login
(
user
)
dump
(
user
)
}
catch
{
dump
(
error
)
}
}
func
logoutHandler
(
result
:
Result
<
Bool
,
Error
>)
{
do
{
let
loggedOut
=
try
result
.
get
()
if
loggedOut
{
client
=
nil
account
.
logout
()
}
}
catch
{
dump
(
error
)
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Sat, Nov 23, 9:48 AM (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3104504
Attached To
rWFSUI WriteFreely SwiftUI
Event Timeline
Log In to Comment