Skip to content
Snippets Groups Projects
Commit cd874b2d authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Use UpdateFromMessageID instead of recursing

parent 469533e2
No related branches found
No related tags found
2 merge requests!129Do not error out when this message already exists inside the DB. Instead, set...,!109Project/haven beta
......@@ -436,19 +436,20 @@ func (w *wasmModel) upsertMessage(msg *Message) (uint64, error) {
msgIdObj, err := impl.Put(w.db, messageStoreName, messageObj)
if err != nil {
// Do not error out when this message already exists inside
// the DB. Instead, set the ID and re-attempt as an upsert.
// the DB. Instead, set the ID and re-attempt as an update.
if msg.ID == 0 { // always error out when not an insert attempt
msgID, inErr := message.UnmarshalID(msg.MessageID)
if inErr == nil {
jww.WARN.Printf("upsertMessage duplicate: %+v",
err)
existingMsg, inErr := w.GetMessage(msgID)
if inErr == nil && existingMsg.UUID != 0 {
msg.ID = existingMsg.UUID
return w.upsertMessage(msg)
}
jww.ERROR.Printf("upsertMessage no UUID: %+v",
inErr)
rnd := &rounds.Round{ID: id.Round(msg.Round)}
status := (*channels.SentStatus)(&msg.Status)
return w.UpdateFromMessageID(msgID,
&msg.Timestamp,
rnd,
&msg.Pinned,
&msg.Hidden,
status)
}
}
return 0, errors.Errorf("Unable to put Message: %+v\n%s",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment