Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

feat(message): add UI component to mark messages as read (#337)

Aldino Kemal4668f8c965b5
diff --git a/src/views/components/MessageRead.js b/src/views/components/MessageRead.js
new file mode 100644
index 00000000..bf0d9672
--- /dev/null
+++ b/src/views/components/MessageRead.js
@@ -0,0 +1,114 @@
+import FormRecipient from "./generic/FormRecipient.js";
+
+export default {
+ name: 'ReadMessage',
+ components: {
+ FormRecipient
+ },
+ data() {
+ return {
+ type: window.TYPEUSER,
+ phone: '',
+ message_id: '',
+ loading: false,
+ }
+ },
+ computed: {
+ phone_id() {
+ return this.phone + this.type;
+ }
+ },
+ methods: {
+ openModal() {
+ $('#modalMessageRead').modal({
+ onApprove: function () {
+ return false;
+ }
+ }).modal('show');
+ },
+ isValidForm() {
+ if (this.type !== window.TYPESTATUS && !this.phone.trim()) {
+ return false;
+ }
+
+ if (!this.message_id.trim()) {
+ return false;
+ }
+
+ return true;
+ },
+ async handleSubmit() {
+ if (!this.isValidForm() || this.loading) {
+ return;
+ }
+
+ try {
+ let response = await this.submitApi()
+ showSuccessInfo(response)
+ $('#modalMessageRead').modal('hide');
+ } catch (err) {
+ showErrorInfo(err)
+ }
+ },
+ async submitApi() {
+ this.loading = true;
+ try {
+ const payload = {phone: this.phone_id}
+
+ let response = await window.http.post(`/message/${this.message_id}/read`, payload)
+ this.handleReset();
+ return response.data.message;
+ } catch (error) {
+ if (error.response) {
+ throw new Error(error.response.data.message);
+ }
+ throw new Error(error.message);
+ } finally {
+ this.loading = false;
+ }
+ },
+ handleReset() {
+ this.type = window.TYPEUSER;
+ this.phone = '';
+ this.message_id = '';
+ this.loading = false;
+ },
+ },
+ template: `
+ <div class="red card" @click="openModal()" style="cursor: pointer">
+ <div class="content">
+ <a class="ui red right ribbon label">Message</a>
+ <div class="header">Mark as Read</div>
+ <div class="description">
+ Mark a message as read in a chat
+ </div>
+ </div>
+ </div>
+
+ <!-- Modal MessageRead -->
+ <div class="ui small modal" id="modalMessageRead">
+ <i class="close icon"></i>
+ <div class="header">
+ Mark Message as Read
+ </div>
+ <div class="content">
+ <form class="ui form">
+ <FormRecipient v-model:type="type" v-model:phone="phone"/>
+
+ <div class="field">
+ <label>Message ID</label>
+ <input v-model="message_id" type="text" placeholder="Please enter the message id to mark as read"
+ aria-label="message id">
+ </div>
+ </form>
+ </div>
+ <div class="actions">
+ <button class="ui approve positive right labeled icon button" :class="{'loading': this.loading, 'disabled': !isValidForm() || loading}"
+ @click.prevent="handleSubmit">
+ Mark as Read
+ <i class="check icon"></i>
+ </button>
+ </div>
+ </div>
+ `
+}
\ No newline at end of file
diff --git a/src/views/index.html b/src/views/index.html
index 5b52bcc7..fd8e2f14 100644
--- a/src/views/index.html
+++ b/src/views/index.html
@@ -93,6 +93,7 @@
<message-revoke></message-revoke>
<message-react></message-react>
<message-update></message-update>
+ <message-read></message-read>
</div>
<div class="ui horizontal divider">
@@ -187,6 +188,7 @@
import MessageUpdate from "./components/MessageUpdate.js";
import MessageReact from "./components/MessageReact.js";
import MessageRevoke from "./components/MessageRevoke.js";
+ import MessageRead from "./components/MessageRead.js";
import GroupList from "./components/GroupList.js";
import GroupCreate from "./components/GroupCreate.js";
import GroupJoinWithLink from "./components/GroupJoinWithLink.js";
@@ -240,7 +242,7 @@
components: {
AppLogin, AppLoginWithCode, AppLogout, AppReconnect,
SendMessage, SendImage, SendFile, SendVideo, SendLink, SendContact, SendLocation, SendAudio, SendPoll, SendPresence, SendChatPresence,
- MessageDelete, MessageUpdate, MessageReact, MessageRevoke,
+ MessageDelete, MessageUpdate, MessageReact, MessageRevoke, MessageRead,
GroupList, GroupCreate, GroupJoinWithLink, GroupAddParticipants, GroupSetPhoto, GroupSetName, GroupSetLocked, GroupSetAnnounce, GroupSetTopic,
NewsletterList,
AccountAvatar, AccountUserInfo, AccountPrivacy, AccountChangeAvatar, AccountContact, AccountChangePushName, AccountUserCheck, AccountBusinessProfile