add new user set avatar and profile background
This commit is contained in:
@@ -4,10 +4,8 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"go-socket/packages/Enums/WsEventType"
|
||||
"go-socket/packages/cache"
|
||||
"go-socket/packages/types"
|
||||
"go-socket/packages/wsServer"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -134,65 +132,6 @@ func HandleHubCreate(response http.ResponseWriter, request *http.Request) {
|
||||
cache.SaveHub(hub)
|
||||
}
|
||||
|
||||
func HandleChannelSendMessage(response http.ResponseWriter, request *http.Request) {
|
||||
if !validCheckWithResponseOnFail(&response, request, normal) {
|
||||
return
|
||||
}
|
||||
ctx := request.Context()
|
||||
user, hubUser, hub, err := getHubUserIfValidWithResponseOnFail(ctx, response, request.Header.Get("token"), request.FormValue("hubid"))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msgContent := request.FormValue("msgContent")
|
||||
attachedFile := request.FormValue("attachedFile")
|
||||
|
||||
if msgContent == "" && attachedFile == "" {
|
||||
http.Error(response, "empty msgContent", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
channel, err := getHubChannelIfValidWithResponseOnFail(ctx, response, hub, hubUser, request.FormValue("channelid"))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !haveHubUserPermissionsOnChannel(types.CachedUserCanMessage, hubUser, channel) {
|
||||
http.Error(response, "cannot send messages here", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
message := &types.Message{
|
||||
Id: uuid.New(),
|
||||
AttachedFile: "",
|
||||
Content: msgContent,
|
||||
Sender: user.Id,
|
||||
Receiver: channel.Id,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
channel.Mu.RLock()
|
||||
recipients := make([]uuid.UUID, 0, len(channel.UsersCachedPermissions))
|
||||
for id, userCachedPerms := range channel.UsersCachedPermissions {
|
||||
if userCachedPerms.CanReadHistory() && id != user.Id {
|
||||
recipients = append(recipients, id)
|
||||
}
|
||||
}
|
||||
channel.Mu.RUnlock()
|
||||
|
||||
for _, id := range recipients {
|
||||
targetUser, err := cache.GetUserById(id)
|
||||
if err != nil {
|
||||
// todo Add to postgres in future
|
||||
continue
|
||||
}
|
||||
wsServer.WsSendMessageCloseIfTimeout(targetUser, types.WsEventMessage{
|
||||
Type: WsEventType.HubMessage,
|
||||
Event: message,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func HandleHubJoin(response http.ResponseWriter, request *http.Request) {
|
||||
if !validCheckWithResponseOnFail(&response, request, normal) {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user