add account data

This commit is contained in:
stryan 2023-05-30 17:50:10 -04:00
parent 891e83b54c
commit 23afd6d183
1 changed files with 24 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"strings"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
)
@ -40,3 +41,26 @@ func NewMatrixClient(config *MatrixClientConfig, store mautrix.Storer) (*mautrix
}
return client, err
}
// SetupAccountDataStore sets the client to use a AccountData store and filter appropriately
func SetupAccountDataStore(client *mautrix.Client, token string) error {
dataFilter := &mautrix.Filter{
AccountData: mautrix.FilterPart{
Limit: 20,
NotTypes: []event.Type{
event.NewEventType(token),
},
},
}
store := mautrix.NewAccountDataStore(token, client)
fID, err := client.CreateFilter(dataFilter)
if err != nil {
//don't want to continue if we can't keep state
return err
}
uid := client.UserID
store.SaveFilterID(uid, fID.FilterID)
client.Store = store
return nil
}