Skip to content

Commit

Permalink
feature: add delete support
Browse files Browse the repository at this point in the history
Signed-off-by: Gary Kim <[email protected]>
  • Loading branch information
gary-kim committed Feb 28, 2021
1 parent eb84ad3 commit e925d94
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ocs/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const (
// MessageCommand is a Nextcloud Talk message that is a command
MessageCommand MessageType = "command"

// MessageDelete is a Nextcloud Talk message indicating a message that was deleted
MessageDelete MessageType = "comment_deleted"

// ActorUser is a Nextcloud Talk message sent by a user
ActorUser ActorType = "users"

Expand All @@ -52,6 +55,8 @@ type TalkRoomMessageData struct {
SystemMessage string `json:"systemMessage"`
Timestamp int `json:"timestamp"`
MessageType MessageType `json:"messageType"`
Deleted bool `json:"deleted"`
Parent []TalkRoomMessageData `json:"parent"`
MessageParameters map[string]RichObjectString `json:"-"`
}

Expand Down
18 changes: 18 additions & 0 deletions room/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ func (t *TalkRoom) SendMessage(msg string) (*ocs.TalkRoomMessageData, error) {
return &msgInfo.OCS.TalkRoomMessage, err
}

func (t *TalkRoom) DeleteMessage(messageId string) (*ocs.TalkRoomMessageData, error) {
url := t.User.NextcloudURL + constants.BaseEndpoint + "/chat/" + t.Token + "/" + messageId

client := t.User.RequestClient(request.Client{
URL: url,
Method: "DELETE",
})
res, err := client.Do()
if err != nil {
return nil, err
}
msgInfo, err := ocs.TalkRoomMessageDataUnmarshal(&res.Data)
if err != nil {
return nil, err
}
return &msgInfo.OCS.TalkRoomMessage[0], nil
}

// ReceiveMessages starts watching for new messages
func (t *TalkRoom) ReceiveMessages(ctx context.Context) (chan ocs.TalkRoomMessageData, error) {
c := make(chan ocs.TalkRoomMessageData)
Expand Down

0 comments on commit e925d94

Please sign in to comment.