This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import React, { Component } from 'react'; | |
import moment from 'moment'; | |
import groupBy from 'lodash/groupBy'; | |
import mapKeys from 'lodash/mapKeys'; | |
import { css, StyleSheet } from 'aphrodite'; | |
import debounce from 'lodash/debounce'; | |
import Message from '../Message'; | |
const styles = StyleSheet.create({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const initialState = { | |
channel: null, | |
currentRoom: {}, | |
messages: [], | |
presentUsers: [], | |
loadingOlderMessages: false, // new line | |
pagination: { // new line | |
total_pages: 0, | |
total_entries: 0, | |
page_size: 0, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// top of file | |
import api from '../api'; | |
// bottom of file | |
export function loadOlderMessages(roomId, params) { | |
return (dispatch) => { | |
dispatch({ type: 'FETCH_MESSAGES_REQUEST' }); | |
return api.fetch(`/rooms/${roomId}/messages`, params) | |
.then((response) => { | |
dispatch({ type: 'FETCH_MESSAGES_SUCCESS', response }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
resources "/rooms", RoomController, only: [:index, :create] do | |
resources "/messages", MessageController, only: [:index] | |
end | |
# ...rest of file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Sling.MessageController do | |
use Sling.Web, :controller | |
plug Guardian.Plug.EnsureAuthenticated, handler: Sling.SessionController | |
def index(conn, params) do | |
last_seen_id = params["last_seen_id"] || 0 | |
room = Repo.get!(Sling.Room, params["room_id"]) | |
page = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import React from 'react'; | |
import { css, StyleSheet } from 'aphrodite'; | |
const styles = StyleSheet.create({ | |
roomSidebar: { | |
color: '#ab9ba9', | |
background: '#4d394b', | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import React, { Component } from 'react'; | |
import { connect } from 'react-redux'; | |
import { connectToChannel, leaveChannel, createMessage } from '../../actions/room'; | |
import MessageList from '../../components/MessageList'; | |
import MessageForm from '../../components/MessageForm'; | |
import RoomNavbar from '../../components/RoomNavbar'; | |
import RoomSidebar from '../../components/RoomSidebar'; // new line | |
type MessageType = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const initialState = { | |
channel: null, | |
currentRoom: {}, | |
messages: [], | |
presentUsers: [], // new line | |
}; | |
export default function (state = initialState, action) { | |
switch (action.type) { | |
case 'ROOM_CONNECTED_TO_CHANNEL': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { reset } from 'redux-form'; | |
import { Presence } from 'phoenix'; // new line | |
// new function | |
const syncPresentUsers = (dispatch, presences) => { | |
const presentUsers = []; | |
Presence.list(presences, (id, { metas: [first] }) => first.user) | |
.map(user => presentUsers.push(user)); | |
dispatch({ type: 'ROOM_PRESENCE_UPDATE', presentUsers }); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Sling.RoomChannel do | |
use Sling.Web, :channel | |
def join("rooms:" <> room_id, _params, socket) do | |
room = Repo.get!(Sling.Room, room_id) | |
page = | |
Sling.Message | |
|> where([m], m.room_id == ^room.id) | |
|> order_by([desc: :inserted_at, desc: :id]) |