add dynamic profile update, connection helper, file download metadata
- replace UserSetColor/UserSetPronouns with single UserUpdateProfile that dynamically builds one UPDATE query from UserProfileUpdateList - add getConnectionWithResponseOnFail helper to deduplicate connection ID parsing and validation across handlers - rename file.go to attachmentFile.go and update handler names - GetDownloadUrlAndMetadata now fetches object metadata via StatObject and returns it alongside the presigned URL - file download endpoint returns JSON with url and originalName - add description field to user and DB schema - remove unused ConnectionState variants (GroupFellow, GroupFriend) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -32,14 +32,8 @@ func HandleDm(response http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
targetConnection, err := convertions.ConvertStringUuid(request.FormValue("connectionid"))
|
||||
if err != nil {
|
||||
http.Error(response, "invalid connectionid", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
conn, ok := cache.CacheGetConnection(user, targetConnection)
|
||||
conn, ok := getConnectionWithResponseOnFail(&response, request, user)
|
||||
if !ok {
|
||||
http.Error(response, "invalid connectionid", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -51,7 +45,7 @@ func HandleDm(response http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if attachedFile != "" && !strings.HasPrefix(attachedFile, targetConnection.String()+"/") {
|
||||
if attachedFile != "" && !strings.HasPrefix(attachedFile, conn.Id.String()+"/") {
|
||||
http.Error(response, "invalid attachedFile", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -105,9 +99,8 @@ func HandleUserGetConnectionMessages(response http.ResponseWriter, request *http
|
||||
return
|
||||
}
|
||||
|
||||
connectionId, err := convertions.ConvertStringUuid(request.FormValue("connectionid"))
|
||||
if err != nil {
|
||||
http.Error(response, "invalid connectionid", http.StatusBadRequest)
|
||||
conn, ok := getConnectionWithResponseOnFail(&response, request, user)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -121,12 +114,6 @@ func HandleUserGetConnectionMessages(response http.ResponseWriter, request *http
|
||||
messagesCap = globals.MaxDirectMsgCache
|
||||
}
|
||||
|
||||
conn, ok := cache.CacheGetConnection(user, connectionId)
|
||||
if !ok {
|
||||
http.Error(response, "invalid connectionid", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
buffer, bufferSize := conn.GetSortedMessagesBuff()
|
||||
|
||||
var validBufCount uint32
|
||||
@@ -148,7 +135,7 @@ func HandleUserGetConnectionMessages(response http.ResponseWriter, request *http
|
||||
if validBufCount > 0 {
|
||||
cutoff = buffer[0].CreatedAt
|
||||
}
|
||||
dbMessages, err := postgresql.ConnectionGetMessagesBefore(ctx, cutoff, connectionId, remaining)
|
||||
dbMessages, err := postgresql.ConnectionGetMessagesBefore(ctx, cutoff, conn.Id, remaining)
|
||||
if err != nil {
|
||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
@@ -241,15 +228,8 @@ func HandleUserDeleteConnection(response http.ResponseWriter, request *http.Requ
|
||||
return
|
||||
}
|
||||
|
||||
connectionId, err := convertions.ConvertStringUuid(request.FormValue("connectionid"))
|
||||
if err != nil {
|
||||
http.Error(response, "invalid connectionid", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
conn, ok := cache.CacheGetConnection(user, connectionId)
|
||||
conn, ok := getConnectionWithResponseOnFail(&response, request, user)
|
||||
if !ok {
|
||||
http.Error(response, "invalid connectionid", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -279,10 +259,10 @@ func HandleUserDeleteConnection(response http.ResponseWriter, request *http.Requ
|
||||
return
|
||||
}
|
||||
|
||||
cache.CacheDeleteConnection(user, user2, connectionId)
|
||||
cache.CacheDeleteConnection(user, user2, conn.Id)
|
||||
wsServer.WsSendMessageCloseIfTimeout(user2, types.WsEventMessage{
|
||||
Type: WsEventType.ConnectionDeleted,
|
||||
Event: connectionId,
|
||||
Event: conn.Id,
|
||||
})
|
||||
|
||||
response.WriteHeader(http.StatusAccepted)
|
||||
@@ -298,14 +278,8 @@ func HandleUserElevateConnection(response http.ResponseWriter, request *http.Req
|
||||
http.Error(response, "invalid token", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
connectionId, err := convertions.ConvertStringUuid(request.FormValue("connectionid"))
|
||||
if err != nil {
|
||||
http.Error(response, "invalid connectionid", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
conn, ok := cache.CacheGetConnection(user, connectionId)
|
||||
conn, ok := getConnectionWithResponseOnFail(&response, request, user)
|
||||
if !ok {
|
||||
http.Error(response, "invalid connectionid", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -316,9 +290,6 @@ func HandleUserElevateConnection(response http.ResponseWriter, request *http.Req
|
||||
case ConnectionState.Stranger:
|
||||
conn.State = ConnectionState.Friend
|
||||
break
|
||||
case ConnectionState.GroupFellow:
|
||||
conn.State = ConnectionState.Stranger
|
||||
break
|
||||
default:
|
||||
http.Error(response, "cannot elevate further", http.StatusBadRequest)
|
||||
return
|
||||
@@ -345,7 +316,7 @@ func HandleUserElevateConnection(response http.ResponseWriter, request *http.Req
|
||||
wsServer.WsSendMessageCloseIfTimeout(user2, types.WsEventMessage{
|
||||
Type: WsEventType.ConnectionElevated,
|
||||
Event: types.ConnectionElevationData{
|
||||
Id: connectionId,
|
||||
Id: conn.Id,
|
||||
NewState: conn.State,
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user