Added full interface implementations for reference

This commit is contained in:
diamondburned (Forefront) 2020-06-02 23:56:34 -07:00
parent 5d3c3568f8
commit 9b3e03753c
2 changed files with 120 additions and 9 deletions

125
README.md
View File

@ -3,8 +3,10 @@
A set of stabilized interfaces for cchat implementations, joining the backend
and frontend together.
## Backend
### Service
A service is a complete service that's capable of multiple sessions. It has to
@ -20,18 +22,35 @@ The current API is a flat key-value map, which can be parsed by the backend
itself into more meaningful data structures. All configurations must be
optional, as frontends may not implement a configurator UI.
```go
type ServiceFull interface {
Service
// Optional
SessionRestorer
Configurator
Commander
CommandCompleter
Icon
}
```
#### Interfaces
- SessionRestorer (optional)
- Configurator (optional)
- Commander (optional)
- Icon (optional)
### Authenticator
The authenticator interface allows for a multistage initial authentication API
that the backend could use. Multistage is done by calling `AuthenticateForm`
then `Authenticate` again forever until no errors are returned.
#### Reference Implementation
```go
var s *cchat.Session
var err error
@ -51,6 +70,26 @@ for {
}
```
### Commander
The commander interface allows the backend to implement custom commands to
easily extend the API.
```go
type CommanderFull interface {
Commander
// Optional
CommandCompleter
}
```
#### Interfaces
- CommandCompleter (optional)
### Session
A session is returned after authentication on the service. Session implements
@ -63,52 +102,95 @@ the session into its keyring at any time. Whether the keyring is completely
secure or not is up to the frontend. For cchat-gtk, that would be using the
Gnome Keyring daemon.
```go
type SessionFull interface {
// Session already inherits ServerList.
Session
Icon
SessionSaver
}
```
#### Interfaces
- ServerList
- Icon (optional)
- SessionSaver (optional)
### Commander
The commander interface allows the backend to implement custom commands to
easily extend the API.
#### Interfaces
- CommandCompleter (optional)
### Identifier
The identifier interface forces whatever interface that embeds this one to be
uniquely identifiable.
### Configurator
The configurator interface is a way for the frontend to display configuration
options that the backend has.
### Server
A server is any entity that is usually a channel or a guild.
```go
type ServerFull interface {
Server
[ ServerList | (
ServerMessage
// Optional
ServerMessageSender
ServerMessageSendCompleter
) ]
// Optional
Icon
}
```
#### Interfaces
- ServerList and/or ServerMessage
- Icon (optional)
### ServerMessage
A server message is an entity that contains messages to be displayed. An example
would be channels in Discord and IRC.
```go
type ServerMessageFull interface {
ServerMessage
// Optional
ServerMessageSender
ServerMessageSendCompleter
}
```
#### Interfaces
- ServerMessageSender (optional): adds message sending capability.
- ServerMessageSendCompleter (optional): adds message completion capability.
### Messages
```go
type MessageFull interface {
// These 3 types already inherit MessageHeader.
[ MessageCreate | MessageUpdate | MessageDelete ]
// Optional
MessageNonce
MessageMentionable
}
```
#### Interfaces
- MessageHeader: the minimum for a proper message.
@ -116,17 +198,29 @@ would be channels in Discord and IRC.
- MessageNonce (optional)
- MessageMentionable (optional)
### MessageAuthor
MessageAuthor is the interface that a message author would implement. ID would
typically return the user ID, or the username if that's the unique identifier.
```go
type MessageAuthorFull interface {
MessageAuthor
// Optional
MessageAuthorAvatar
}
```
#### Interfaces
- MessageAuthorAvatar (optional)
## Frontend
### ServersContainer
A servers container is any type of view that displays the list of servers. It
@ -138,6 +232,7 @@ instead of a tree view, as servers can be infinitely nested.
This interface expects the frontend to handle its own errors.
### MessagesContainer
A messages container is a view implementation that displays a list of messages
@ -148,6 +243,7 @@ Since this container interface extends a single Server, the frontend is allowed
to have multiple views. This is usually done with tabs or splits, but the
backend should update them all nonetheless.
### SendableMessage
The frontend can make its own send message data implementation to indicate extra
@ -157,3 +253,16 @@ An example of this is `MessageNonce`, which is similar to IRCv3's [labeled
response extension](https://ircv3.net/specs/extensions/labeled-response).
The frontend could implement this interface and check if incoming
`MessageCreate` events implement the same interface.
```go
type SendableMessageFull interface {
SendableMessage
// Optional
MessageNonce
}
```
#### Interfaces (only known)
- MessageNonce (optional)

View File

@ -243,7 +243,9 @@ type MessageAuthor interface {
}
// MessageAuthorAvatar is an optional interface that MessageAuthor could
// implement. A frontend may optionally support this.
// implement. A frontend may optionally support this. A backend may return an
// empty string, in which the frontend must handle, perhaps by using a
// placeholder.
type MessageAuthorAvatar interface {
Avatar() (url string)
}