diff --git a/client.go b/client.go index 6654ead..48bc043 100644 --- a/client.go +++ b/client.go @@ -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 +}