mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-06 10:00:24 +08:00
消息任务防止单个接收人接收到多封同样的内容
This commit is contained in:
@@ -122,24 +122,31 @@ func (this *MessageTaskDAO) CreateMessageTasks(tx *dbs.Tx, target MessageTaskTar
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
allRecipientIds := []int64{}
|
||||||
for _, receiver := range receivers {
|
for _, receiver := range receivers {
|
||||||
if receiver.RecipientId > 0 {
|
if receiver.RecipientId > 0 {
|
||||||
_, err := this.CreateMessageTask(tx, int64(receiver.RecipientId), 0, "", subject, body, false)
|
allRecipientIds = append(allRecipientIds, int64(receiver.RecipientId))
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else if receiver.RecipientGroupId > 0 {
|
} else if receiver.RecipientGroupId > 0 {
|
||||||
recipientIds, err := SharedMessageRecipientDAO.FindAllEnabledAndOnRecipientIdsWithGroup(tx, int64(receiver.RecipientGroupId))
|
recipientIds, err := SharedMessageRecipientDAO.FindAllEnabledAndOnRecipientIdsWithGroup(tx, int64(receiver.RecipientGroupId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, recipientId := range recipientIds {
|
allRecipientIds = append(allRecipientIds, recipientIds...)
|
||||||
_, err := this.CreateMessageTask(tx, recipientId, 0, "", subject, body, false)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sentMap := map[int64]bool{} // recipientId => bool 用来检查是否已经发送,防止重复发送给某个接收人
|
||||||
|
for _, recipientId := range allRecipientIds {
|
||||||
|
_, ok := sentMap[recipientId]
|
||||||
|
if ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sentMap[recipientId] = true
|
||||||
|
_, err := this.CreateMessageTask(tx, recipientId, 0, "", subject, body, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user