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

@@ -148,6 +148,16 @@ func ConsumeInboxFile(messageFilename string) ([]string, []string, string, error
return nil, nil, "ReadMessage: ProcessInboundUserMessage", err
}
// Check for received or processed already filled => it's an ack for one of our sent messages
if len(usermsg.Data) == 0 && usermsg.Status != nil && usermsg.Status.Uuid != "" &&
(usermsg.Status.Received != 0 || usermsg.Status.Processed != 0) {
password, _ := client.GetConfig().GetMemPass()
if ackErr := client.UpdateMessageAck(peer, usermsg.Status.Uuid, usermsg.Status.Received, usermsg.Status.Processed, password); ackErr != nil {
logger.Warn().Err(ackErr).Str("uuid", usermsg.Status.Uuid).Msg("ConsumeInboxFile: UpdateMessageAck")
}
continue
}
//fmt.Println("From:", usermsg.From)
//jsonUserMessage, _ := json.Marshal(usermsg)
//fmt.Println(string(jsonUserMessage))
@@ -202,7 +212,7 @@ func ConsumeInboxFile(messageFilename string) ([]string, []string, string, error
logger.Warn().Err(ackErr).Str("peer", peer.Uid).Msg("ConsumeInboxFile: sendDeliveryAck")
}
}
}
}
}
err = os.Remove(messageFilename)

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,