store msg db and inbox by identity
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc
2024-03-29 18:07:06 +01:00
parent 0b8e3c4c90
commit 31df45e771
3 changed files with 28 additions and 10 deletions

View File

@ -31,12 +31,14 @@ type Identity struct {
StaticMtkServerPaths []ServerList `json:"static_mtk_server_paths,omitempty"`
DynamicMtkServeRules []string `json:"dynamic_mtk_serve_rules,omitempty"`
InvitationTimeout int `json:"invitation_timeout,omitempty"`
Uuid string `json:"uuid,omitempty"`
unlockedHiddenPeers PeerList
}
func CreateIdentity(nickname string) *Identity {
var id Identity
id.Nickname = nickname
id.Uuid = uuid.New().String()
id.RootKp = meowlib.NewKeyPair()
GetConfig().me = &id
id.MessageServers = ServerStorage{DbFile: uuid.NewString()}
@ -44,6 +46,14 @@ func CreateIdentity(nickname string) *Identity {
return &id
}
func (id *Identity) CreateFolder() error {
err := os.MkdirAll(filepath.Join(GetConfig().StoragePath, id.Uuid), 0700)
if err != nil {
return err
}
return nil
}
// Creates an invitation for a peer, returns the newly created peer including infos to provide a ContactCard
func (id *Identity) InvitePeer(MyName string, ContactName string, MessageServerUids []string, InvitationMessage string) (*Peer, error) {
var peer Peer
@ -171,6 +181,10 @@ func (id *Identity) Save() error {
if GetConfig().IdentityFile == "" {
return errors.New("identity filename empty")
}
//! temp patch
if id.Uuid == "" {
id.Uuid = uuid.New().String()
}
b, _ := json.Marshal(id)
armor, err := helper.EncryptMessageWithPassword([]byte(GetConfig().memoryPassword), string(b))
if err != nil {
@ -296,7 +310,8 @@ func (id *Identity) SaveBackgroundJob() error {
if err != nil {
return err
}
err = os.WriteFile(filepath.Join(GetConfig().StoragePath, ".jobs"), jsonjobs, 0600)
id.CreateFolder()
err = os.WriteFile(filepath.Join(GetConfig().StoragePath, id.Uuid, ".jobs"), jsonjobs, 0600)
if err != nil {
return err
}