如果用户看到消息,我该如何倾听?
我有代码:
watch: {
message() {
Echo.private('chat')
.whisper('typing', {
name: this.message
});
}
},
methods: {
send(){
if(this.message.length != 0 && this.message.length <= 4000) {
this.chat.message.push(this.message);
this.chat.user.push('you');
this.chat.time.push(this.getTime());
axios.post('/sendMessage', {
message: this.message,
//lastName: 'Flintstone'
})
.then(response => {
console.log(response);
this.message = '';
})
.catch(error => {
console.log(error);
});
}
},
getTime() {
let time = new Date();
return time.getHours() + ':' + time.getMinutes();
}
},
mounted() {
Echo.private('chat')
.listen('ChatEvent', (e) => {
this.chat.message.push(e.message);
this.chat.user.push(e.user);
this.chat.time.push(this.getTime());
console.log(e);
})
.listenForWhisper('typing', (e) => {
if(e.name != '')
this.typing = 'typing..';
else
this.typing = null;
});
}
&#13;
我更新了:
methods: {
seenMessage() {
axios.post('/setMessagesSeen/' + this.convId)
.then( response => { this.chat.seen = ''; })
.catch( response => { console.log(response) } )
},
send(){
if(this.message.length != 0 && this.message.length <= 4000) {
this.chat.message.push(this.message);
this.chat.user.push(this.user);
this.chat.time.push(this.getTime());
this.chat.seen.push('unread');
axios.post('/sendMessage/' + this.convId, {
message: this.message,
})
.then(response => {
console.log(response);
this.message = '';
})
.catch(error => {
console.log(error);
});
}
},
getTime() {
let time = new Date();
return time.getHours() + ':' + time.getMinutes();
}
},
&#13;
我如何发送课程&#34;未读&#34; to element div其他用户?我可以在当前用户上粘贴类,我只为我获取元素聊天的颜色,但是当我看到消息时,我如何能够为我和其他用户隐藏元素?
我可以看,如果输入信息。但是,如果用户看到消息我怎么能听?如果消息被发送给看到的消息或者如何发送消息,我需要采取行动吗?
答案 0 :(得分:1)
要检测用户是否点击了textarea,请尝试以下操作:
首先,在Vuejs实例中创建一个方法hasSeen。
..., methods : { send : () => {...}, getTime: () => {...}, hasSeen: () => { axios.put('your-api-or-backend-domains/setHasSeenMessage') .then( response => { //Okay }) .catch(response => { console.log(response)}) } }
CREATE DYNAMIC SET [Wide World Importers DW].[Selected Months] as (
[Delivery Date].[Calendar].[Calendar Month Label]
) ;
CREATE MEMBER [Wide World Importers DW].[Measures].[Months Count] AS (
count( [Selected Months] )
)
CREATE MEMBER [Wide World Importers DW].[Measures].[SumOfMonths] AS (
sum(Existing [Months Count] )
)
SELECT
{[Measures].[Measures].[Sales Amount With Tax]
,[Measures].[SumOfMonths]
} on 0
from (
SELECT (
{[Delivery Date].[Calendar].[Calendar Month Label].&[CY2016-Dec]
})
ON COLUMNS FROM [Wide World Importers DW]
)
答案 1 :(得分:0)
如果你想做 facebook 之类的事情,我在这里找到了一个逻辑:https://www.quora.com/How-does-Facebook-know-if-a-chat-message-is-seen
当您使用与文本字段关联的焦点事件侦听器单击要键入的字段时,它会发出“看到”通知(ajaxRequest)。
案例2:Facebook标签不在焦点
如果您已将文本框置于焦点但位于不同的选项卡上,则在切换到facebook选项卡时会发送通知(AjaxRequest)。 JavaScript窗口焦点和窗口模糊事件可用于检测选项卡是否处于焦点。这些以及文本框的onfocus事件可用于发送通知(AjaxRequest)。
所以你可以创建一个可以实现这个逻辑的javascript脚本!
我希望它能帮到你!