@@ -4,9 +4,7 @@ import config from '../config/config';
44import {
55 calculateWidthAndHeight ,
66 getCurrentChatUser ,
7- getThumbImage ,
87 getUserIdFromJid ,
9- getVideoThumbImage ,
108 handleConversationScollToBottom ,
119 handleUploadNextImage ,
1210 isLocalUser ,
@@ -96,47 +94,41 @@ export const fetchContactsFromSDK = async (_searchText, _pageNumber, _limit) =>
9694} ;
9795
9896export const fetchMessagesFromSDK = async ( { fromUserJId, forceGetFromSDK = false , pageReset = false } ) => {
99- try {
100- const userId = getUserIdFromJid ( fromUserJId ) ;
101- const messsageList = getChatMessages ( userId ) || [ ] ;
102- if ( messsageList . length && ! forceGetFromSDK ) {
103- return ;
104- }
105- if ( pageReset ) {
106- delete chatPage [ userId ] ;
107- }
108- const lastMessageId = messsageList [ messsageList . length - 1 ] ?. msgId || '' ;
109- console . log ( 'lastMessageId ==>' , messsageList . length , messsageList . length - 1 , lastMessageId ) ;
110- if ( lastMessageId . includes ( 'groupCreated' ) ) {
111- hasNextChatPage [ userId ] = false ;
112- return ;
113- }
114- const page = chatPage [ userId ] || 1 ;
115-
116- const {
117- statusCode,
118- userJid,
119- data = [ ] ,
120- message,
121- } = await SDK . getChatMessages ( {
122- toJid : fromUserJId ,
123- lastMessageId,
124- size : config . chatMessagesSizePerPage ,
125- source : 'db' ,
126- } ) ;
127- if ( statusCode === 200 ) {
128- let hasEqualDataFetched = data . length === config . chatMessagesSizePerPage ;
129- if ( data . length && hasEqualDataFetched ) {
130- chatPage [ userId ] = page + 1 ;
131- }
132- hasNextChatPage [ userId ] = hasEqualDataFetched ;
133- store . dispatch ( setChatMessages ( { userJid, data, forceUpdate : page === 1 } ) ) ;
134- }
135- if ( statusCode !== 200 ) {
136- showToast ( message ) ;
137- }
138- return data ;
139- } catch ( error ) { }
97+ const userId = getUserIdFromJid ( fromUserJId ) ;
98+ const messsageList = getChatMessages ( userId ) || [ ] ;
99+ if ( messsageList . length && ! forceGetFromSDK ) {
100+ return ;
101+ }
102+ if ( pageReset ) {
103+ delete chatPage [ userId ] ;
104+ }
105+ const lastMessageId = messsageList [ messsageList . length - 1 ] ?. msgId || '' ;
106+ console . log ( 'lastMessageId ==>' , messsageList . length , messsageList . length - 1 , lastMessageId ) ;
107+ if ( lastMessageId . includes ( 'groupCreated' ) ) {
108+ hasNextChatPage [ userId ] = false ;
109+ return ;
110+ }
111+
112+ const {
113+ statusCode,
114+ userJid,
115+ data = [ ] ,
116+ message,
117+ } = await SDK . getChatMessages ( {
118+ toJid : fromUserJId ,
119+ lastMessageId,
120+ size : config . chatMessagesSizePerPage ,
121+ } ) ;
122+ if ( statusCode === 200 ) {
123+ let hasEqualDataFetched = data . length === config . chatMessagesSizePerPage ;
124+
125+ hasNextChatPage [ userId ] = hasEqualDataFetched ;
126+ store . dispatch ( setChatMessages ( { userJid, data } ) ) ;
127+ }
128+ if ( statusCode !== 200 ) {
129+ showToast ( message ) ;
130+ }
131+ return data ;
140132} ;
141133
142134const sendMediaMessage = async ( messageType , files , chatType , toUserJid , replyTo ) => {
@@ -531,8 +523,10 @@ export const getUserSettings = async (iq = false) => {
531523
532524export const updateNotificationSettings = async ( ) => {
533525 let {
526+ data,
534527 data : { archive = 0 , muteNotification = false , notificationSound = true , notificationVibrate = false } ,
535528 } = await SDK . getUserSettings ( ) ;
529+ console . log ( 'data ==>' , JSON . stringify ( data , null , 2 ) ) ;
536530 store . dispatch ( toggleArchiveSetting ( Number ( archive ) ) ) ;
537531 store . dispatch ( updateNotificationSetting ( { muteNotification, notificationSound, notificationVibrate } ) ) ;
538532} ;
0 commit comments