From 1c331010575deb5ae0d66fe35d6e2465cd27af76 Mon Sep 17 00:00:00 2001 From: nioc Date: Tue, 14 Feb 2023 02:12:50 +0100 Subject: [PATCH 1/2] feat(chat states): Send chat state (XEP-0085) Opt-out for composing/pauses/active states Opt-in for inactive state Save user preferences to local storage And add icons to presence controller --- README.md | 2 +- src/assets/styles.scss | 4 +++ src/components/Chat.vue | 17 ++++++++++ src/components/Home.vue | 2 +- src/components/NotificationsSwitch.vue | 2 +- src/components/PresenceController.vue | 47 ++++++++++++++++++++++++-- src/components/Sendbox.vue | 36 +++++++++++++++++++- src/store/index.js | 2 ++ 8 files changed, 106 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bacf98d..2820182 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Lightweight web chat client for XMPP server. - Retrieve contacts (roster) and bookmarked rooms (XEP-0048), - Send and receive files over HTTP (XEP-0066, XEP-0363), - Handle password protected room, -- Display chat state notifications: is composing, is paused (XEP-0085), +- Display and send chat state notifications: is composing, is paused (XEP-0085), - Format messages: bold, italic, striked, link and code inline/block (XEP-0393), - Pick emoji, - Room creation and configuration, diff --git a/src/assets/styles.scss b/src/assets/styles.scss index 12ab5c3..b404966 100644 --- a/src/assets/styles.scss +++ b/src/assets/styles.scss @@ -173,6 +173,10 @@ body, user-select: all; } +.has-no-wrap { + white-space: nowrap; +} + .messages-container { overflow-y: auto; scroll-behavior: smooth; diff --git a/src/components/Chat.vue b/src/components/Chat.vue index 9b0884a..3843c12 100644 --- a/src/components/Chat.vue +++ b/src/components/Chat.vue @@ -98,6 +98,7 @@ export default { ...mapState(useStore, [ 'activeChat', 'messages', + 'isSendingInactiveChatStates', ]), hasGuestInviteLink () { return window.config.hasGuestAccess && this.isRoom @@ -112,6 +113,22 @@ export default { // handle route prop this.handleRoute() }, + async beforeUnmount () { + if (!this.userJid) { + // $xmpp is not loaded + return + } + if (!this.isSendingInactiveChatStates) { + // the user has not opted in + return + } + // notify leaving discussion + try { + await this.$xmpp.sendChatState(this.jid, this.isRoom, 'inactive') + } catch (error) { + console.warn(error.message) + } + }, methods: { // check if a jid is current user (including MUC nick) isUser (jid) { diff --git a/src/components/Home.vue b/src/components/Home.vue index 9270fdc..5969021 100644 --- a/src/components/Home.vue +++ b/src/components/Home.vue @@ -11,7 +11,7 @@ - + diff --git a/src/components/NotificationsSwitch.vue b/src/components/NotificationsSwitch.vue index afd4581..e2ec74e 100644 --- a/src/components/NotificationsSwitch.vue +++ b/src/components/NotificationsSwitch.vue @@ -1,6 +1,6 @@ diff --git a/src/components/PresenceController.vue b/src/components/PresenceController.vue index 496113f..318901e 100644 --- a/src/components/PresenceController.vue +++ b/src/components/PresenceController.vue @@ -9,9 +9,15 @@
- Set away when inactive +