Skip to content

fix(client): read() chat target, dead unsend() guard, i64 fetch cursor - #222

Open
nezumi0627 wants to merge 1 commit into
evex-dev:mainfrom
nezumi0627:fix/message-read-and-unsend-guard
Open

fix(client): read() chat target, dead unsend() guard, i64 fetch cursor#222
nezumi0627 wants to merge 1 commit into
evex-dev:mainfrom
nezumi0627:fix/message-read-and-unsend-guard

Conversation

@nezumi0627

Copy link
Copy Markdown
Contributor

Summary

Three client-facing bugs, each verified with a failing call before the fix:

1. TalkMessage.read() marked the wrong chat as read for received group messages

chatMid: this.isMyMessage ? this.to.id : this.from.id

For a group/room message received from someone else, from.id is the sender's USER mid, but sendChatChecked's chatMid must be the chat id — so .read() targeted a (usually non-existent) 1:1 chat instead of the group. The neighboring reply()/send() already branch on toType, which makes this look like an oversight.

Now: GROUP/ROOM → always to.id; USER chats keep the previous behavior (counterpart mid).

2. SquareMessage.unsend() / SquareThreadMessage.unsend() ownership guard was dead code

isMyMessage is an async method on square messages, but both unsend() implementations tested it as a property:

if (!this.isMyMessage) { throw new TypeError(...) }

this.isMyMessage is a function object — always truthy — so the guard never fired and unsend() proceeded for anyone's message. Now awaited properly. (TalkMessage.unsend() is unaffected; its isMyMessage is a getter.)

3. Message-fetcher pagination cursor lost i64 precision + crashed on empty pages

createMessageFetcher().fetch() did:

  • parseInt(lastMessage.id) — LINE message ids are ~19-digit values beyond Number.MAX_SAFE_INTEGER, so the next page's cursor was silently rounded, skipping/duplicating messages. Now BigInt(lastMessage.id) (the struct writer already supports bigint I64).
  • messages.at(-1)! — threw TypeError when a fetch returned an empty array (end of history). Empty pages now return [] with the cursor left unchanged.

Testing

New tests: talk.test.ts (group read targets chat mid; 1:1 unchanged), square.test.ts (unsend of another member's message throws TypeError without calling unsendMessage), fetcher.test.ts (2^53+1 cursor round-trips losslessly; empty page returns [] without throwing).

Full suite: deno test --allow-all — 218 passed, 0 failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant