nctalk: update library to v0.2.0
Signed-off-by: Gary Kim <gary@garykim.dev>
This commit is contained in:
2
go.mod
2
go.mod
@@ -53,7 +53,7 @@ require (
|
||||
github.com/zfjagann/golang-ring v0.0.0-20210116075443-7c86fdb43134
|
||||
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb
|
||||
golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c
|
||||
gomod.garykim.dev/nc-talk v0.1.7
|
||||
gomod.garykim.dev/nc-talk v0.2.0
|
||||
gopkg.in/olahol/melody.v1 v1.0.0-20170518105555-d52139073376
|
||||
layeh.com/gumble v0.0.0-20200818122324-146f9205029b
|
||||
)
|
||||
|
||||
4
go.sum
4
go.sum
@@ -1243,8 +1243,8 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gomod.garykim.dev/nc-talk v0.1.7 h1:G2qsiRcyaj5FEADQlulsBAFJHs27tPmH9VtKK+at9SM=
|
||||
gomod.garykim.dev/nc-talk v0.1.7/go.mod h1:DNucAJ6zeaumBEwV5NiYk+Eea8Ca+Q5f+plhz9F7d58=
|
||||
gomod.garykim.dev/nc-talk v0.2.0 h1:uTGgDOsz7G3l1YxKVv/daufQII4MBfOPxK7iuKQOtZg=
|
||||
gomod.garykim.dev/nc-talk v0.2.0/go.mod h1:q/Adot/H7iqi+H4lANopV7/xcMf+sX3AZXUXqiITwok=
|
||||
google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
|
||||
google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
|
||||
google.golang.org/api v0.0.0-20181220000619-583d854617af/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
|
||||
|
||||
@@ -33,10 +33,14 @@ type SpreedCapabilities struct {
|
||||
Folder string `json:"folder"`
|
||||
} `json:"attachments"`
|
||||
Chat struct {
|
||||
MaxLength int `json:"max-length"`
|
||||
MaxLength int `json:"max-length"`
|
||||
ReadPrivacy int `json:"read-privacy"`
|
||||
} `json:"chat"`
|
||||
Conversations struct {
|
||||
CanCreate bool `json:"can-create"`
|
||||
} `json:"conversations"`
|
||||
Previews struct {
|
||||
MaxGifSize int `json:"max-gif-size"`
|
||||
} `json:"previews"`
|
||||
} `json:"config"`
|
||||
}
|
||||
|
||||
11
vendor/gomod.garykim.dev/nc-talk/ocs/message.go
vendored
11
vendor/gomod.garykim.dev/nc-talk/ocs/message.go
vendored
@@ -35,6 +35,15 @@ 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
|
||||
//
|
||||
// If a message has been deleted, a message of MessageType MessageSystem is
|
||||
// sent through the channel for which the parent message's MessageType is MessageDelete.
|
||||
// So, in order to check if a new message is a message deletion request, a check
|
||||
// like this can be used:
|
||||
// msg.MessageType == ocs.MessageSystem && msg.Parent != nil && msg.Parent.MessageType == ocs.MessageDelete
|
||||
MessageDelete MessageType = "comment_deleted"
|
||||
|
||||
// ActorUser is a Nextcloud Talk message sent by a user
|
||||
ActorUser ActorType = "users"
|
||||
|
||||
@@ -55,6 +64,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:"-"`
|
||||
}
|
||||
|
||||
|
||||
32
vendor/gomod.garykim.dev/nc-talk/room/room.go
vendored
32
vendor/gomod.garykim.dev/nc-talk/room/room.go
vendored
@@ -41,6 +41,8 @@ var (
|
||||
ErrUnexpectedReturnCode = errors.New("unexpected return code")
|
||||
// ErrTooManyRequests is returned if the server returns a 429
|
||||
ErrTooManyRequests = errors.New("too many requests")
|
||||
// ErrLackingCapabilities is returned if the server lacks the required capability for the given function
|
||||
ErrLackingCapabilities = errors.New("lacking required capabilities")
|
||||
)
|
||||
|
||||
// TalkRoom represents a room in Nextcloud Talk
|
||||
@@ -90,6 +92,36 @@ func (t *TalkRoom) SendMessage(msg string) (*ocs.TalkRoomMessageData, error) {
|
||||
return &msgInfo.OCS.TalkRoomMessage, err
|
||||
}
|
||||
|
||||
// DeleteMessage deletes the message with the given messageID on the server.
|
||||
//
|
||||
// Requires "delete-messages" capability on the Nextcloud Talk server
|
||||
func (t *TalkRoom) DeleteMessage(messageID int) (*ocs.TalkRoomMessageData, error) {
|
||||
// Check for required capability
|
||||
capable, err := t.User.Capabilities()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !capable.DeleteMessages {
|
||||
return nil, ErrLackingCapabilities
|
||||
}
|
||||
|
||||
url := t.User.NextcloudURL + constants.BaseEndpoint + "/chat/" + t.Token + "/" + strconv.Itoa(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)
|
||||
|
||||
57
vendor/gomod.garykim.dev/nc-talk/user/user.go
vendored
57
vendor/gomod.garykim.dev/nc-talk/user/user.go
vendored
@@ -28,12 +28,16 @@ import (
|
||||
|
||||
const (
|
||||
ocsCapabilitiesEndpoint = "/ocs/v2.php/cloud/capabilities"
|
||||
ocsRoomsEndpoint = "/ocs/v2.php/apps/spreed/api/v2/room"
|
||||
ocsRoomsv2Endpoint = "/ocs/v2.php/apps/spreed/api/v2/room"
|
||||
ocsRoomsv4Endpoint = "/ocs/v2.php/apps/spreed/api/v4/room"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrUserIsNil is returned when a funciton is called with an nil user.
|
||||
// ErrUserIsNil is returned when a function is called with an nil user.
|
||||
ErrUserIsNil = errors.New("user is nil")
|
||||
|
||||
// ErrCannotDownloadFile is returned when a function cannot download the requested file
|
||||
ErrCannotDownloadFile = errors.New("cannot download file")
|
||||
)
|
||||
|
||||
// TalkUser represents a user of Nextcloud Talk
|
||||
@@ -83,6 +87,22 @@ type Capabilities struct {
|
||||
ForceMute bool `ocscapability:"force-mute"`
|
||||
ConversationV2 bool `ocscapability:"conversation-v2"`
|
||||
ChatReferenceID bool `ocscapability:"chat-reference-id"`
|
||||
ConversationV3 bool `ocscapability:"conversation-v3"`
|
||||
ConversationV4 bool `ocscapability:"conversation-v4"`
|
||||
SIPSupport bool `ocscapability:"sip-support"`
|
||||
ChatReadStatus bool `ocscapability:"chat-read-status"`
|
||||
ListableRooms bool `ocscapability:"listable-rooms"`
|
||||
PhonebookSearch bool `ocscapability:"phonebook-search"`
|
||||
RaiseHand bool `ocscapability:"raise-hand"`
|
||||
RoomDescription bool `ocscapability:"room-description"`
|
||||
DeleteMessages bool `ocscapability:"delete-messages"`
|
||||
RichObjectSharing bool `ocscapability:"rich-object-sharing"`
|
||||
ConversationCallFlags bool `ocscapability:"conversation-call-flags"`
|
||||
GeoLocationSharing bool `ocscapability:"geo-location-sharing"`
|
||||
ReadPrivacyConfig bool `ocscapability:"config => chat => read-privacy"`
|
||||
SignalingV3 bool `ocscapability:"signaling-v3"`
|
||||
TempUserAvatarAPI bool `ocscapability:"temp-user-avatar-api"`
|
||||
MaxGifSizeConfig int `ocscapability:"config => previews => max-gif-size"`
|
||||
}
|
||||
|
||||
// RoomInfo contains information about a room
|
||||
@@ -160,8 +180,17 @@ func (t *TalkUser) RequestClient(client request.Client) *request.Client {
|
||||
|
||||
// GetRooms returns a list of all rooms the user is in
|
||||
func (t *TalkUser) GetRooms() (*[]RoomInfo, error) {
|
||||
endpoint := ocsRoomsv2Endpoint
|
||||
cap, err := t.Capabilities()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cap.ConversationV4 {
|
||||
endpoint = ocsRoomsv4Endpoint
|
||||
}
|
||||
|
||||
client := t.RequestClient(request.Client{
|
||||
URL: ocsRoomsEndpoint,
|
||||
URL: endpoint,
|
||||
})
|
||||
res, err := client.Do()
|
||||
if err != nil {
|
||||
@@ -239,6 +268,22 @@ func (t *TalkUser) Capabilities() (*Capabilities, error) {
|
||||
ConversationV2: sliceContains(sc.Features, "conversation-v2"),
|
||||
ChatReferenceID: sliceContains(sc.Features, "chat-reference-id"),
|
||||
ChatMaxLength: sc.Config.Chat.MaxLength,
|
||||
ConversationV3: sliceContains(sc.Features, "conversation-v3"),
|
||||
ConversationV4: sliceContains(sc.Features, "conversation-v4"),
|
||||
SIPSupport: sliceContains(sc.Features, "sip-support"),
|
||||
ChatReadStatus: sliceContains(sc.Features, "chat-read-status"),
|
||||
ListableRooms: sliceContains(sc.Features, "listable-rooms"),
|
||||
PhonebookSearch: sliceContains(sc.Features, "phonebook-search"),
|
||||
RaiseHand: sliceContains(sc.Features, "raise-hand"),
|
||||
RoomDescription: sliceContains(sc.Features, "room-description"),
|
||||
ReadPrivacyConfig: sc.Config.Chat.ReadPrivacy != 0,
|
||||
MaxGifSizeConfig: sc.Config.Previews.MaxGifSize,
|
||||
DeleteMessages: sliceContains(sc.Features, "delete-messages"),
|
||||
RichObjectSharing: sliceContains(sc.Features, "rich-object-sharing"),
|
||||
ConversationCallFlags: sliceContains(sc.Features, "conversation-call-flags"),
|
||||
GeoLocationSharing: sliceContains(sc.Features, "geo-location-sharing"),
|
||||
SignalingV3: sliceContains(sc.Features, "signaling-v3"),
|
||||
TempUserAvatarAPI: sliceContains(sc.Features, "temp-user-avatar-api"),
|
||||
}
|
||||
|
||||
t.capabilities = tr
|
||||
@@ -264,7 +309,11 @@ func (t *TalkUser) DownloadFile(path string) (data *[]byte, err error) {
|
||||
URL: url,
|
||||
})
|
||||
res, err := c.Do()
|
||||
if err != nil || res.StatusCode() != 200 {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if res.StatusCode() != 200 {
|
||||
err = ErrCannotDownloadFile
|
||||
return
|
||||
}
|
||||
data = &res.Data
|
||||
|
||||
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@@ -384,7 +384,7 @@ golang.org/x/text/unicode/norm
|
||||
golang.org/x/text/width
|
||||
# golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
|
||||
golang.org/x/time/rate
|
||||
# gomod.garykim.dev/nc-talk v0.1.7
|
||||
# gomod.garykim.dev/nc-talk v0.2.0
|
||||
## explicit
|
||||
gomod.garykim.dev/nc-talk/constants
|
||||
gomod.garykim.dev/nc-talk/ocs
|
||||
|
||||
Reference in New Issue
Block a user