UpdateMessage updates an existing message by its ID.
(_ context.Context, messageID int64, msg *Message)
| 286 | |
| 287 | // UpdateMessage updates an existing message by its ID. |
| 288 | func (s *InMemorySessionStore) UpdateMessage(_ context.Context, messageID int64, msg *Message) error { |
| 289 | // Create a deep copy of the message to avoid mutating the caller's pointer, |
| 290 | // which may be shared with another Session object. |
| 291 | updated := cloneMessage(msg) |
| 292 | updated.ID = messageID |
| 293 | |
| 294 | // For in-memory store, we need to find the message across all sessions |
| 295 | var found bool |
| 296 | s.sessions.Range(func(_ string, session *Session) bool { |
| 297 | session.mu.Lock() |
| 298 | defer session.mu.Unlock() |
| 299 | for i := range session.Messages { |
| 300 | if session.Messages[i].Message == nil || session.Messages[i].Message.ID != messageID { |
| 301 | continue |
| 302 | } |
| 303 | session.Messages[i].Message = updated |
| 304 | found = true |
| 305 | return false |
| 306 | } |
| 307 | return true |
| 308 | }) |
| 309 | if !found { |
| 310 | return ErrNotFound |
| 311 | } |
| 312 | return nil |
| 313 | } |
| 314 | |
| 315 | // AddSubSession creates a sub-session and links it to the parent. |
| 316 | func (s *InMemorySessionStore) AddSubSession(_ context.Context, parentSessionID string, subSession *Session) error { |
nothing calls this directly
no test coverage detected