fixed notification dismiss bug

This commit is contained in:
supertiger1234 2020-02-25 19:41:59 +00:00
parent 6850bd3f24
commit 42cdb93fb6
9 changed files with 54 additions and 78 deletions

View file

@ -113,15 +113,6 @@ export default {
this.drag = true; this.drag = true;
this.$store.dispatch("setAllPopout", { show: false }); this.$store.dispatch("setAllPopout", { show: false });
}, },
dismissNotification(channelID) {
const notifications = this.$store.getters.notifications.find(function(e) {
return e.channelID === channelID;
});
if (notifications && notifications.count >= 1 && document.hasFocus()) {
this.$socket.client.client.emit("notification:dismiss", { channelID });
}
},
openServer(serverID) { openServer(serverID) {
const server = this.servers[serverID]; const server = this.servers[serverID];
const lastSelectedChannel = JSON.parse( const lastSelectedChannel = JSON.parse(
@ -134,7 +125,6 @@ export default {
channel = channels[defaultChannelID]; channel = channels[defaultChannelID];
} }
this.dismissNotification(channel.channelID);
this.$store.dispatch("servers/setSelectedServerID", serverID); this.$store.dispatch("servers/setSelectedServerID", serverID);
this.$store.dispatch("openChannel", channel); this.$store.dispatch("openChannel", channel);
}, },

View file

@ -224,6 +224,14 @@ export default {
}); });
} }
this.backToBottomLoading = false; this.backToBottomLoading = false;
},
dismissNotification(channelID) {
const notifications = this.channelNotifications;
if (notifications && notifications.count >= 1 && document.hasFocus()) {
setTimeout(() => {
this.$socket.client.emit("notification:dismiss", { channelID });
}, 500);
}
} }
}, },
@ -253,11 +261,22 @@ export default {
}, },
watch: { watch: {
selectedChannelMessages() { selectedChannelMessages(newVal) {
this.$set(this.loadMoreTop, "show", true); this.$set(this.loadMoreTop, "show", true);
this.$nextTick(function() { this.$nextTick(function() {
this.scrollDown(); this.scrollDown();
}); });
const lastMessage = newVal[newVal.length - 1];
if (!lastMessage) return;
if (!this.selectedChannelID) return;
if (lastMessage.creator.uniqueID != this.user.uniqueID) {
this.dismissNotification(this.selectedChannelID);
}
},
selectedChannelID(channelID) {
if (!channelID) return;
this.dismissNotification(channelID);
}, },
uploadQueue() { uploadQueue() {
this.$nextTick(function() { this.$nextTick(function() {
@ -276,6 +295,11 @@ export default {
} }
}, },
computed: { computed: {
channelNotifications() {
return this.$store.getters.notifications.find(e => {
return e.channelID === this.selectedChannelID;
});
},
isServer() { isServer() {
return this.$store.getters.currentTab === 2; return this.$store.getters.currentTab === 2;
}, },

View file

@ -714,9 +714,11 @@ export default {
return notification.channelID === this.$store.getters.selectedChannelID; return notification.channelID === this.$store.getters.selectedChannelID;
}); });
if (find && find.count >= 1) { if (find && find.count >= 1) {
this.$socket.client.emit("notification:dismiss", { setTimeout(() => {
channelID: this.$store.getters.selectedChannelID this.$socket.client.emit("notification:dismiss", {
}); channelID: this.$store.getters.selectedChannelID
});
}, 500);
} }
}, },
backToTopButton() { backToTopButton() {

View file

@ -686,6 +686,9 @@ $message-color: rgba(0, 0, 0, 0.3);
border-radius: 50%; border-radius: 50%;
cursor: default; cursor: default;
} }
@media (max-width: 468px) { @media (max-width: 830px) {
audio {
width: initial;
}
} }
</style> </style>

View file

@ -86,15 +86,6 @@ export default {
this.drag = true; this.drag = true;
this.$store.dispatch("setAllPopout", { show: false }); this.$store.dispatch("setAllPopout", { show: false });
}, },
dismissNotification(channelID) {
const notifications = this.$store.getters.notifications.find(function(e) {
return e.channelID === channelID;
});
if (notifications && notifications.count >= 1 && document.hasFocus()) {
this.$socket.client.emit("notification:dismiss", { channelID });
}
},
openServer(serverID) { openServer(serverID) {
this.switchTab(2); this.switchTab(2);
const server = this.servers[serverID]; const server = this.servers[serverID];
@ -107,8 +98,6 @@ export default {
if (!channel) { if (!channel) {
channel = channels[defaultChannelID]; channel = channels[defaultChannelID];
} }
this.dismissNotification(channel.channelID);
this.$store.dispatch("servers/setSelectedServerID", serverID); this.$store.dispatch("servers/setSelectedServerID", serverID);
this.$store.dispatch("openChannel", channel); this.$store.dispatch("openChannel", channel);
this.$store.dispatch("selectedChannelID", channel.channelID); this.$store.dispatch("selectedChannelID", channel.channelID);

View file

@ -58,17 +58,6 @@ export default {
"selectedChannels", "selectedChannels",
JSON.stringify(selectedChannels) JSON.stringify(selectedChannels)
); );
const notificationExists = this.$store.getters.notifications.find(
n => n.channelID === channel.channelID
);
if (notificationExists && document.hasFocus()) {
this.$socket.client.emit("notification:dismiss", {
channelID: channel.channelID
});
}
bus.$emit("closeLeftMenu"); bus.$emit("closeLeftMenu");
this.$store.dispatch("openChannel", channel); this.$store.dispatch("openChannel", channel);
this.$store.dispatch("selectedChannelID", channel.channelID); this.$store.dispatch("selectedChannelID", channel.channelID);

View file

@ -64,12 +64,20 @@ export default {
return e.sender.uniqueID === recipient.uniqueID; return e.sender.uniqueID === recipient.uniqueID;
}); });
if ( let isSelectedUser = false;
!notifications || if (this.friend.recipient) {
(this.friend.channelID === this.$store.getters.selectedChannelID && isSelectedUser =
document.hasFocus()) this.friend.recipient.uniqueID ===
) this.$store.getters.selectedUserUniqueID;
return; } else {
isSelectedUser =
this.friend.recipients[0].uniqueID ===
this.$store.getters.selectedUserUniqueID;
}
if (!notifications) return;
if (isSelectedUser && document.hasFocus()) return;
return notifications.count; return notifications.count;
}, },
userAvatar() { userAvatar() {
@ -112,17 +120,6 @@ export default {
) )
return; return;
bus.$emit("closeLeftMenu"); bus.$emit("closeLeftMenu");
// dismiss notification if exists
// TODO move this into openchat or something :/
if (
this.notifications &&
this.notifications >= 1 &&
document.hasFocus()
) {
this.$socket.client.emit("notification:dismiss", {
channelID: this.friend.channelID
});
}
this.$store.dispatch("openChat", { this.$store.dispatch("openChat", {
uniqueID: this.recipient.uniqueID, uniqueID: this.recipient.uniqueID,
channelID: this.friend.channelID, channelID: this.friend.channelID,
@ -243,8 +240,6 @@ export default {
transition: 0.3s; transition: 0.3s;
} }
.status-name { .status-name {
opacity: 0; opacity: 0;
font-size: 13px; font-size: 13px;
@ -265,5 +260,4 @@ export default {
.close-button:hover { .close-button:hover {
color: white; color: white;
} }
</style> </style>

View file

@ -198,16 +198,12 @@ const actions = {
}); });
} }
const currentTab = context.rootGetters.currentTab; const currentTab = context.rootGetters.currentTab;
if ( const selectedChannelID = context.rootState.channelModule.selectedChannelID;
context.rootState.channelModule.selectedChannelID ==
data.message.channelID && const isSelectedChannel = selectedChannelID == data.message.channelID;
document.hasFocus() && const isCurrentTabDMOrSrvrs = currentTab === 1 || currentTab === 2;
(currentTab === 1 || currentTab === 2)
) { if (!isSelectedChannel || !document.hasFocus() || !isCurrentTabDMOrSrvrs) {
this._vm.$socket.client.emit("notification:dismiss", {
channelID: data.message.channelID
});
} else {
// send notification if other users message the recipient // send notification if other users message the recipient
if (data.message.creator.uniqueID === context.getters.user.uniqueID) if (data.message.creator.uniqueID === context.getters.user.uniqueID)
return; return;

View file

@ -88,15 +88,6 @@ export default {
}; };
}, },
methods: { methods: {
dismissNotification(channelID) {
const notifications = this.$store.getters.notifications.find(function(e) {
return e.channelID === channelID;
});
if (notifications && notifications.count >= 1 && document.hasFocus()) {
this.$socket.client.emit("notification:dismiss", { channelID });
}
},
switchChannel(isServer) { switchChannel(isServer) {
const serverChannelID = this.$store.state.channelModule.serverChannelID; const serverChannelID = this.$store.state.channelModule.serverChannelID;
const DMChannelID = this.$store.state.channelModule.DMChannelID; const DMChannelID = this.$store.state.channelModule.DMChannelID;
@ -107,7 +98,6 @@ export default {
serverChannelID serverChannelID
]; ];
this.$store.dispatch("setChannelName", channel ? channel.name : ""); this.$store.dispatch("setChannelName", channel ? channel.name : "");
this.dismissNotification(serverChannelID);
} else { } else {
const channel = this.$store.state.channelModule.channels[DMChannelID]; const channel = this.$store.state.channelModule.channels[DMChannelID];
this.$store.dispatch( this.$store.dispatch(
@ -115,7 +105,6 @@ export default {
channel ? channel.recipients[0].username : "" channel ? channel.recipients[0].username : ""
); );
this.$store.dispatch("selectedChannelID", DMChannelID); this.$store.dispatch("selectedChannelID", DMChannelID);
this.dismissNotification(DMChannelID);
} }
}, },
switchTab(index) { switchTab(index) {