Skip to content

Commit

Permalink
fix: Fixed status/stores screen after send
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Jul 30, 2022
1 parent a7eef5b commit 3fb61bd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
38 changes: 38 additions & 0 deletions src/status/functions/postSendStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*!
* Copyright 2021 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { SendMessageReturn } from '../../chat';
import { MsgStore, StatusV3Store } from '../../whatsapp';

export function postSendStatus(result: SendMessageReturn): void {
result.sendMsgResult.then(() => {
const msg = MsgStore.get(result.id);

if (!msg) {
return;
}

// Trigger screen update
StatusV3Store.handleUpdate(msg.attributes, null, false);

const myStatus = StatusV3Store.getMyStatus();

if (myStatus) {
// Fix models index
myStatus.msgs.add(msg);
}
});
}
6 changes: 5 additions & 1 deletion src/status/functions/sendImageStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { sendFileMessage } from '../../chat';
import { MsgKey, UserPrefs } from '../../whatsapp';
import { randomHex } from '../../whatsapp/functions';
import { defaultSendStatusOptions } from '..';
import { postSendStatus } from './postSendStatus';
import { SendStatusOptions } from './sendRawStatus';

export type ImageStatusOptions = SendStatusOptions;
Expand Down Expand Up @@ -48,9 +49,12 @@ export async function sendImageStatus(
...options,
};

return sendFileMessage('status@broadcast', content, {
const result = await sendFileMessage('status@broadcast', content, {
...options,
createChat: true,
type: 'image',
});
postSendStatus(result);

return result;
}
6 changes: 2 additions & 4 deletions src/status/functions/sendRawStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { assertWid } from '../../assert';
import * as Chat from '../../chat';
import * as webpack from '../../webpack';
import {
ChatStore,
ContactStore,
MsgKey,
ParticipantModel,
Expand All @@ -35,6 +34,7 @@ import {
updateParticipants,
} from '../../whatsapp/functions';
import { defaultSendStatusOptions } from '..';
import { postSendStatus } from './postSendStatus';

export interface SendStatusOptions {
waitForAck?: boolean;
Expand Down Expand Up @@ -65,9 +65,7 @@ export async function sendRawStatus(
createChat: true,
});

result.sendMsgResult.then(() => {
ChatStore.resyncMessages();
});
postSendStatus(result);

return result;
}
Expand Down
7 changes: 6 additions & 1 deletion src/status/functions/sendVideoStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { sendFileMessage } from '../../chat';
import { MsgKey, UserPrefs } from '../../whatsapp';
import { randomHex } from '../../whatsapp/functions';
import { defaultSendStatusOptions } from '..';
import { postSendStatus } from './postSendStatus';
import { SendStatusOptions } from './sendRawStatus';

export type VideoStatusOptions = SendStatusOptions;
Expand Down Expand Up @@ -48,9 +49,13 @@ export async function sendVideoStatus(
...options,
};

return sendFileMessage('status@broadcast', content, {
const result = await sendFileMessage('status@broadcast', content, {
...options,
createChat: true,
type: 'video',
});

postSendStatus(result);

return result;
}
4 changes: 2 additions & 2 deletions src/whatsapp/collections/StatusV3Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export declare class StatusV3Collection extends BaseCollection<StatusV3Model> {
sync(e?: any): any;
logMetrics(e?: any): any;
hasSynced(): boolean;
handleUpdate(e?: any, t?: any, r?: any): any;
handleUpdate(rawMsg?: any, checksum?: any, isMsgUpdate?: boolean): any;
updateChecksum(e?: any): any;
addStatusMessages(e?: any, t?: any): any;
getUnexpired(e?: any): any;
getMyStatus(): any;
getMyStatus(): StatusV3Model;
static comparator(): any;
}
exportModule(
Expand Down

0 comments on commit 3fb61bd

Please sign in to comment.