💄 Better DM
This commit is contained in:
parent
9aa5dec54d
commit
8567ce7d17
@ -209,7 +209,7 @@ func deleteChannel(c *fiber.Ctx) error {
|
||||
tx = tx.Where("realm_id = ?", val.ID)
|
||||
}
|
||||
} else {
|
||||
tx = tx.Where("account_id = ? AND realm_id IS NULL", user.ID)
|
||||
tx = tx.Where("(account_id = ? OR type = ?) AND realm_id IS NULL", user.ID, models.ChannelTypeDirect)
|
||||
}
|
||||
|
||||
var channel models.Channel
|
||||
@ -217,6 +217,14 @@ func deleteChannel(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||
}
|
||||
|
||||
if channel.Type == models.ChannelTypeDirect {
|
||||
if member, err := services.GetChannelMember(user, channel.ID); err != nil {
|
||||
return fiber.NewError(fiber.StatusForbidden, "you must related to this direct message if you want delete it")
|
||||
} else if member.PowerLevel < 100 {
|
||||
return fiber.NewError(fiber.StatusForbidden, "you must be a moderator of this direct message if you want delete it")
|
||||
}
|
||||
}
|
||||
|
||||
if err := services.DeleteChannel(channel); err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
@ -38,7 +38,9 @@ func createDirectChannel(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
var relatedUser models.Account
|
||||
if err := database.C.Where("id = ?", data.RelatedUser).First(&relatedUser).Error; err != nil {
|
||||
if err := database.C.
|
||||
Where("external_id = ?", data.RelatedUser).
|
||||
First(&relatedUser).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("unable to find related user: %v", err))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user