43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
|
|
package chat
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"go.uber.org/zap"
|
||
|
|
)
|
||
|
|
|
||
|
|
func (h *MessageHandler) HandleJoinConversation(ctx context.Context, client *Client, msg *IncomingMessage) {
|
||
|
|
if msg.ConversationID == nil {
|
||
|
|
client.SendJSON(NewErrorResponse("conversation_id is required"))
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
if !h.permissions.CanJoin(ctx, client.UserID, *msg.ConversationID) {
|
||
|
|
client.SendJSON(NewErrorResponse("not allowed to join this conversation"))
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
h.hub.JoinRoom(client, *msg.ConversationID)
|
||
|
|
|
||
|
|
h.logger.Info("User joined conversation",
|
||
|
|
zap.String("user_id", client.UserID.String()),
|
||
|
|
zap.String("conversation_id", msg.ConversationID.String()))
|
||
|
|
|
||
|
|
client.SendJSON(NewActionConfirmedResponse("joined_conversation", true))
|
||
|
|
}
|
||
|
|
|
||
|
|
func (h *MessageHandler) HandleLeaveConversation(ctx context.Context, client *Client, msg *IncomingMessage) {
|
||
|
|
if msg.ConversationID == nil {
|
||
|
|
client.SendJSON(NewErrorResponse("conversation_id is required"))
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
h.hub.LeaveRoom(client, *msg.ConversationID)
|
||
|
|
|
||
|
|
h.logger.Info("User left conversation",
|
||
|
|
zap.String("user_id", client.UserID.String()),
|
||
|
|
zap.String("conversation_id", msg.ConversationID.String()))
|
||
|
|
|
||
|
|
client.SendJSON(NewActionConfirmedResponse("left_conversation", true))
|
||
|
|
}
|