Exemple #1
0
func (Chat) ChatDelete(so *wsevent.Client, args struct {
	ID   *int  `json:"id"`
	Room *uint `json:"room"`
}) interface{} {

	if err := chelpers.CheckPrivilege(so, helpers.ActionDeleteChat); err != nil {
		return err
	}

	message := &models.ChatMessage{}
	err := db.DB.Table("chat_messages").Where("room = ? AND id = ?", args.Room, args.ID).First(message).Error
	if message.Bot {
		return helpers.NewTPError("Cannot delete notification messages", -1)
	}
	if err != nil {
		return helpers.NewTPError("Can't find message", -1)
	}

	player, _ := models.GetPlayerByID(message.PlayerID)
	message.Deleted = true
	message.Timestamp = message.CreatedAt.Unix()
	message.Save()
	message.Message = "<deleted>"
	message.Player = models.DecoratePlayerSummary(player)
	message.Player.Tags = append(message.Player.Tags, "deleted")
	message.Send()

	return chelpers.EmptySuccessJS
}
Exemple #2
0
func (Chat) ChatDelete(so *wsevent.Client, args struct {
	ID   *int  `json:"id"`
	Room *uint `json:"room"`
}) interface{} {

	if err := chelpers.CheckPrivilege(so, helpers.ActionDeleteChat); err != nil {
		return err
	}

	message := &chat.ChatMessage{}
	err := db.DB.First(message, *args.ID).Error
	if message.Bot {
		return errors.New("Cannot delete notification messages")
	}
	if err != nil {
		return errors.New("Can't find message")
	}

	message.Deleted = true
	message.Save()
	message.Send()

	return emptySuccess
}