- syntax = "proto3";
- package accord;
- option go_package = ".;pb";
- import "google/protobuf/timestamp.proto";
- message AddChannelRequest {
- string name = 1;
- bool isPublic = 2;
- }
- message AddChannelResponse {}
- message RemoveChannelRequest { fixed64 channel_id = 1; }
- message RemoveChannelResponse {}
- message GetChannelRequest { fixed64 channel_id = 1; }
- message GetChannelResponse {
- fixed64 channel_id = 1;
- string name = 2;
- bool isPublic = 3;
- repeated User users = 4;
- // and more to be added.
- message User {
- string username = 1;
- string role = 2;
- // and more to be added.
- }
- }
- message ServerStreamRequest { string username = 1; }
- message ServerStreamResponse {
- oneof event {
- ChannelAction channel_action = 1;
- AnyOtherServerConfigChange any_other_server_config_change = 2;
- }
- // After users call unary rpc to add/remove channel, it gets
- // broadcasted to all users (including the caller) through
- // this message.
- message ChannelAction {
- fixed64 channel_id = 1;
- oneof action {
- // AddChannel is for broadcasting to users that a new channel
- // has been added.
- AddChannel add_channel = 2;
- // Broadcasting to users that a channel has been removed.
- RemoveChannel remove_channel = 3;
- }
- message AddChannel {
- string name = 1;
- bool isPublic = 2;
- }
- message RemoveChannel {}
- }
- // This is a placeholder to be renamed for emerging needs for
- // server configuration changes.
- message AnyOtherServerConfigChange {}
- }
- // Used in ChannelStreamRequest- and Response to initiate and broadcast
- // channel-related changes.
- message ChannelConfigMessage {
- oneof msg {
- NameChannelConfigMessage name_msg = 1;
- PermissionChannelConfigMessage permission_msg = 2;
- PinChannelConfigMessage pin_msg = 3;
- }
- message NameChannelConfigMessage { string new_channel_name = 1; }
- enum AddRemoveAction {
- UNKNOWN_ACTION = 0;
- ADD_ACTION = 1;
- REMOVE_ACTION = 2;
- }
- enum Permission {
- // default role in case api user leaves this field empty
- UNKNOWN_PERMISSION = 0;
- // permission to read for subscribed users or any member of the channel
- READ = 1;
- // includes writing, modifying, and deletion of own messages
- WRITE = 2;
- // allows deleting othes users' messages
- DELETE = 3;
- // allows to modify channel configurations
- MODIFY = 4;
- // for kicking users out of the channel
- KICK = 5;
- // for banning users
- BAN = 6;
- // permanently removing the channel and all its data
- REMOVE_CHANNEL = 7;
- }
- message PermissionChannelConfigMessage {
- AddRemoveAction action = 1;
- Permission permission = 2;
- string role = 3;
- }
- message PinChannelConfigMessage { fixed64 message_id = 1; }
- }
- // Stream response for bidirectional streaming of user and config
- // messages with a single channel.
- message ChannelStreamRequest {
- string username = 1;
- fixed64 channel_id = 2;
- oneof msg {
- UserMessage user_msg = 3;
- ChannelConfigMessage config_msg = 4;
- }
- message UserMessage {
- oneof user_msg {
- NewUserMessage new_user_msg = 1;
- EditUserMessage edit_user_msg = 2;
- DeleteUserMessage delete_user_msg = 3;
- }
- message NewUserMessage { string content = 1; }
- message EditUserMessage {
- fixed64 message_id = 1;
- string content = 2;
- }
- message DeleteUserMessage { fixed64 message_id = 1; }
- }
- }
- // Stream response for bidirectional streaming of user and config
- // messages with a single channel.
- message ChannelStreamResponse {
- oneof msg {
- UserMessage user_msg = 1;
- ChannelConfigMessage config_msg = 2;
- }
- message UserMessage {
- fixed64 message_id = 1;
- oneof user_msg {
- NewAndUpdateUserMessage new_and_update_user_msg = 2;
- DeleteUserMessage delete_user_msg = 3;
- }
- message NewAndUpdateUserMessage {
- google.protobuf.Timestamp timestamp = 1;
- string content = 2;
- }
- message DeleteUserMessage {}
- }
- }
- service Chat {
- rpc AddChannel(AddChannelRequest) returns (AddChannelResponse) {}
- rpc RemoveChannel(RemoveChannelRequest) returns (RemoveChannelResponse) {}
- // Returns all the information about a particular channel.
- rpc GetChannel(GetChannelRequest) returns (GetChannelResponse) {}
- // Stream's server-scope information to user, such as addition or
- // removal of channels, and change in other server configurations.
- rpc ServerStream(ServerStreamRequest) returns (stream ServerStreamResponse) {}
- // Bidirectional stream of user and channel configuration messages
- // with a single channel.
- // NOTE: the fields and nested messages were designed with a single
- // channel in mind. So while it may be possible to use this RPC to
- // stream with multiple channels simultaneously, no adequate result
- // should be expected. Thus, it is developer's responsibility to make
- // sure that separate Stream RPCs are invoked for each channel.
- rpc ChannelStream(stream ChannelStreamRequest)
- returns (stream ChannelStreamResponse) {}
- }