Rework headless public message API

This commit is contained in:
FIGBERT 2023-08-08 23:57:35 -07:00
parent 97154a6787
commit df0ff2035e
No known key found for this signature in database
GPG key ID: 67F1598D607A844B
2 changed files with 33 additions and 31 deletions

View file

@ -22,10 +22,10 @@ type Config struct {
MxID id.UserID MxID id.UserID
} }
func Init(conf Config, updates chan fmt.Stringer) error { func Init(conf Config, updates chan fmt.Stringer) Completed {
// setup package dir // setup package dir
os.Setenv("GOMUKS_ROOT", conf.OutputDir) os.Setenv("GOMUKS_ROOT", conf.OutputDir)
updates <- ExportDirSetMsg{dir: conf.OutputDir} updates <- exportDirSet{dir: conf.OutputDir}
// init boilerplate // init boilerplate
configDir, dataDir, cacheDir, downloadDir, err := initDirs() configDir, dataDir, cacheDir, downloadDir, err := initDirs()
@ -38,7 +38,7 @@ func Init(conf Config, updates chan fmt.Stringer) error {
if err != nil { if err != nil {
return err return err
} }
updates <- InitializedGomuksMsg{} updates <- initializedGomuks{}
// login section // login section
_, hs, err := conf.MxID.Parse() _, hs, err := conf.MxID.Parse()
@ -52,7 +52,7 @@ func Init(conf Config, updates chan fmt.Stringer) error {
} else if err = gmx.Matrix().Login(conf.MxID.String(), conf.MxPassword); err != nil { } else if err = gmx.Matrix().Login(conf.MxID.String(), conf.MxPassword); err != nil {
return err return err
} }
updates <- LoggedInMsg{account: conf.MxID} updates <- loggedIn{account: conf.MxID}
// key import // key import
data, err := os.ReadFile(conf.KeyPath) data, err := os.ReadFile(conf.KeyPath)
@ -64,7 +64,7 @@ func Init(conf Config, updates chan fmt.Stringer) error {
if err != nil { if err != nil {
return fmt.Errorf("Failed to import sessions: %v", err) return fmt.Errorf("Failed to import sessions: %v", err)
} }
updates <- ImportedKeysMsg{imported: imported, total: total} updates <- importedKeys{imported: imported, total: total}
// verify (fetch) // verify (fetch)
key, err := getSSSS(mach, conf.RecoveryPhrase) key, err := getSSSS(mach, conf.RecoveryPhrase)
@ -76,7 +76,7 @@ func Init(conf Config, updates chan fmt.Stringer) error {
if err != nil { if err != nil {
return fmt.Errorf("Error fetching cross-signing keys: %v", err) return fmt.Errorf("Error fetching cross-signing keys: %v", err)
} }
updates <- FetchedVerificationKeysMsg{} updates <- fetchedVerificationKeys{}
// verify (sign) // verify (sign)
if mach.CrossSigningKeys == nil { if mach.CrossSigningKeys == nil {
@ -87,14 +87,14 @@ func Init(conf Config, updates chan fmt.Stringer) error {
if err != nil { if err != nil {
return fmt.Errorf("Failed to self-sign: %v", err) return fmt.Errorf("Failed to self-sign: %v", err)
} }
updates <- SuccessfullyVerifiedMsg{} updates <- successfullyVerified{}
// display mode // display mode
gmx.Config().Preferences.DisplayMode = config.DisplayModeModern gmx.Config().Preferences.DisplayMode = config.DisplayModeModern
updates <- ConfiguredDisplayModeMsg{} updates <- configuredDisplayMode{}
// sync // sync
updates <- BeginningSyncMsg{} updates <- beginningSync{}
resp, err := gmx.Matrix().Client().FullSyncRequest(mautrix.ReqSync{ resp, err := gmx.Matrix().Client().FullSyncRequest(mautrix.ReqSync{
Timeout: 30000, Timeout: 30000,
Since: "", Since: "",
@ -107,10 +107,10 @@ func Init(conf Config, updates chan fmt.Stringer) error {
if err != nil { if err != nil {
return err return err
} }
updates <- FetchedSyncDataMsg{} updates <- fetchedSyncData{}
gmx.Matrix().(*matrix.Container).InitSyncer() gmx.Matrix().(*matrix.Container).InitSyncer()
updates <- ProcessingSyncMsg{} updates <- processingSync{}
err = gmx.Matrix().(*matrix.Container).ProcessSyncResponse(resp, "") err = gmx.Matrix().(*matrix.Container).ProcessSyncResponse(resp, "")
return err return err

View file

@ -2,62 +2,64 @@ package headless
import "fmt" import "fmt"
type ExportDirSetMsg struct{ dir string } type exportDirSet struct{ dir string }
func (msg ExportDirSetMsg) String() string { func (msg exportDirSet) String() string {
return fmt.Sprintf("Set gomuks root directory to %s…", msg.dir) return fmt.Sprintf("Set gomuks root directory to %s…", msg.dir)
} }
type InitializedGomuksMsg struct{} type initializedGomuks struct{}
func (msg InitializedGomuksMsg) String() string { func (msg initializedGomuks) String() string {
return "Initialized gomuks…" return "Initialized gomuks…"
} }
type LoggedInMsg struct{ account fmt.Stringer } type loggedIn struct{ account fmt.Stringer }
func (msg LoggedInMsg) String() string { func (msg loggedIn) String() string {
return fmt.Sprintf("Logged in to %s…", msg.account) return fmt.Sprintf("Logged in to %s…", msg.account)
} }
type ImportedKeysMsg struct{ imported, total int } type importedKeys struct{ imported, total int }
func (msg ImportedKeysMsg) String() string { func (msg importedKeys) String() string {
return fmt.Sprintf("Successfully imported %d/%d sessions", msg.imported, msg.total) return fmt.Sprintf("Successfully imported %d/%d sessions", msg.imported, msg.total)
} }
type FetchedVerificationKeysMsg struct{} type fetchedVerificationKeys struct{}
func (msg FetchedVerificationKeysMsg) String() string { func (msg fetchedVerificationKeys) String() string {
return "Successfully unlocked cross-signing keys…" return "Successfully unlocked cross-signing keys…"
} }
type SuccessfullyVerifiedMsg struct{} type successfullyVerified struct{}
func (msg SuccessfullyVerifiedMsg) String() string { func (msg successfullyVerified) String() string {
return "Successfully self-signed. This device is now trusted by other devices…" return "Successfully self-signed. This device is now trusted by other devices…"
} }
type ConfiguredDisplayModeMsg struct{} type configuredDisplayMode struct{}
func (msg ConfiguredDisplayModeMsg) String() string { func (msg configuredDisplayMode) String() string {
return "Configured display mode…" return "Configured display mode…"
} }
type BeginningSyncMsg struct{} type beginningSync struct{}
func (msg BeginningSyncMsg) String() string { func (msg beginningSync) String() string {
return "Beginning the sync process…" return "Beginning the sync process…"
} }
type FetchedSyncDataMsg struct{} type fetchedSyncData struct{}
func (msg FetchedSyncDataMsg) String() string { func (msg fetchedSyncData) String() string {
return "Fetched sync data…" return "Fetched sync data…"
} }
type ProcessingSyncMsg struct{} type processingSync struct{}
func (msg ProcessingSyncMsg) String() string { func (msg processingSync) String() string {
return "Processing sync response…" return "Processing sync response…"
} }
type Completed error