status-im / status-protocol-go

Status Protocol implementation in Go
Mozilla Public License 2.0
0 stars 1 forks source link

Join does not call SaveChat #79

Open jakubgs opened 4 years ago

jakubgs commented 4 years ago

While trying to implement MatterBridge with a newer version of this library I encountered the error:

received a public message from non-existing chat"

Which comes from: https://github.com/status-im/status-protocol-go/blob/4492eb97793f7edabe9d0072b6c85cdde08fee49/messenger.go#L814 Which fails because chat is not in known chats: https://github.com/status-im/status-protocol-go/blob/4492eb97793f7edabe9d0072b6c85cdde08fee49/messenger.go#L787-L788 Because the Join() method: https://github.com/status-im/status-protocol-go/blob/4492eb97793f7edabe9d0072b6c85cdde08fee49/messenger.go#L451-L458 Does not call the SaveChat() method: https://github.com/status-im/status-protocol-go/blob/4492eb97793f7edabe9d0072b6c85cdde08fee49/messenger.go#L469-L471

jakubgs commented 4 years ago

I'm calling the SaveChat() method myself but I'm still getting the error:

ERROR   status-protocol-go@v0.1.5-0.20190828083140-4492eb97793f7edabe9d0072b6c85cdde08fee49/messenger.go:797
    failed to match a chat to a message
    {"error": "received a public message from non-existing chat", "errorVerbose": "received a public message from non-existing chat"}
github.com/status-im/status-protocol-go.(*postProcessor).matchMessages
    /home/sochan/go/pkg/mod/github.com/status-im/status-protocol-go@v0.1.5-0.20190828083140-4492eb97793f7edabe9d0072b6c85cdde08fee49/messenger.go:797
github.com/status-im/status-protocol-go.(*postProcessor).Run
    /home/sochan/go/pkg/mod/github.com/status-im/status-protocol-go@v0.1.5-0.20190828083140-4492eb97793f7edabe9d0072b6c85cdde08fee49/messenger.go:770
github.com/status-im/status-protocol-go.(*Messenger).RetrieveAll
    /home/sochan/go/pkg/mod/github.com/status-im/status-protocol-go@v0.1.5-0.20190828083140-4492eb97793f7edabe9d0072b6c85cdde08fee49/messenger.go:587
github.com/42wim/matterbridge/bridge/status.(*Bstatus).retrieveLatestMessages
    /home/sochan/work/matterbridge/bridge/status/status.go:191
github.com/42wim/matterbridge/bridge/status.(*Bstatus).fetchMessagesLoop
    /home/sochan/work/matterbridge/bridge/status/status.go:174

Not sure what that's about, might be a bug. Failure seems to happen here: https://github.com/status-im/status-protocol-go/blob/4492eb97793f7edabe9d0072b6c85cdde08fee49/messenger.go#L795-L799

jakubgs commented 4 years ago

Looks like the issue was due to me not setting the ID field of the Chat struct: https://github.com/status-im/status-protocol-go/blob/4492eb97793f7edabe9d0072b6c85cdde08fee49/chat.go#L23-L28 Looks like the best way to make a Chat object is to use the helper method: https://github.com/status-im/status-protocol-go/blob/4492eb97793f7edabe9d0072b6c85cdde08fee49/chat.go#L111-L118