message ack receice and reactions protobuf
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc
2026-03-06 11:59:47 +01:00
parent f6531e344e
commit d23ab73cf9
4 changed files with 204 additions and 72 deletions

View File

@@ -368,6 +368,67 @@ func SetMessageServerDelivery(dbFile string, dbId int64, serverUid string, recei
return UpdateDbMessage(dbm, dbFile, dbId, password)
}
// FindMessageByUuid scans all DB files for a peer (newest first) and returns
// the dbFile, row ID, and DbMessage for the message whose Status.Uuid matches.
func FindMessageByUuid(peer *Peer, messageUuid string, password string) (string, int64, *meowlib.DbMessage, error) {
cfg := GetConfig()
identity := cfg.GetIdentity()
for i := len(peer.DbIds) - 1; i >= 0; i-- {
dbid := peer.DbIds[i]
db, err := sql.Open("sqlite3", filepath.Join(cfg.StoragePath, identity.Uuid, dbid+GetConfig().DbSuffix))
if err != nil {
continue
}
rows, err := db.Query("SELECT id, m FROM message ORDER BY id DESC")
if err != nil {
db.Close()
continue
}
for rows.Next() {
var id int64
var m []byte
if err := rows.Scan(&id, &m); err != nil {
continue
}
decdata, err := meowlib.SymDecrypt(password, m)
if err != nil {
continue
}
var dbm meowlib.DbMessage
if err := proto.Unmarshal(decdata, &dbm); err != nil {
continue
}
if dbm.Status != nil && dbm.Status.Uuid == messageUuid {
rows.Close()
db.Close()
return dbid, id, &dbm, nil
}
}
rows.Close()
db.Close()
}
return "", 0, nil, fmt.Errorf("message with UUID %s not found", messageUuid)
}
// UpdateMessageAck finds a stored outbound message by UUID and stamps it with
// the received and/or processed timestamps from an inbound ACK message.
func UpdateMessageAck(peer *Peer, messageUuid string, receivedAt uint64, processedAt uint64, password string) error {
dbFile, dbId, dbm, err := FindMessageByUuid(peer, messageUuid, password)
if err != nil {
return err
}
if dbm.Status == nil {
dbm.Status = &meowlib.ConversationStatus{}
}
if receivedAt != 0 {
dbm.Status.Received = receivedAt
}
if processedAt != 0 {
dbm.Status.Processed = processedAt
}
return UpdateDbMessage(dbm, dbFile, dbId, password)
}
func createMessageTable(db *sql.DB) error {
createMessageTableSQL := `CREATE TABLE message (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,