Facebook
From Temir, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 57
  1. syntax = "proto3";
  2.  
  3. package accord;
  4. option go_package = ".;pb";
  5.  
  6. import "google/protobuf/timestamp.proto";
  7.  
  8. message AddChannelRequest {
  9.   string name = 1;
  10.   bool isPublic = 2;
  11. }
  12.  
  13. message AddChannelResponse {}
  14.  
  15. message RemoveChannelRequest { fixed64 channel_id = 1; }
  16.  
  17. message RemoveChannelResponse {}
  18.  
  19. message GetChannelRequest { fixed64 channel_id = 1; }
  20.  
  21. message GetChannelResponse {
  22.   fixed64 channel_id = 1;
  23.   string name = 2;
  24.   bool isPublic = 3;
  25.   repeated User users = 4;
  26.   // and more to be added.
  27.  
  28.   message User {
  29.     string username = 1;
  30.     string role = 2;
  31.     // and more to be added.
  32.   }
  33. }
  34.  
  35. message ServerStreamRequest { string username = 1; }
  36.  
  37. message ServerStreamResponse {
  38.   oneof event {
  39.     ChannelAction channel_action = 1;
  40.     AnyOtherServerConfigChange any_other_server_config_change = 2;
  41.   }
  42.  
  43.   // After users call unary rpc to add/remove channel, it gets
  44.   // broadcasted to all users (including the caller) through
  45.   // this message.
  46.   message ChannelAction {
  47.     fixed64 channel_id = 1;
  48.     oneof action {
  49.       // AddChannel is for broadcasting to users that a new channel
  50.       // has been added.
  51.       AddChannel add_channel = 2;
  52.       // Broadcasting to users that a channel has been removed.
  53.       RemoveChannel remove_channel = 3;
  54.     }
  55.  
  56.     message AddChannel {
  57.       string name = 1;
  58.       bool isPublic = 2;
  59.     }
  60.  
  61.     message RemoveChannel {}
  62.   }
  63.  
  64.   // This is a placeholder to be renamed for emerging needs for
  65.   // server configuration changes.
  66.   message AnyOtherServerConfigChange {}
  67. }
  68.  
  69. // Used in ChannelStreamRequest- and Response to initiate and broadcast
  70. // channel-related changes.
  71. message ChannelConfigMessage {
  72.   oneof msg {
  73.     NameChannelConfigMessage name_msg = 1;
  74.     PermissionChannelConfigMessage permission_msg = 2;
  75.     PinChannelConfigMessage pin_msg = 3;
  76.   }
  77.  
  78.   message NameChannelConfigMessage { string new_channel_name = 1; }
  79.  
  80.   enum AddRemoveAction {
  81.     UNKNOWN_ACTION = 0;
  82.     ADD_ACTION = 1;
  83.     REMOVE_ACTION = 2;
  84.   }
  85.  
  86.   enum Permission {
  87.     // default role in case api user leaves this field empty
  88.     UNKNOWN_PERMISSION = 0;
  89.     // permission to read for subscribed users or any member of the channel
  90.     READ = 1;
  91.     // includes writing, modifying, and deletion of own messages
  92.     WRITE = 2;
  93.     // allows deleting othes users' messages
  94.     DELETE = 3;
  95.     // allows to modify channel configurations
  96.     MODIFY = 4;
  97.     // for kicking users out of the channel
  98.     KICK = 5;
  99.     // for banning users
  100.     BAN = 6;
  101.     // permanently removing the channel and all its data
  102.     REMOVE_CHANNEL = 7;
  103.   }
  104.  
  105.   message PermissionChannelConfigMessage {
  106.     AddRemoveAction action = 1;
  107.     Permission permission = 2;
  108.     string role = 3;
  109.   }
  110.  
  111.   message PinChannelConfigMessage { fixed64 message_id = 1; }
  112. }
  113.  
  114. // Stream response for bidirectional streaming of user and  config
  115. // messages with a single channel.
  116. message ChannelStreamRequest {
  117.   string username = 1;
  118.   fixed64 channel_id = 2;
  119.  
  120.   oneof msg {
  121.     UserMessage user_msg = 3;
  122.     ChannelConfigMessage config_msg = 4;
  123.   }
  124.  
  125.   message UserMessage {
  126.     oneof user_msg {
  127.       NewUserMessage new_user_msg = 1;
  128.       EditUserMessage edit_user_msg = 2;
  129.       DeleteUserMessage delete_user_msg = 3;
  130.     }
  131.  
  132.     message NewUserMessage { string content = 1; }
  133.  
  134.     message EditUserMessage {
  135.       fixed64 message_id = 1;
  136.       string content = 2;
  137.     }
  138.  
  139.     message DeleteUserMessage { fixed64 message_id = 1; }
  140.   }
  141. }
  142.  
  143. // Stream response for bidirectional streaming of user and  config
  144. // messages with a single channel.
  145. message ChannelStreamResponse {
  146.   oneof msg {
  147.     UserMessage user_msg = 1;
  148.     ChannelConfigMessage config_msg = 2;
  149.   }
  150.  
  151.   message UserMessage {
  152.     fixed64 message_id = 1;
  153.     oneof user_msg {
  154.       NewAndUpdateUserMessage new_and_update_user_msg = 2;
  155.       DeleteUserMessage delete_user_msg = 3;
  156.     }
  157.  
  158.     message NewAndUpdateUserMessage {
  159.       google.protobuf.Timestamp timestamp = 1;
  160.       string content = 2;
  161.     }
  162.  
  163.     message DeleteUserMessage {}
  164.   }
  165. }
  166.  
  167. service Chat {
  168.   rpc AddChannel(AddChannelRequest) returns (AddChannelResponse) {}
  169.   rpc RemoveChannel(RemoveChannelRequest) returns (RemoveChannelResponse) {}
  170.  
  171.   // Returns all the information about a particular channel.
  172.   rpc GetChannel(GetChannelRequest) returns (GetChannelResponse) {}
  173.  
  174.   // Stream's server-scope information to user, such as addition or
  175.   // removal of channels, and change in other server configurations.
  176.   rpc ServerStream(ServerStreamRequest) returns (stream ServerStreamResponse) {}
  177.  
  178.   // Bidirectional stream of user and channel configuration messages
  179.   // with a single channel.
  180.   // NOTE: the fields and nested messages were designed with a single
  181.   // channel in mind. So while it may be possible to use this RPC to
  182.   // stream with multiple channels simultaneously, no adequate result
  183.   // should be expected. Thus, it is developer's responsibility to make
  184.   // sure that separate Stream RPCs are invoked for each channel.
  185.   rpc ChannelStream(stream ChannelStreamRequest)
  186.       returns (stream ChannelStreamResponse) {}
  187. }