Guest User

Untitled

a guest
Jan 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. /**
  2. * Returns the id of the default chat for the given wiki.
  3. *
  4. * Expects the deafult room name and default topic name because those require MediaWiki-side i18n.
  5. *
  6. * If the chat doesn't exist, creates it.
  7. *
  8. * Returns JSON with three keys:
  9. * roomId, roomName, and roomTopic.
  10. */
  11. function api_getDefaultRoomId(cityId, defaultRoomName, defaultRoomTopic, extraDataString){
  12. // See if there are any rooms for this wiki and if there are, get the first one.
  13. var roomId = "";
  14. var roomName = "";
  15. var roomTopic = "";
  16.  
  17. var keyForListOfRooms = getKey_listOfRooms(cityId);
  18. rc.llen(keyForListOfRooms, function(err, numRooms){
  19. if (err) {
  20. console.log('Error: while getting length of list of rooms for wiki with cityId "'+ cityId + '": ' + err);
  21. } else if (numRooms && (numRooms != 0)) {
  22. console.log("Found " + numRooms + " rooms...");
  23. var roomIds = rc.lrange(keyForListOfRooms, 0, 1, function(err, roomIds){
  24. if (err) {
  25. console.log('Error: first room for cityId "'+ cityId + '": ' + err);
  26. } else if(roomIds){
  27.  
  28. // TODO: REMOVE - not sure what format roomIds will be in, though.
  29. // STILL TESTING THIS PART
  30. console.log("Room ids returned: ");
  31. console.log(roomIds);
  32. /* roomId = roomIds[0];
  33. var roomKey = getKey_room(roomId);
  34. rc.hgetall(roomKey, function(err, roomData){
  35. if(err){
  36. console.log("Error: couldn't get hash data for room w/key '"+ roomKey + "': " + err);
  37. } else {
  38. roomName = roomData.roomName;
  39. roomTopic = roomData.roomTopic;
  40. }
  41. });
  42. */
  43.  
  44. } else {
  45. console.log("First room not found even though there were rooms a moment ago for cityId: " + cityId);
  46. }
  47. });
  48. }
  49.  
  50. // No existing room could not be loaded. Create one.
  51. if(!roomId){
  52. roomId = api_createChatRoom(cityId, defaultRoomName, defaultRoomTopic, extraDataString);
  53. roomName = defaultRoomName;
  54. roomTopic = defaultRoomTopic;
  55. }
  56. });
  57.  
  58. var result = {
  59. 'roomId': roomId,
  60. 'roomName': roomName,
  61. 'roomTopic': roomTopic
  62. };
  63.  
  64. return result;
  65. } // end api_getDefaultRoomId()
Add Comment
Please, Sign In to add comment