Skip to content

Commit

Permalink
simplify UI message filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Inveracity committed Jul 22, 2023
1 parent 07929fa commit fb5639a
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions frontend/src/lib/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,14 @@ const filtered = (msg: ChatMessage, lastTs: string): boolean => {
return true;
}

// Do not write messages with timestamp 0 to the UI
if (msg.ts === "0") {
return true;
}

if (msg.userId === "server") {
return true;
}

if (msg.channelId === "system") {
return filter_system_messages(msg);
}

// Do not write messages with timestamp 0 to the UI
// Deduplicate messages with the same timestamp
if (msg.ts === lastTs) {
// Ignore all other server messages
if (msg.ts === "0" || msg.ts === lastTs || msg.userId === "server") {
return true;
}

Expand All @@ -151,13 +144,15 @@ const timestampToDate = (timestamp: string): string => {
}

const filter_system_messages = (msg: ChatMessage): boolean => {
console.log(msg)
// Tell UI to show new channel when another user adds one
if (msg.text.startsWith("channel_add") && msg.userId !== pb.authStore.model?.name) {
const channel_name = msg.text.split(" ")[1]
channels.add(channel_name);
}

if (msg.text.startsWith("connected")) {
console.log(msg);
const user: User = { name: msg.userId, presence: true }
users.upd(user);
}
Expand Down

0 comments on commit fb5639a

Please sign in to comment.