Commit Graph

127 Commits

Author SHA1 Message Date
diamondburned 997b156e2f Changed Namer to a Name method in Authenticator
This commit removes the Namer interface and use a normal Name() method
instead. This is because we don't want to add icons into Authenticators.
2020-10-26 22:25:55 -07:00
diamondburned 65273770ca Added Namer and Description into Authenticator
This commit embeds the Namer interface into Authenticator as well as
adding the new Description method, both of which returns a text.Rich.
These methods are added to provide contextual clues to the user about
each Authenticator method.

Frontends can use the Name as the title, so the name should be short,
concise, and not include the name of the service.
2020-10-26 22:21:21 -07:00
diamondburned 524bd06b7a Clarified ID uniqueness
This commit clarifies the rules regarding ID uniqueness and guarantees
when it comes to the backend and frontend. This piece of documentation
was added into the top package section.
2020-10-26 21:48:28 -07:00
diamondburned 642f13a8c3 Allow multiple implementations of Authenticator
This commit breaks the API to allow backends to return a slice of
Authenticators instead of a single Authenticator in the Service
interface. This is because some services might allow for more than one
method of authentication.

Note that the representation of multiple authenticators depends on the
frontend. One may choose to use tabs, notebooks, stacks, or anything
that is reasonable.
2020-10-26 21:44:09 -07:00
diamondburned b5dabacff4 WIP IPC draft 2020-10-18 19:06:48 -07:00
diamondburned 4c835a467b Fixed several ArgsIndexed bugs
This commit fixes several ArgsIndexed bugs that would cause the function
to return no words with -1. Additional test cases have been added.
2020-10-14 23:24:26 -07:00
diamondburned 10549e49e1 Added SplitFunc helper type
This commit adds the SplitFunc helper type which has a function
signature matching that of ArgsIndexer and SplitIndexer. Implementations
can use this type to provide pluggable splitters.
2020-10-14 18:26:49 -07:00
diamondburned 289eda1c25 Clarified Commander split rules; added ArgsIndexed
This commit clarified the word split rules when it comes to the
Commander interface. Specifically, this interface now has an edge case
of having split rules similarly to shell words (or shell syntax).

The implementation of these split rules is added into package split,
similarly to SplitIndexed. It is called ArgsIndexed. For the most parts,
it will behave similarly to shell syntax.
2020-10-14 18:08:35 -07:00
diamondburned 05f8ec0cbf Changed Commander to use []byte over io.Writer
This commit breaks the Commander interface. Prior to this, the Run
method would take in an io.Writer and do its tasks in the background.
Although this has lots of potential for usages, it is also very
overkill. Moreover, it makes IPC harder, since it now has to send over
fragments of data in synchronized order.

This commit gets rid of the io.Writer and only take a []byte for return
along with the error. This makes it easier for both the frontend and
backend to implement most commands, as well as making it easier for data
to be transferred over the wire.
2020-10-13 22:22:02 -07:00
diamondburned 1dd36e0034 Clarified text.Imager's bound behavior
This commit clarifies text.Imager's (and therefore text.Avatarer's as
well) bound behaviors. Prior to this commit, it is unclear which end
bound an implementation should return. This commit clarifies that in
order for the image to be inlined, the start must overlap the end
bounds.

This clarification was needed in order to differentiate images to be
inlined with images to be associated with other contexts, such as
Mentioned. The inline check would therefore be very simple:

    if start == end {
        if imager := segment.AsImager(); imager != nil {
            log.Println("Segment has an inline image.")
        }
    }

Note that since there's now a way to explicitly define whether an image
is inlined or not, for implementations that can't display images, the
ImageText() should only be used if the image is actually inlined.
Therefore, the same check also applies to ImageText(). This also applies
to AvatarText().
2020-10-13 18:30:21 -07:00
diamondburned 76f5201a6f Fix text.SolidColor returning invalid color
This commit fixes the implementation of the helper function SolidColor.
It now does correctly what it says: it sets the alpha bits to 0xFF.
Prior to this, the function would override part of the color due to an
incorrect shift.
2020-10-13 16:46:18 -07:00
diamondburned 4864d61476 Changed ServerUpdate's PreviousID API
Prior to this commit, the PreviousID method ambiguously confused two
different behaviors for the same result, that is when the returned ID is
empty.

This commit adds a return boolean to the method to differentiate those
two behaviors.
2020-10-09 12:11:23 -07:00
diamondburned 0ebf0c3302 Clarified ServerUpdate behavior
Prior to this commit, the PreviousID method of ServerUpdate seemed to be
a big unknown. This commit clarified that unknown by declaring two
conditions: when PreviousID returns an empty and non-empty ID.

The above change allows ServerUpdate events to both modify existing
servers as well as inserting new ones.
2020-10-09 11:51:16 -07:00
diamondburned d62231a4ef Fixed Backlogger method name
This commit fixes a mistake in the Backlogger interface, that is the
Backlog method was called Backlogger incorrectly.
2020-10-09 10:27:38 -07:00
diamondburned cfc0e00c8a Shorter, more idiomatic method names
This commit breaks several cchat interfaces to rename some method names
and make them shorter. These new method names are more idiomatic.
2020-10-09 10:09:38 -07:00
diamondburned 1b1e10a8a6 Updated reference split package to int64
This commit breaks package split's API to take in int64 types instead of
int. This is because CompletionEntry now uses int64 over int for
concreteness.
2020-10-09 09:34:02 -07:00
diamondburned 6140b5a131 Clarified text.{Imager,Avatarer}'s bound behavior
This commit clarifies text.Imager and text.Avatarer's bound behaviors.
Prior to this, the only behavior that those two interfaces have
regarding bounds is that only the starting bound matters, because images
must not substitute texts.

This commit clarifies that images are allowed complement other sections.
For example, a Mentioner can "have" an Imager by having the bounds
overlap.

These details are intentionally vaguely defined (it doesn't list any
interfaces beyond Mentioner), so implementations of either side can
implement these however they want, as long as the bounds overlap.

In the future, further clarification rules may be added if needed.
2020-10-09 00:17:58 -07:00
diamondburned 285ac6403f Added (text.Rich).IsEmpty
This commit restores the old IsEmpty API that was removed during code
generation.
2020-10-09 00:12:02 -07:00
diamondburned 819bcd3504 Clarified bitwise enum starting point; regenerate 2020-10-09 00:05:25 -07:00
diamondburned 32fa6266db Fixed Bitwise codegen being flipped 2020-10-08 23:58:58 -07:00
diamondburned 89b5ede1d8 Regenerated code to adhere to codegen header
This commit regenerates all files to adhere to the arguably-official
convention of having a standardized comment format to allow
distinguishing between written and generated files.

Refer to https://golang.org/s/generatedcode for more information.
2020-10-04 14:33:57 -07:00
diamondburned 5f7316cf9d Actioner.Actions to take a message ID
This commit restores the old API prior to the repository commits to make
the Actions method of the Actioner interface take in a message ID and
return a slice of strings.
2020-10-04 11:45:18 -07:00
diamondburned 086f987b3c Add Stringer into struct repositories
This commit adds the Stringer method representation into the repository.
The Rich struct of package text now implements Stringer and returns the
Content in plain text.

Prior to the repository commits, Rich used to have String().
2020-10-04 10:28:48 -07:00
diamondburned e08064021e Reproducible empty interface code generation
Prior to this commit, the code generator for package empty doesn't have
a defined order. This commit now sorts the packages before generation,
which gets rid of the main map's undefined order.
2020-10-03 23:24:15 -07:00
diamondburned dd4e230e0f Fixed UnreadContainer's comment
Prior to this commit, UnreadContainer's comments mentioned deprecated
SetUnread and such methods. It now reflects the new API.
2020-10-03 23:17:32 -07:00
diamondburned 99f7224d32 Mentioned now returns bool
Prior to this commit, the Mentioned method in MessageCreate didn't
return anything. This is a regression. It now returns a boolean that
indicates mentioned.
2020-10-03 23:14:54 -07:00
diamondburned 555931f974 Added Avatar() into Author
This commit adds the Avatar method into the Author interface. It returns
the URL if one, or it can return an empty string if either the service
does not support avatars or the user doesn't have avatars.
2020-10-03 23:08:24 -07:00
diamondburned aaa29f35b0 Author now has Name() over Namer
Prior to this commit, interface Author embedded interface Namer. This
doesn't work, as it is discouraged to keep a working state inside the
implementation of Author, but Namer's embedded Iconer requires a state.

The commit changed Author to use a Name method instead, which is only a
getter. It will no longer satisfy interface Name.
2020-10-03 22:52:21 -07:00
diamondburned 1588cfef9c Fixed IconContainer.SetIcon; added ImageContainer
This commit fixes IconContainer's SetIcon, which was SetImage prior to
this commit. Before the code generation commits, this container
originally had SetIcon.

This commit also adds back ImageContainer, which was a regression during
the code generation changes. It has the SetImage method.
2020-10-03 22:06:50 -07:00
diamondburned e2751cc260 Added helper functions in package text
This package adds back the Plain function from the old package text as
well as a new function called SolidColor that returns a new RGBA color
with the alpha bits maxed out.

These functions are there for convenience. They're also outside the
scope of the code generator and repository.
2020-10-03 21:29:15 -07:00
diamondburned 7b9b4864a5 Fixed package empty having wrong package name 2020-10-03 20:00:09 -07:00
diamondburned 2d00544d67 Added missing methods from embedded interfaces
This commit adds missing empty asserter methods from the interfaces
embedded in the parent interface.
2020-10-03 19:56:58 -07:00
diamondburned 59778af1dd Empty impls for package text
This commit adds empty structs that implement no-op asserter methods for
interfaces in package text. Those implementations have "Text" prefixed
to their names.

The added implementations stay in the same place as cchat's.
2020-10-03 19:31:44 -07:00
diamondburned 9a64b50703 Package text to use asserters; colors now RGBA
This commit regenerates package text to use asserters instead of
manually asserting structs. This is to both bring consistency to the
interfaces and prepare it for the incoming IPC additions.

This commit also changed the Colorer interface to require returning a
32-bit RGBA color. Before, backends could return 24-bit RGB OR 32-bit
RGBA, but there wasn't a good way to distinguish between the two. Now,
backends must set the alpha bits to 0xFF if it's 24-bit only.
2020-10-03 15:43:05 -07:00
diamondburned 25980eb794 Added package empty
This package adds the code generation for package empty, which provides
structs that has no-op asserter methods for ease of use.

The package demonstrates one of the many possible use cases of having a
repository ready for code generation.
2020-10-03 14:31:38 -07:00
diamondburned 2d93bf62ea Regenerated with Backlogger and fixes 2020-09-27 20:37:27 -07:00
diamondburned f515470458 Generated code now compiles; added DO NOT EDIT 2020-09-27 19:30:36 -07:00
diamondburned 516532ee01 Repository changes; regenerated code
This commit fixes some trivial errors in the repository package. The
changes are breaking.

This commit also replaced the old cchat and text Go source code files
with ones generated straight from the repository. To regenerate, run

    go generate ./...

The code is generated using the Jennifer library. In the future, all
generated code (including package empty and the RPC library) will use
Jennifer.
2020-09-27 18:41:17 -07:00
diamondburned 8e9321928b Added a repository for API source of truth
This commit adds a new package repository containing every single cchat
types that the package provides. Its goal is to be the source of truth
for the cchat files to be generated from.

A huge advantage of this is having types in an easily representable
format. This means that other languages can easily parse the repository
and generate its own types that are similar to the original ones.

Having a repository also allows easier code generation. For example,
this commit will allow generating the "empty" package in the future,
which would contain empty implementations of cchat databases that would
return nil for asserter methods.
2020-09-26 18:24:56 -07:00
diamondburned 8b8c46a714 Refactored to a completely new API
This commit refactors entirely the ways cchat interfaces extend others.
Prior to this commit, interfaces extend itself simply by implementing
methods. This change is crucial to allow structs to decide whether or
not an interface is extended during runtime.

The current change adds the "As" methods into interfaces. When said, for
example, "Messenger extends Server," we now have the Server interface
implementing the AsMessenger method instead of before where the struct
implementing Server also implemented Messenger's methods.

For future references, these method will be called asserter methods.

The biggest motivation for this change is that these asserter methods
can allow backends to decide whether or not certain features are
implemented during runtime. For example, not all servers may support
sending messages. The asserting method is also simpler than the actual
type assertions done before.

Another motivation is to prepare cchat for an API that can reasonably be
translated to something that can be transferred over the wire. Although
the API itself will likely not be transferred over actual networking,
there are lots of plans for IPC-ing the API. This could mean that
developers would be able to develop the backends and frontends in any
programming language.

A downside to this is that the API is more restricted in terms of
extending beyond interfaces defined in the package. The initial goal of
this was to allow certain frontends to check for additional interfaces
outside of cchat that certain services could implement. However, this
goal is mostly moot, as interfaces like these require prior extensive
knowledge from both the developers of the backend and frontend
libraries.
2020-09-25 19:31:01 -07:00
diamondburned d51668512b Fixed typo in MemberListDynamicSection 2020-09-07 20:36:32 -07:00
diamondburned 62711b89f2 Fixed superfluous Lister in Session 2020-09-07 18:30:12 -07:00
diamondburned 214233cf3d Fixed error: Messager -> Messenger
This commit breaks existing v0.1.0 code to fix a grammatical error.
2020-09-07 17:19:18 -07:00
diamondburned ab2b4d48fa Fixed assert example in package header
This commit fixed an error in the package header from the previous
commit.
2020-09-05 19:46:58 -07:00
diamondburned 40dbe21c82 Shorter interface names; "Is" method in interfaces
This commit introduces many breaking changes that will break all current
code, both in the frontend and backend.

This commit changes the previous interface names to shorter versions.
This is done because, with the addition of the parent interface being
embedded in every extension interfaces, it is pointless to have the
name indicate this relationship. Furthermore, shorter and concise names
are more idiomatic.

This commit also introduces the "Is" method that is in every extension
interfaces. The purpose of this method is to provide an alternative
mechanism to check if an interface is extended.

Prior to the "Is" method, the only way for a backend to indicate
channels that can either be sent a message or not is to use two
separate types. Now, backends could implement a single type and return a
true or false on the Is method.

This method has a major disadvantage: it makes type assertions longer
and more complex. Refer to the "assert extension interfaces" example for
an example.

Despite the above disadvantage, this change is needed by the RPC
implementation in the future. Thus, it is worth the trouble of checks
being more verbose.
2020-09-05 19:39:34 -07:00
diamondburned 4239dc47c4 Added rich.Empty
This commit adds rich.Empty for convenience. It describes an empty text
segment.
2020-09-05 19:39:34 -07:00
diamondburned cd018ef8f9 Added ID type; Added backlog interfaces
This commit adds the ID type, which is a type alias to a string. This
change does not break any APIs and is done purely for documentation
purposes.

This commit also adds backlog interfaces to add support for services
capable of storing and showing chat history.

A subtle behavior change with the above change would be that
MessageContainer implementations are now required to add a mechanism to
invalidate old containers when needed. For example, the MessagePrepender
passed into MessagesBefore must be invalidated by the frontend when the
channel in view is changed. This prevents stray messages from old
channels coming in.

There are many ways to invalidate a container, but the easiest way would
be to attach an optionally atomic boolean into the store and completely
separate the store from the view (aka widget).
2020-08-19 15:58:36 -07:00
diamondburned 1b70301711 Added MemberListDynamicSection
The interface MemberListDynamicSection was added to allow server
implementations to ignore the dynamic section methods if needed.

A new method LoadLess was also introduced into the new interfaces along
with the old LoadMore. This method basically unrolls the member list as
the user scroll back up.
2020-08-15 14:19:44 -07:00
diamondburned 681cc520d9 Added text.Plain helper function
This function was added for convenience.
2020-08-15 14:10:53 -07:00
diamondburned 2f5c86aa60 Breaking changes on member list interfaces
This commit breaks the old member list API in order to change several
things. These changes are done to improve the overall usability and
flexibility of their interfaces.

This commit introduces the method LoadMore into the MemberListSection
interface. The method was added to allow sections to be lazy loaded
conditionally. This allows the server to lazy load the member list over
the network.

In the future, there might be further modifications to allow clients to
invalidate or mark sections as stale, which would allow the server to
free up the list.

This commit also changed the old Name method of MemberListSection to use
the unified Namer interface. It also moved from using section's contents
as identifiers to having a dedicated ID method using the unified
Identifier interface.
2020-08-14 14:11:28 -07:00