Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Returns the id of the default chat for the given wiki.
- *
- * Expects the deafult room name and default topic name because those require MediaWiki-side i18n.
- *
- * If the chat doesn't exist, creates it.
- *
- * Returns JSON with three keys:
- * roomId, roomName, and roomTopic.
- */
- function api_getDefaultRoomId(cityId, defaultRoomName, defaultRoomTopic, extraDataString){
- // See if there are any rooms for this wiki and if there are, get the first one.
- var roomId = "";
- var roomName = "";
- var roomTopic = "";
- var keyForListOfRooms = getKey_listOfRooms(cityId);
- rc.llen(keyForListOfRooms, function(err, numRooms){
- if (err) {
- console.log('Error: while getting length of list of rooms for wiki with cityId "'+ cityId + '": ' + err);
- } else if (numRooms && (numRooms != 0)) {
- console.log("Found " + numRooms + " rooms...");
- var roomIds = rc.lrange(keyForListOfRooms, 0, 1, function(err, roomIds){
- if (err) {
- console.log('Error: first room for cityId "'+ cityId + '": ' + err);
- } else if(roomIds){
- // TODO: REMOVE - not sure what format roomIds will be in, though.
- // STILL TESTING THIS PART
- console.log("Room ids returned: ");
- console.log(roomIds);
- /* roomId = roomIds[0];
- var roomKey = getKey_room(roomId);
- rc.hgetall(roomKey, function(err, roomData){
- if(err){
- console.log("Error: couldn't get hash data for room w/key '"+ roomKey + "': " + err);
- } else {
- roomName = roomData.roomName;
- roomTopic = roomData.roomTopic;
- }
- });
- */
- } else {
- console.log("First room not found even though there were rooms a moment ago for cityId: " + cityId);
- }
- });
- }
- // No existing room could not be loaded. Create one.
- if(!roomId){
- roomId = api_createChatRoom(cityId, defaultRoomName, defaultRoomTopic, extraDataString);
- roomName = defaultRoomName;
- roomTopic = defaultRoomTopic;
- }
- });
- var result = {
- 'roomId': roomId,
- 'roomName': roomName,
- 'roomTopic': roomTopic
- };
- return result;
- } // end api_getDefaultRoomId()
Add Comment
Please, Sign In to add comment