From 3cf31358d9797212edf77ab08e2614f3f0545125 Mon Sep 17 00:00:00 2001 From: Alexander Kulinich Date: Tue, 27 Jul 2021 15:31:49 +0300 Subject: [PATCH] previous message may not be present when deleted --- v1/client.go | 26 +++++++++++++------------- v1/client_test.go | 14 ++++++++++---- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/v1/client.go b/v1/client.go index 5d8b945..4c478f3 100644 --- a/v1/client.go +++ b/v1/client.go @@ -543,15 +543,15 @@ func (c *MgClient) AckMessage(request AckMessageRequest) (int, error) { // 10, // } // -// data, status, err := client.DeleteMessage(msg) -// +// previousChatMessage, status, err := client.DeleteMessage(msg) // if err != nil { // fmt.Printf("%v", err) // } // -// fmt.Printf("%s\n", data.MessageID) -func (c *MgClient) DeleteMessage(request DeleteData) (MessagesResponse, int, error) { - var resp MessagesResponse +// if previousChatMessage != nil { +// fmt.Printf("Previous chat message id = %d", previousChatMessage.MessageID) +// } +func (c *MgClient) DeleteMessage(request DeleteData) (*MessagesResponse, int, error) { outgoing, _ := json.Marshal(&request) data, status, err := c.DeleteRequest( @@ -559,18 +559,18 @@ func (c *MgClient) DeleteMessage(request DeleteData) (MessagesResponse, int, err []byte(outgoing), ) if err != nil { - return resp, status, err + return nil, status, err } - - if e := json.Unmarshal(data, &resp); e != nil { - return resp, status, e - } - if status != http.StatusOK { - return resp, status, c.Error(data) + return nil, status, c.Error(data) } - return resp, status, err + var previousChatMessage *MessagesResponse + if e := json.Unmarshal(data, &previousChatMessage); e != nil { + return nil, status, e + } + + return previousChatMessage, status, nil } // GetFile implement get file url diff --git a/v1/client_test.go b/v1/client_test.go index 54440ed..2b4f792 100644 --- a/v1/client_test.go +++ b/v1/client_test.go @@ -490,13 +490,16 @@ func TestMgClient_MarkMessageReadAndDelete(t *testing.T) { channelID, } - data, status, err := c.DeleteMessage(sndD) + previousChatMessage, status, err := c.DeleteMessage(sndD) if status != http.StatusOK { t.Errorf("%v", err) } - t.Logf("Message %v deleted", data.MessageID) + t.Logf("Message %v deleted", ext) + if previousChatMessage != nil { + t.Logf("Previous chat message %+v", *previousChatMessage) + } sndD = DeleteData{ Message{ @@ -505,13 +508,16 @@ func TestMgClient_MarkMessageReadAndDelete(t *testing.T) { channelID, } - data, status, err = c.DeleteMessage(sndD) + previousChatMessage, status, err = c.DeleteMessage(sndD) if status != http.StatusOK { t.Errorf("%v", err) } - t.Logf("Message %v deleted", data.MessageID) + t.Logf("Message %v deleted", ext+"file") + if previousChatMessage != nil { + t.Logf("Previous chat message %+v", *previousChatMessage) + } } func TestMgClient_DeactivateTransportChannel(t *testing.T) {