Skip to content

Commit 7c4e604

Browse files
committed
fix: improve mapping logic
1 parent 9c83df7 commit 7c4e604

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

service/messages.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,16 +590,22 @@ func (s *MessageService) SaveMapping(req *models.MappingRequest) (*models.Mappin
590590
s.mu.Lock()
591591
defer s.mu.Unlock()
592592

593+
numberKey := fmt.Sprintf("%d", req.Number)
593594
// Clean up old sub-number mappings if updating an existing entry
594-
if oldEntry, exists := s.mappings[fmt.Sprintf("%d", req.Number)]; exists {
595+
if oldEntry, exists := s.mappings[numberKey]; exists {
596+
for _, sub := range oldEntry.SubNumbers {
597+
delete(s.subNumberMappings, sub)
598+
}
599+
}
600+
if oldEntry, exists := s.mappings[userName]; exists {
595601
for _, sub := range oldEntry.SubNumbers {
596602
delete(s.subNumberMappings, sub)
597603
}
598604
}
599605

600606
entry.UpdatedAt = s.now()
601607
// Double map: by number and by username
602-
s.mappings[fmt.Sprintf("%d", entry.Number)] = entry
608+
s.mappings[numberKey] = entry
603609
s.mappings[userName] = entry
604610

605611
// Update sub-number index

0 commit comments

Comments
 (0)