gotd / td

Telegram client, in Go. (MTProto API)
MIT License
1.49k stars 134 forks source link

FromID same for both parties in one to one chat #288

Open spacemolly opened 3 years ago

spacemolly commented 3 years ago

What version of gotd are you using?

$ go list -m github.com/gotd/td
github.com/gotd/td v0.33.3

Does this issue reproduce with the latest release?

Yes

What did you do?

Not 100% sure this is a bug but it's at least unexpected and inconsistent so leaning towards it being one. So sorry if i'm wrong!

I'm receiving message in a one to one chat via OnNewMessage dispatcher. When I send the first message the FromID is the user id of the first user (which is expected), but the response Message and all future messages from the other user, has the same FromID as the first user. So it looks like messages all come from the same user, the first one.

Here are two (abbreviated) json-encoded messages:

First:

{
 "Flags": 0,
 "Out": false,
 "Mentioned": false,
 "MediaUnread": false,
 "Silent": false,
 "Post": false,
 "FromScheduled": false,
 "Legacy": false,
 "EditHide": false,
 "Pinned": false,
 "ID": 3402,
 "FromID": {
  "UserID": 56132410
 },
 "PeerID": {
  "UserID": 56132410
 },
 "Date": 1617977512,
 "Message": "Hello",
}

Second:

 {
 "Flags": 0,
 "Out": true,
 "Mentioned": false,
 "MediaUnread": false,
 "Silent": false,
 "Post": false,
 "FromScheduled": false,
 "Legacy": false,
 "EditHide": false,
 "Pinned": false,
 "ID": 3407,
 "FromID": {
  "UserID": 56132410
 },
 "PeerID": {
  "UserID": 56132410
 },
 "Date": 1618004712,
 "Message": "Hi again",
}

What did you expect to see?

I expected the FromID to be the user id of the user who actually sent the message.

What did you see instead?

As you see in the above examples, both the from user id and the peer user id is the same in both messages, the id of the user who initiated the chat.

What Go version and environment are you using?

$ go version
go version go1.16 darwin/amd64

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Library/Caches/go-build"
GOENV="/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/j1/hgqrbz2n1xsgz6_2c0slq9nh0000gn/T/go-build3091972184=/tmp/go-build -gno-record-gcc-switches -fno-common"

ernado commented 3 years ago

Please try v0.34.0

spacemolly commented 3 years ago

Tested with v0.34.0, now FromID is simply Nil. PeerID is the same as before and that probably makes sense.

Is there a way to access current client UserID and use this when Out is true?

 {
 "Flags": 0,
 "Out": true,
 "Mentioned": false,
 "MediaUnread": false,
 "Silent": false,
 "Post": false,
 "FromScheduled": false,
 "Legacy": false,
 "EditHide": false,
 "Pinned": false,
 "ID": 3408,
 "FromID": null,
 "PeerID": {
  "UserID": 56132410
 },
 "Date": 1618143621,
 "Message": "Testing"
}
ernado commented 3 years ago

For now you can use Client.Self method to access current UserID and cache it.

Initially @xjem proposed to do it implicitly (cache it on first call and set FromID), but currently there is no consensus in gotd development team.

spacemolly commented 3 years ago

Thanks! Ok, that's an alright work around