import {
  actionGetMessagesSuccess,
  actionGetMessagesReject
} from '../action';
import { asyncFindPinnedMessages } from '../../pinnedMessages/operations'
import { getMessagesById } from '../../../api-data';
import { IMessagesState } from '../../../typescript/redux/messages/interfaces'


const asyncGetMessagesById= (id:string,cb:any) => async (dispatch:any) => {
  try {
    const data = await getMessagesById<IMessagesState>(id)
    if (data) {
      dispatch(actionGetMessagesSuccess(data))
      dispatch(asyncFindPinnedMessages(data.messages))
    }
    cb&&cb()
  } catch (e) {
    dispatch(actionGetMessagesReject())
    
  } 
};


export { asyncGetMessagesById };




