Compare commits

...

4 Commits

Author SHA1 Message Date
diamondburned f24feb2002 MessageUpdate should only update the content
This commit changes MessageUpdate so that it only updates the message
content. Updating the username should be up to MessageCreate's Author.
2021-03-20 00:13:39 -07:00
diamondburned f8c644fa7e Allow empty texts with segments
This commit allows segments in an empty text segment to account for
segments with only an image.
2021-03-19 22:40:31 -07:00
diamondburned c7d4473c23 Nicknamer to embed Name instead
This commit breaks Nicknamer to embed Name instead of having its own
ContainerMethod with a similar function signature but different name.
This allows the frontend to reuse the same LabelContainer abstraction
for Nickname as well.
2021-03-19 22:15:42 -07:00
diamondburned 174496bdf9 Enforce Identifier on all Services
This commit breaks the Service interface to force all services to have a
global unique identifier. The commit does not enforce any particular
format, but the Reverse Domain Name Notation is recommended.

For reference:
https://en.wikipedia.org/wiki/Reverse_domain_name_notation
2021-03-19 16:52:41 -07:00
4 changed files with 44 additions and 20 deletions

View File

@ -523,7 +523,9 @@ type MessageHeader interface {
// behaves similarly to MessageCreate, except all fields are optional. The
// frontend is responsible for checking which field is not empty and check it.
type MessageUpdate interface {
MessageCreate
MessageHeader
Content() text.Rich
}
// MessagesContainer is a view implementation that displays a list of messages
@ -588,7 +590,7 @@ type Namer interface {
// implement ServerMessage also don't need to implement ServerNickname. By
// default, the session name should be used.
type Nicknamer interface {
Nickname(context.Context, LabelContainer) (stop func(), err error)
Namer
}
// Noncer adds nonce support. A nonce is defined in this context as a unique
@ -731,9 +733,9 @@ type ServersContainer interface {
SetServers([]Server)
}
// A service is a complete service that's capable of multiple sessions. It has
// to implement the Authenticate() method, which returns multiple
// implementations of Authenticator.
// Service is a complete service that's capable of multiple sessions. It has to
// implement the Authenticate() method, which returns multiple implementations
// of Authenticator.
//
// A service can implement SessionRestorer, which would indicate the frontend
// that it can restore past sessions. Sessions are saved using the SessionSaver
@ -745,6 +747,13 @@ type ServersContainer interface {
// configurations must be optional, as frontends may not implement a
// configurator UI.
type Service interface {
// Identifier returns the unique identifier for the service. There is no
// enforced representation, but services are recommended to follow the Reverse
// Domain Name Notation for consistency. An example of that would be:
//
// com.github.diamondburned.cchat-discord
// com.github.username.service
Identifier
// Namer returns the name of the service.
Namer

Binary file not shown.

View File

@ -651,7 +651,7 @@ var Main = Packages{
},
}, {
Comment: Comment{`
A service is a complete service that's capable of multiple
Service is a complete service that's capable of multiple
sessions. It has to implement the Authenticate() method, which
returns multiple implementations of Authenticator.
@ -668,6 +668,17 @@ var Main = Packages{
`},
Name: "Service",
Embeds: []EmbeddedInterface{{
Comment: Comment{`
Identifier returns the unique identifier for the service. There
is no enforced representation, but services are recommended to
follow the Reverse Domain Name Notation for consistency. An
example of that would be:
com.github.diamondburned.cchat-discord
com.github.username.service
`},
InterfaceName: "Identifier",
}, {
Comment: Comment{`
Namer returns the name of the service.
`},
@ -1200,14 +1211,8 @@ var Main = Packages{
implement ServerNickname. By default, the session name should be
used.
`},
Name: "Nicknamer",
Methods: []Method{
ContainerMethod{
method: method{Name: "Nickname"},
HasContext: true,
ContainerType: "LabelContainer",
},
},
Name: "Nicknamer",
Embeds: []EmbeddedInterface{{InterfaceName: "Namer"}},
}, {
Comment: Comment{`
Backlogger adds message history capabilities into a message
@ -1597,12 +1602,20 @@ var Main = Packages{
}, {
Comment: Comment{`
MessageUpdate is the interface for a message update (or edit)
event. It behaves similarly to MessageCreate, except all fields
are optional. The frontend is responsible for checking which
field is not empty and check it.
event. It is only responsible for updating a message's content.
The author's name should be updated using MessageCreate's
Author.
`},
Name: "MessageUpdate",
Embeds: []EmbeddedInterface{{InterfaceName: "MessageCreate"}},
Embeds: []EmbeddedInterface{{InterfaceName: "MessageHeader"}},
Methods: []Method{
GetterMethod{
method: method{Name: "Content"},
Returns: []NamedType{{
Type: MakeQual("text", "Rich"),
}},
},
},
}, {
Comment: Comment{`
MessageDelete is the interface for a message delete event.

View File

@ -11,7 +11,9 @@ func SolidColor(rgb uint32) uint32 {
return (rgb << 8) | 0xFF
}
// IsEmpty returns true if the given rich segment's content is empty.
// IsEmpty returns true if the given rich segment's content is empty. Note that
// a rich text is not necessarily empty if the content is empty, because there
// may be images within the segments.
func (r Rich) IsEmpty() bool {
return r.Content == ""
return r.Content == "" && len(r.Segments) == 0
}