dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 1764298d8b98ff098f133cf2468e6893e321b8c1
parent 1c8898199280ee3c807621b3c3c49aa0814a7593
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue, 18 Feb 2025 14:33:50 -0800

add hellbanMsg to createMsg function

Diffstat:
Mpkg/database/database.go | 2+-
Mpkg/database/tableChatMessages.go | 11++++++-----
Mpkg/database/utils/utils.go | 8++++----
Mpkg/web/handlers/interceptors/battleship.go | 4++--
Mpkg/web/handlers/interceptors/chess.go | 2+-
Mpkg/web/handlers/interceptors/command/command.go | 6+++---
6 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/pkg/database/database.go b/pkg/database/database.go @@ -49,7 +49,7 @@ type IDkfDB interface { CreateLinkPgp(linkID int64, title, description, publicKey string) (out LinksPgp, err error) CreateLinksCategory(category string) (out LinksCategory, err error) CreateLinksTag(tag string) (out LinksTag, err error) - CreateMsg(raw, txt, roomKey string, roomID RoomID, userID UserID, toUserID *UserID) (out ChatMessage, err error) + CreateMsg(raw, txt, roomKey string, roomID RoomID, userID UserID, toUserID *UserID, hellbanMsg bool) (out ChatMessage, err error) CreateNotification(msg string, userID UserID) CreateOrEditMessage(editMsg *ChatMessage, message, raw, roomKey string, roomID RoomID, fromUserID UserID, toUserID *UserID, upload *Upload, groupID *GroupID, hellbanMsg, modMsg, systemMsg bool) (int64, error) CreateRoom(name string, passwordHash string, ownerID UserID, isListed bool) (out ChatRoom, err error) diff --git a/pkg/database/tableChatMessages.go b/pkg/database/tableChatMessages.go @@ -569,17 +569,17 @@ func makeMsg(raw, txt string, roomID RoomID, userID UserID) ChatMessage { return msg } -func (d *DkfDB) CreateMsg(raw, txt, roomKey string, roomID RoomID, userID UserID, toUserID *UserID) (out ChatMessage, err error) { - return d.createMsg(raw, txt, roomKey, roomID, userID, toUserID, false, false) +func (d *DkfDB) CreateMsg(raw, txt, roomKey string, roomID RoomID, userID UserID, toUserID *UserID, hellbanMsg bool) (out ChatMessage, err error) { + return d.createMsg(raw, txt, roomKey, roomID, userID, toUserID, hellbanMsg, false, false) } func (d *DkfDB) CreateSysMsg(raw, txt, roomKey string, roomID RoomID, userID UserID) error { - _, err := d.createMsg(raw, txt, roomKey, roomID, userID, nil, true, false) + _, err := d.createMsg(raw, txt, roomKey, roomID, userID, nil, false, true, false) return err } func (d *DkfDB) CreateSysMsgPM(raw, txt, roomKey string, roomID RoomID, userID UserID, toUserID *UserID, skipNotify bool) error { - _, err := d.createMsg(raw, txt, roomKey, roomID, userID, toUserID, true, skipNotify) + _, err := d.createMsg(raw, txt, roomKey, roomID, userID, toUserID, false, true, skipNotify) return err } @@ -603,7 +603,7 @@ func (d *DkfDB) CreateUnkickMsg(kickedUser, kickedByUser User) { } } -func (d *DkfDB) createMsg(raw, txt, roomKey string, roomID RoomID, userID UserID, toUserID *UserID, system, skipNotify bool) (out ChatMessage, err error) { +func (d *DkfDB) createMsg(raw, txt, roomKey string, roomID RoomID, userID UserID, toUserID *UserID, hellbanMsg, system, skipNotify bool) (out ChatMessage, err error) { if roomKey != "" { var err error txt, raw, err = encryptMessages(txt, raw, roomKey) @@ -617,6 +617,7 @@ func (d *DkfDB) createMsg(raw, txt, roomKey string, roomID RoomID, userID UserID if toUserID != nil { out.ToUserID = toUserID } + out.IsHellbanned = hellbanMsg out.System = system err = d.db.Create(&out).Error MsgPubSub.Pub("room_"+roomID.String(), ChatMessageType{Typ: CreateMsg, Msg: out}) diff --git a/pkg/database/utils/utils.go b/pkg/database/utils/utils.go @@ -21,7 +21,7 @@ func GetZeroUser(db *database.DkfDB) database.User { func ZeroSendMsg(db *database.DkfDB, recipientID database.UserID, msg string) { zeroUser := GetZeroUser(db) - _, _ = db.CreateMsg(msg, msg, "", config.GeneralRoomID, zeroUser.ID, &recipientID) + _, _ = db.CreateMsg(msg, msg, "", config.GeneralRoomID, zeroUser.ID, &recipientID, false) } func RootAdminNotify(db *database.DkfDB, msg string) { @@ -37,9 +37,9 @@ func SendNewChessGameMessages(db *database.DkfDB, key, roomKey string, roomID da return } raw, msg := getPlayerMsg(player2) - _, _ = db.CreateMsg(raw, msg, roomKey, roomID, zeroUser.ID, &player1.ID) + _, _ = db.CreateMsg(raw, msg, roomKey, roomID, zeroUser.ID, &player1.ID, false) raw, msg = getPlayerMsg(player1) - _, _ = db.CreateMsg(raw, msg, roomKey, roomID, zeroUser.ID, &player2.ID) + _, _ = db.CreateMsg(raw, msg, roomKey, roomID, zeroUser.ID, &player2.ID, false) // Send notifications to chess games subscribers raw = `Chess game: ` + string(player1.Username) + ` VS ` + string(player2.Username) @@ -59,7 +59,7 @@ func SendNewChessGameMessages(db *database.DkfDB, key, roomKey string, roomID da // Make a copy of user ID, otherwise next iteration will overwrite the pointer // and change data that was sent previously in the pubsub later on userID := user.ID - _, _ = db.CreateMsg(raw, msg, roomKey, roomID, zeroUser.ID, &userID) + _, _ = db.CreateMsg(raw, msg, roomKey, roomID, zeroUser.ID, &userID, false) } } diff --git a/pkg/web/handlers/interceptors/battleship.go b/pkg/web/handlers/interceptors/battleship.go @@ -595,10 +595,10 @@ func (b *Battleship) PlayMove(roomName string, roomID database.RoomID, roomKey s } card1 := g.drawCardFor(0, roomName, isNewGame, shipDead, gameEnded, shipStr, pos) - _, _ = b.db.CreateMsg(card1, card1, roomKey, roomID, b.zeroID, &g.player1.id) + _, _ = b.db.CreateMsg(card1, card1, roomKey, roomID, b.zeroID, &g.player1.id, false) card2 := g.drawCardFor(1, roomName, isNewGame, shipDead, gameEnded, shipStr, pos) - _, _ = b.db.CreateMsg(card2, card2, roomKey, roomID, b.zeroID, &g.player2.id) + _, _ = b.db.CreateMsg(card2, card2, roomKey, roomID, b.zeroID, &g.player2.id, false) if gameEnded { delete(b.games, gameKey) diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go @@ -863,7 +863,7 @@ func (b *Chess) SendMove(gameKey string, userID database.UserID, g *ChessGame, c if opponentPlayer.NotifyChessMove { msg := fmt.Sprintf("@%s played %s", currentPlayer.Username, moveStr) msg, _ = dutils.ColorifyTaggedUsers(msg, b.db.GetUsersByUsername) - chatMsg, _ := b.db.CreateMsg(msg, msg, "", config.GeneralRoomID, b.zeroID, &opponentPlayer.ID) + chatMsg, _ := b.db.CreateMsg(msg, msg, "", config.GeneralRoomID, b.zeroID, &opponentPlayer.ID, false) go func() { time.Sleep(30 * time.Second) _ = chatMsg.Delete(b.db) diff --git a/pkg/web/handlers/interceptors/command/command.go b/pkg/web/handlers/interceptors/command/command.go @@ -160,7 +160,7 @@ func (c *Command) rawMsg(user1 database.User, user2 *database.User, raw, msg str if c.Room.ReadOnly { return } - rawMsgRoom(c.DB, user1, user2, raw, msg, c.RoomKey, c.Room.ID) + rawMsgRoom(c.DB, user1, user2, raw, msg, c.RoomKey, c.Room.ID, c.HellbanMsg) } func (c *Command) rawSysMsg(user1 database.User, user2 *database.User, raw, msg string, skipNotify bool) { @@ -170,12 +170,12 @@ func (c *Command) rawSysMsg(user1 database.User, user2 *database.User, raw, msg rawSysMsgRoom(c.DB, user1, user2, raw, msg, c.RoomKey, c.Room.ID, skipNotify) } -func rawMsgRoom(db *database.DkfDB, user1 database.User, user2 *database.User, raw, msg, roomKey string, roomID database.RoomID) { +func rawMsgRoom(db *database.DkfDB, user1 database.User, user2 *database.User, raw, msg, roomKey string, roomID database.RoomID, hellbanMsg bool) { var toUserID *database.UserID if user2 != nil { toUserID = &user2.ID } - _, _ = db.CreateMsg(raw, msg, roomKey, roomID, user1.ID, toUserID) + _, _ = db.CreateMsg(raw, msg, roomKey, roomID, user1.ID, toUserID, hellbanMsg) } func rawSysMsgRoom(db *database.DkfDB, user1 database.User, user2 *database.User, raw, msg, roomKey string, roomID database.RoomID, skipNotify bool) {