/**1* This file is provided by Facebook for testing and evaluation purposes2* only. Facebook reserves all rights not expressly granted.3*4* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR5* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,6* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL7* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN8* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN9* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.10*/1112var ChatServerActionCreators = require('../actions/ChatServerActionCreators');1314// !!! Please Note !!!15// We are using localStorage as an example, but in a real-world scenario, this16// would involve XMLHttpRequest, or perhaps a newer client-server protocol.17// The function signatures below might be similar to what you would build, but18// the contents of the functions are just trying to simulate client-server19// communication and server-side processing.2021module.exports = {2223getAllMessages: function() {24// simulate retrieving data from a database25var rawMessages = JSON.parse(localStorage.getItem('messages'));2627// simulate success callback28ChatServerActionCreators.receiveAll(rawMessages);29},3031createMessage: function(message, threadName) {32// simulate writing to a database33var rawMessages = JSON.parse(localStorage.getItem('messages'));34var timestamp = Date.now();35var id = 'm_' + timestamp;36var threadID = message.threadID || ('t_' + Date.now());37var createdMessage = {38id: id,39threadID: threadID,40threadName: threadName,41authorName: message.authorName,42text: message.text,43timestamp: timestamp44};45rawMessages.push(createdMessage);46localStorage.setItem('messages', JSON.stringify(rawMessages));4748// simulate success callback49setTimeout(function() {50ChatServerActionCreators.receiveCreatedMessage(createdMessage);51}, 0);52}5354};555657