createRoom implements /createRoom nolint: gocyclo
( ctx context.Context, r createRoomRequest, device *api.Device, cfg *config.ClientAPI, profileAPI api.ClientUserAPI, rsAPI roomserverAPI.ClientRoomserverAPI, asAPI appserviceAPI.AppServiceInternalAPI, evTime time.Time, )
| 180 | // createRoom implements /createRoom |
| 181 | // nolint: gocyclo |
| 182 | func createRoom( |
| 183 | ctx context.Context, |
| 184 | r createRoomRequest, device *api.Device, |
| 185 | cfg *config.ClientAPI, |
| 186 | profileAPI api.ClientUserAPI, rsAPI roomserverAPI.ClientRoomserverAPI, |
| 187 | asAPI appserviceAPI.AppServiceInternalAPI, |
| 188 | evTime time.Time, |
| 189 | ) util.JSONResponse { |
| 190 | // TODO (#267): Check room ID doesn't clash with an existing one, and we |
| 191 | // probably shouldn't be using pseudo-random strings, maybe GUIDs? |
| 192 | roomID := fmt.Sprintf("!%s:%s", util.RandomString(16), cfg.Matrix.ServerName) |
| 193 | |
| 194 | logger := util.GetLogger(ctx) |
| 195 | userID := device.UserID |
| 196 | |
| 197 | // Clobber keys: creator, room_version |
| 198 | |
| 199 | roomVersion := roomserverVersion.DefaultRoomVersion() |
| 200 | if r.RoomVersion != "" { |
| 201 | candidateVersion := gomatrixserverlib.RoomVersion(r.RoomVersion) |
| 202 | _, roomVersionError := roomserverVersion.SupportedRoomVersion(candidateVersion) |
| 203 | if roomVersionError != nil { |
| 204 | return util.JSONResponse{ |
| 205 | Code: http.StatusBadRequest, |
| 206 | JSON: jsonerror.UnsupportedRoomVersion(roomVersionError.Error()), |
| 207 | } |
| 208 | } |
| 209 | roomVersion = candidateVersion |
| 210 | } |
| 211 | |
| 212 | // TODO: visibility/presets/raw initial state |
| 213 | // TODO: Create room alias association |
| 214 | // Make sure this doesn't fall into an application service's namespace though! |
| 215 | |
| 216 | logger.WithFields(log.Fields{ |
| 217 | "userID": userID, |
| 218 | "roomID": roomID, |
| 219 | "roomVersion": roomVersion, |
| 220 | }).Info("Creating new room") |
| 221 | |
| 222 | profile, err := appserviceAPI.RetrieveUserProfile(ctx, userID, asAPI, profileAPI) |
| 223 | if err != nil { |
| 224 | util.GetLogger(ctx).WithError(err).Error("appserviceAPI.RetrieveUserProfile failed") |
| 225 | return jsonerror.InternalServerError() |
| 226 | } |
| 227 | |
| 228 | createContent := map[string]interface{}{} |
| 229 | if len(r.CreationContent) > 0 { |
| 230 | if err = json.Unmarshal(r.CreationContent, &createContent); err != nil { |
| 231 | util.GetLogger(ctx).WithError(err).Error("json.Unmarshal for creation_content failed") |
| 232 | return util.JSONResponse{ |
| 233 | Code: http.StatusBadRequest, |
| 234 | JSON: jsonerror.BadJSON("invalid create content"), |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | createContent["creator"] = userID |
| 239 | createContent["room_version"] = roomVersion |
no test coverage detected