identity in config to allow save from everywhere
This commit is contained in:
		@@ -11,6 +11,7 @@ type Config struct {
 | 
				
			|||||||
	SavePassword  bool   `json:"save_password,omitempty"`
 | 
						SavePassword  bool   `json:"save_password,omitempty"`
 | 
				
			||||||
	SavedPassword string `json:"saved_password,omitempty"`
 | 
						SavedPassword string `json:"saved_password,omitempty"`
 | 
				
			||||||
	// Technical
 | 
						// Technical
 | 
				
			||||||
 | 
						IdentityFile       string `json:"identity_file,omitempty"`
 | 
				
			||||||
	StoragePath        string `json:"storage_path,omitempty"`
 | 
						StoragePath        string `json:"storage_path,omitempty"`
 | 
				
			||||||
	MaxIdsPerUser      int    `json:"max_ids_per_user,omitempty"`
 | 
						MaxIdsPerUser      int    `json:"max_ids_per_user,omitempty"`
 | 
				
			||||||
	MsgDbRollingPeriod int    `json:"msg_db_rolling_period,omitempty"`
 | 
						MsgDbRollingPeriod int    `json:"msg_db_rolling_period,omitempty"`
 | 
				
			||||||
@@ -29,10 +30,10 @@ type Config struct {
 | 
				
			|||||||
	PrivateChatNotifiactions    bool   `json:"private_chat_notifiactions,omitempty"`
 | 
						PrivateChatNotifiactions    bool   `json:"private_chat_notifiactions,omitempty"`
 | 
				
			||||||
	GroupChatNotifiactions      bool   `json:"group_chat_notifiactions,omitempty"`
 | 
						GroupChatNotifiactions      bool   `json:"group_chat_notifiactions,omitempty"`
 | 
				
			||||||
	ChannelNotifications        bool   `json:"channel_notifications,omitempty"`
 | 
						ChannelNotifications        bool   `json:"channel_notifications,omitempty"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Inner
 | 
						// Inner
 | 
				
			||||||
	memoryPassword      string
 | 
						memoryPassword      string
 | 
				
			||||||
	additionalPasswords []string
 | 
						additionalPasswords []string
 | 
				
			||||||
	identityFile        string
 | 
					 | 
				
			||||||
	me                  *Identity
 | 
						me                  *Identity
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -115,7 +115,7 @@ func (id *Identity) FinalizeInvitation(ReceivedContact *meowlib.ContactCard) err
 | 
				
			|||||||
func LoadIdentity(filename string, password string) (*Identity, error) {
 | 
					func LoadIdentity(filename string, password string) (*Identity, error) {
 | 
				
			||||||
	var id Identity
 | 
						var id Identity
 | 
				
			||||||
	GetConfig().memoryPassword = password
 | 
						GetConfig().memoryPassword = password
 | 
				
			||||||
	GetConfig().identityFile = filename
 | 
						GetConfig().IdentityFile = filename
 | 
				
			||||||
	indata, err := os.ReadFile(filename)
 | 
						indata, err := os.ReadFile(filename)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
@@ -135,6 +135,6 @@ func (id *Identity) Save() error {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	err = os.WriteFile(GetConfig().identityFile, []byte(armor), 0600)
 | 
						err = os.WriteFile(GetConfig().IdentityFile, []byte(armor), 0600)
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,7 @@ import (
 | 
				
			|||||||
	"forge.redroom.link/yves/meowlib"
 | 
						"forge.redroom.link/yves/meowlib"
 | 
				
			||||||
	"github.com/google/uuid"
 | 
						"github.com/google/uuid"
 | 
				
			||||||
	_ "github.com/mattn/go-sqlite3"
 | 
						_ "github.com/mattn/go-sqlite3"
 | 
				
			||||||
 | 
						"google.golang.org/protobuf/proto"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func StoreMessage(peer *Peer, usermessage *meowlib.UserMessage, password string) error {
 | 
					func StoreMessage(peer *Peer, usermessage *meowlib.UserMessage, password string) error {
 | 
				
			||||||
@@ -34,11 +35,11 @@ func StoreMessage(peer *Peer, usermessage *meowlib.UserMessage, password string)
 | 
				
			|||||||
	// Open Db
 | 
						// Open Db
 | 
				
			||||||
	db, _ := sql.Open("sqlite3", filepath.Join(GetConfig().StoragePath, dbid)) // Open the created SQLite File
 | 
						db, _ := sql.Open("sqlite3", filepath.Join(GetConfig().StoragePath, dbid)) // Open the created SQLite File
 | 
				
			||||||
	defer db.Close()
 | 
						defer db.Close()
 | 
				
			||||||
	// TODO Detach Files
 | 
						// Detach Files
 | 
				
			||||||
	if len(usermessage.Files) > 0 {
 | 
						if len(usermessage.Files) > 0 {
 | 
				
			||||||
		for _, f := range usermessage.Files {
 | 
							for _, f := range usermessage.Files {
 | 
				
			||||||
			hiddenFilename := uuid.NewString()
 | 
								hiddenFilename := uuid.NewString()
 | 
				
			||||||
			// TODO cypher file
 | 
								// Cypher file
 | 
				
			||||||
			encData, err := meowlib.SymEncrypt(password, f.Data)
 | 
								encData, err := meowlib.SymEncrypt(password, f.Data)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return err
 | 
									return err
 | 
				
			||||||
@@ -48,14 +49,22 @@ func StoreMessage(peer *Peer, usermessage *meowlib.UserMessage, password string)
 | 
				
			|||||||
			f.Data = []byte(hiddenFilename)
 | 
								f.Data = []byte(hiddenFilename)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// TODO Encrypt message
 | 
						// Encrypt message
 | 
				
			||||||
	// Inser message
 | 
						out, err := proto.Marshal(usermessage)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						encData, err := meowlib.SymEncrypt(password, out)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// Insert message
 | 
				
			||||||
	insertMessageSQL := `INSERT INTO message(m) VALUES (?)`
 | 
						insertMessageSQL := `INSERT INTO message(m) VALUES (?)`
 | 
				
			||||||
	statement, err := db.Prepare(insertMessageSQL) // Prepare statement.
 | 
						statement, err := db.Prepare(insertMessageSQL) // Prepare statement.
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	_, err = statement.Exec(usermessage)
 | 
						_, err = statement.Exec(encData)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user