+
+
-
-
-
{message.message}
-
+
+
+
+ {message.senderName}
+
+
+
{message.message}
+
))}
-
-
+
>
diff --git a/jam-ui/src/store/features/textMessagesSlice.js b/jam-ui/src/store/features/textMessagesSlice.js
new file mode 100644
index 000000000..70a3fcfd5
--- /dev/null
+++ b/jam-ui/src/store/features/textMessagesSlice.js
@@ -0,0 +1,89 @@
+import { createSlice, createAsyncThunk, nanoid } from "@reduxjs/toolkit"
+import { getTextMessages, createTextMessage } from '../../helpers/rest';
+
+const initialState = {
+ messages: [],
+ status: 'idel',
+ error: null,
+ offset: 0
+}
+
+// const [offset, setOffset] = useState(0);
+// const LIMIT = 20;
+
+export const fetchMessagesByReceiverId = createAsyncThunk(
+ 'textMessage/fetchMessagesByReceiverId',
+ async (userId, thunkAPI) => {
+ const response = await getTextMessages({
+ target_user_id: userId
+ // offset: offset,
+ // limit: LIMIT
+ })
+ return response.json()
+ }
+)
+
+export const resturectureTextMessage = (args) => {
+ const { payload, sent } = args
+ //console.log(payload);
+ const messageId = payload.id ? payload.id : nanoid()
+ const createdAt = payload.created_at ? payload.created_at : new Date().toISOString()
+ return {
+ id: messageId,
+ message: payload.message,
+ senderId: payload.source_user_id,
+ senderName: payload.source_user['first_name'],
+ receiverId: payload.target_user_id,
+ receiverName: payload.target_user['first_name'],
+ createdAt: createdAt,
+ sent: sent
+ }
+}
+
+export const postNewMessage = createAsyncThunk(
+ 'textMessage/postNewMessage',
+ async (message, thunkAPI) => {
+ const response = await createTextMessage(message)
+ return { status: response.status, payload: message }
+ }
+)
+
+export const textMessageSlice = createSlice({
+ name: 'textMessage',
+ initialState,
+ reducers: {
+ addMessage: (state, action) => {
+ state.messages.push(action.payload)
+ },
+ updateMessage: state => {},
+ deleteMessage: state => {}
+ },
+ extraReducers: (builder) => {
+ builder
+ .addCase(fetchMessagesByReceiverId.pending, (state, action) => {
+ state.status = 'loading'
+ })
+ .addCase(fetchMessagesByReceiverId.fulfilled, (state, action) => {
+ state.status = 'succeeded'
+ console.log(action.payload);
+ state.messages = action.payload.map(message => resturectureTextMessage({ payload: message, sent: true }))
+ })
+ .addCase(fetchMessagesByReceiverId.rejected, (state, action) => {
+ state.status = 'failed'
+ state.error = action.error.message
+ })
+ .addCase(postNewMessage.fulfilled, (state, action) => {
+ console.log("postNewMessage fullfilled", action.payload);
+ })
+ }
+})
+
+export const { addMessage, updateMessage, deleteMessage } = textMessageSlice.actions
+
+export default textMessageSlice.reducer
+
+//export const selectAllMessages = state => state.textMessage.messages
+
+//export const selectMessageById = (state, messageId) => state.textMessage.messages.find(message => message.id === messageId)
+
+//export const selectMessagesBySenderId = (state, senderId) => state.textMessage.messages.filter(message => message.senderId === senderId)
diff --git a/jam-ui/src/store/store.js b/jam-ui/src/store/store.js
new file mode 100644
index 000000000..775c5363b
--- /dev/null
+++ b/jam-ui/src/store/store.js
@@ -0,0 +1,8 @@
+import { configureStore } from "@reduxjs/toolkit"
+import textMessageReducer from "./features/textMessagesSlice"
+
+export default configureStore({
+ reducer: {
+ textMessage: textMessageReducer
+ }
+})
\ No newline at end of file
diff --git a/ruby/lib/jam_ruby/models/notification.rb b/ruby/lib/jam_ruby/models/notification.rb
index 66cbfbd46..e937b19d5 100644
--- a/ruby/lib/jam_ruby/models/notification.rb
+++ b/ruby/lib/jam_ruby/models/notification.rb
@@ -1543,7 +1543,9 @@ module JamRuby
msg_is_clipped,
notification.id,
notification.created_date)
-
+ logger.debug('-' * 30)
+ logger.debug(msg)
+ logger.debug('-' * 30)
@@mq_router.publish_to_user(receiver.id, msg)
else
diff --git a/web/app/views/api_text_messages/index.rabl b/web/app/views/api_text_messages/index.rabl
index e38e85034..cb6570229 100644
--- a/web/app/views/api_text_messages/index.rabl
+++ b/web/app/views/api_text_messages/index.rabl
@@ -2,10 +2,10 @@ collection @text_messages
attributes :id, :source_user_id, :target_user_id, :message, :created_at
-node :source_user do |msg|
- attributes :id, :name
+child :source_user => :source_user do |msg|
+ attributes :id, :name, :first_name
end
-node :target_user do |msg|
- attributes :id, :name
+child :target_user => :target_user do |msg|
+ attributes :id, :name, :first_name
end
\ No newline at end of file