🐛 Tryin' to fix notifications issue
This commit is contained in:
		@@ -116,6 +116,7 @@ func (v *Server) NotifyAllUser(_ context.Context, in *proto.NotifyRequest) (*pro
 | 
				
			|||||||
			Picture:     in.Picture,
 | 
								Picture:     in.Picture,
 | 
				
			||||||
			IsRealtime:  in.GetIsRealtime(),
 | 
								IsRealtime:  in.GetIsRealtime(),
 | 
				
			||||||
			IsForcePush: in.GetIsForcePush(),
 | 
								IsForcePush: in.GetIsForcePush(),
 | 
				
			||||||
 | 
								Account:     user,
 | 
				
			||||||
			AccountID:   user.ID,
 | 
								AccountID:   user.ID,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -67,6 +67,26 @@ func NewNotification(notification models.Notification) error {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewNotificationBatch(notifications []models.Notification) error {
 | 
					func NewNotificationBatch(notifications []models.Notification) error {
 | 
				
			||||||
 | 
						if len(notifications) == 0 {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						notifiable := CheckNotificationNotifiableBatch(lo.Map(notifications, func(item models.Notification, index int) models.Account {
 | 
				
			||||||
 | 
							return item.Account
 | 
				
			||||||
 | 
						}), notifications[0].Topic)
 | 
				
			||||||
 | 
						accountIdx := lo.Map(
 | 
				
			||||||
 | 
							lo.Filter(notifications, func(item models.Notification, index int) bool {
 | 
				
			||||||
 | 
								return notifiable[index]
 | 
				
			||||||
 | 
							}),
 | 
				
			||||||
 | 
							func(item models.Notification, index int) uint {
 | 
				
			||||||
 | 
								return item.AccountID
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(accountIdx) == 0 {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := database.C.CreateInBatches(notifications, 1000).Error; err != nil {
 | 
						if err := database.C.CreateInBatches(notifications, 1000).Error; err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,10 +47,8 @@ func CheckNotificationNotifiable(account models.Account, topic string) bool {
 | 
				
			|||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if val, ok := notification.Config[topic]; ok {
 | 
						if val, ok := notification.Config[topic]; ok {
 | 
				
			||||||
		if status, ok := val.(bool); !ok || status {
 | 
							if status, ok := val.(bool); ok {
 | 
				
			||||||
			return true
 | 
								return status
 | 
				
			||||||
		} else if !status {
 | 
					 | 
				
			||||||
			return false
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return true
 | 
						return true
 | 
				
			||||||
@@ -67,11 +65,8 @@ func CheckNotificationNotifiableBatch(accounts []models.Account, topic string) [
 | 
				
			|||||||
	var notifiable []bool
 | 
						var notifiable []bool
 | 
				
			||||||
	for _, notification := range notifications {
 | 
						for _, notification := range notifications {
 | 
				
			||||||
		if val, ok := notification.Config[topic]; ok {
 | 
							if val, ok := notification.Config[topic]; ok {
 | 
				
			||||||
			if status, ok := val.(bool); !ok || status {
 | 
								if status, ok := val.(bool); ok {
 | 
				
			||||||
				notifiable = append(notifiable, true)
 | 
									notifiable = append(notifiable, status)
 | 
				
			||||||
				continue
 | 
					 | 
				
			||||||
			} else if !status {
 | 
					 | 
				
			||||||
				notifiable = append(notifiable, false)
 | 
					 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user