fix changes from debug, edit groups return, add new connections func
This commit is contained in:
@@ -381,7 +381,7 @@ func HttpHandleUserAcceptConnection(response http.ResponseWriter, request *http.
|
||||
}
|
||||
|
||||
targetId, err := ConvertStringUint32(request.FormValue("connectedid"))
|
||||
if err != nil {
|
||||
if err != nil || user.Connections[targetId] == nil {
|
||||
http.Error(response, "invalid recipient id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -400,7 +400,7 @@ func HttpHandleUserAcceptConnection(response http.ResponseWriter, request *http.
|
||||
return
|
||||
}
|
||||
}
|
||||
if user.Connections[targetId] == nil {
|
||||
if target.Connections[user.Id] == nil {
|
||||
http.Error(response, "invalid recipient id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@@ -420,6 +420,23 @@ func HttpHandleUserAcceptConnection(response http.ResponseWriter, request *http.
|
||||
response.WriteHeader(http.StatusAccepted)
|
||||
}
|
||||
|
||||
func HttpHandleUserGetConnections(response http.ResponseWriter, request *http.Request) {
|
||||
ctx := request.Context()
|
||||
user, err := getUser(ctx, request.FormValue("token"))
|
||||
if err != nil {
|
||||
http.Error(response, "invalid token", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json2.Marshal(user.Connections)
|
||||
if err != nil {
|
||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
response.WriteHeader(http.StatusAccepted)
|
||||
response.Write(json)
|
||||
}
|
||||
|
||||
func HttpHandleTokenNew(response http.ResponseWriter, request *http.Request) {
|
||||
if !isMethodAllowed(&response, request) {
|
||||
return
|
||||
@@ -777,23 +794,13 @@ func HttpHandleGroupsGetWithoutMembers(response http.ResponseWriter, request *ht
|
||||
return
|
||||
}
|
||||
|
||||
groups := make([]GroupNoMembers, 0, len(user.Groups))
|
||||
|
||||
groups := make(map[uint32]*Group, len(user.Groups))
|
||||
for groupId := range user.Groups {
|
||||
group, err := getGroup(ctx, groupId)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
groups = append(groups, GroupNoMembers{
|
||||
Id: groupId,
|
||||
Name: group.Name,
|
||||
CreatedAt: group.CreatedAt,
|
||||
CreatorId: group.CreatorId,
|
||||
OwnerId: group.OwnerId,
|
||||
Color: group.Color,
|
||||
EnableUsersColors: group.EnableUserColors,
|
||||
})
|
||||
groups[groupId] = group
|
||||
}
|
||||
|
||||
json, err := json2.Marshal(groups)
|
||||
|
||||
Reference in New Issue
Block a user