1
0
mirror of synced 2024-11-24 22:16:05 +03:00

previous message may not be present when deleted

This commit is contained in:
Alexander Kulinich 2021-07-27 15:31:49 +03:00
parent ebded3077b
commit 3cf31358d9
2 changed files with 23 additions and 17 deletions

View File

@ -543,15 +543,15 @@ func (c *MgClient) AckMessage(request AckMessageRequest) (int, error) {
// 10, // 10,
// } // }
// //
// data, status, err := client.DeleteMessage(msg) // previousChatMessage, status, err := client.DeleteMessage(msg)
//
// if err != nil { // if err != nil {
// fmt.Printf("%v", err) // fmt.Printf("%v", err)
// } // }
// //
// fmt.Printf("%s\n", data.MessageID) // if previousChatMessage != nil {
func (c *MgClient) DeleteMessage(request DeleteData) (MessagesResponse, int, error) { // fmt.Printf("Previous chat message id = %d", previousChatMessage.MessageID)
var resp MessagesResponse // }
func (c *MgClient) DeleteMessage(request DeleteData) (*MessagesResponse, int, error) {
outgoing, _ := json.Marshal(&request) outgoing, _ := json.Marshal(&request)
data, status, err := c.DeleteRequest( data, status, err := c.DeleteRequest(
@ -559,18 +559,18 @@ func (c *MgClient) DeleteMessage(request DeleteData) (MessagesResponse, int, err
[]byte(outgoing), []byte(outgoing),
) )
if err != nil { 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 { 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 // GetFile implement get file url

View File

@ -490,13 +490,16 @@ func TestMgClient_MarkMessageReadAndDelete(t *testing.T) {
channelID, channelID,
} }
data, status, err := c.DeleteMessage(sndD) previousChatMessage, status, err := c.DeleteMessage(sndD)
if status != http.StatusOK { if status != http.StatusOK {
t.Errorf("%v", err) 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{ sndD = DeleteData{
Message{ Message{
@ -505,13 +508,16 @@ func TestMgClient_MarkMessageReadAndDelete(t *testing.T) {
channelID, channelID,
} }
data, status, err = c.DeleteMessage(sndD) previousChatMessage, status, err = c.DeleteMessage(sndD)
if status != http.StatusOK { if status != http.StatusOK {
t.Errorf("%v", err) 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) { func TestMgClient_DeactivateTransportChannel(t *testing.T) {