Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

reducer.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // @flow
  2. import { CONFERENCE_JOINED, CONFERENCE_LEFT, SET_PASSWORD } from '../base/conference';
  3. import { ReducerRegistry } from '../base/redux';
  4. import {
  5. KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED,
  6. KNOCKING_PARTICIPANT_LEFT,
  7. REMOVE_LOBBY_CHAT_WITH_MODERATOR,
  8. SET_KNOCKING_STATE,
  9. SET_LOBBY_MODE_ENABLED,
  10. SET_LOBBY_PARTICIPANT_CHAT_STATE,
  11. SET_LOBBY_VISIBILITY,
  12. SET_PASSWORD_JOIN_FAILED
  13. } from './actionTypes';
  14. const DEFAULT_STATE = {
  15. knocking: false,
  16. knockingParticipants: [],
  17. lobbyEnabled: false,
  18. lobbyVisible: false,
  19. passwordJoinFailed: false
  20. };
  21. /**
  22. * Reduces redux actions which affect the display of notifications.
  23. *
  24. * @param {Object} state - The current redux state.
  25. * @param {Object} action - The redux action to reduce.
  26. * @returns {Object} The next redux state which is the result of reducing the
  27. * specified {@code action}.
  28. */
  29. ReducerRegistry.register('features/lobby', (state = DEFAULT_STATE, action) => {
  30. switch (action.type) {
  31. case CONFERENCE_JOINED:
  32. case CONFERENCE_LEFT:
  33. return {
  34. ...state,
  35. knocking: false,
  36. passwordJoinFailed: false
  37. };
  38. case KNOCKING_PARTICIPANT_ARRIVED_OR_UPDATED:
  39. return _knockingParticipantArrivedOrUpdated(action.participant, state);
  40. case KNOCKING_PARTICIPANT_LEFT:
  41. return {
  42. ...state,
  43. knockingParticipants: state.knockingParticipants.filter(p => p.id !== action.id)
  44. };
  45. case SET_KNOCKING_STATE:
  46. return {
  47. ...state,
  48. knocking: action.knocking,
  49. passwordJoinFailed: false
  50. };
  51. case SET_LOBBY_MODE_ENABLED:
  52. return {
  53. ...state,
  54. lobbyEnabled: action.enabled
  55. };
  56. case SET_LOBBY_VISIBILITY:
  57. return {
  58. ...state,
  59. lobbyVisible: action.visible
  60. };
  61. case SET_PASSWORD:
  62. return {
  63. ...state,
  64. passwordJoinFailed: false
  65. };
  66. case SET_PASSWORD_JOIN_FAILED:
  67. return {
  68. ...state,
  69. passwordJoinFailed: action.failed
  70. };
  71. case SET_LOBBY_PARTICIPANT_CHAT_STATE:
  72. return {
  73. ...state,
  74. knockingParticipants: state.knockingParticipants.map(participant => {
  75. if (participant.id === action.participant.id) {
  76. return {
  77. ...participant,
  78. chattingWithModerator: action.moderator.id
  79. };
  80. }
  81. return participant;
  82. })
  83. };
  84. case REMOVE_LOBBY_CHAT_WITH_MODERATOR:
  85. return {
  86. ...state,
  87. knockingParticipants: state.knockingParticipants.map(participant => {
  88. if (participant.chattingWithModerator === action.moderatorId) {
  89. return {
  90. ...participant,
  91. chattingWithModerator: undefined
  92. };
  93. }
  94. return participant;
  95. })
  96. };
  97. }
  98. return state;
  99. });
  100. /**
  101. * Stores or updates a knocking participant.
  102. *
  103. * @param {Object} participant - The arrived or updated knocking participant.
  104. * @param {Object} state - The current Redux state of the feature.
  105. * @returns {Object}
  106. */
  107. function _knockingParticipantArrivedOrUpdated(participant, state) {
  108. let existingParticipant = state.knockingParticipants.find(p => p.id === participant.id);
  109. existingParticipant = {
  110. ...existingParticipant,
  111. ...participant
  112. };
  113. return {
  114. ...state,
  115. knockingParticipants: [
  116. ...state.knockingParticipants.filter(p => p.id !== participant.id),
  117. existingParticipant
  118. ]
  119. };
  120. }