chore: initial inbox store model

This commit is contained in:
Steven 2023-10-27 01:10:19 +08:00
parent 59f0ee862d
commit e5978a70f5
8 changed files with 358 additions and 0 deletions

View File

@ -5,6 +5,9 @@
- [store/activity.proto](#store_activity-proto)
- [store/common.proto](#store_common-proto)
- [store/inbox.proto](#store_inbox-proto)
- [InboxMessage](#memos-store-InboxMessage)
- [store/system_setting.proto](#store_system_setting-proto)
- [BackupConfig](#memos-store-BackupConfig)
@ -53,6 +56,40 @@
<a name="store_inbox-proto"></a>
<p align="right"><a href="#top">Top</a></p>
## store/inbox.proto
<a name="memos-store-InboxMessage"></a>
### InboxMessage
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| title | [string](#string) | | |
| content | [string](#string) | | |
| link | [string](#string) | | |
| activity_id | [int32](#int32) | optional | |
<a name="store_system_setting-proto"></a>
<p align="right"><a href="#top">Top</a></p>

182
proto/gen/store/inbox.pb.go Normal file
View File

@ -0,0 +1,182 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc (unknown)
// source: store/inbox.proto
package store
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type InboxMessage struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"`
Content string `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"`
Link string `protobuf:"bytes,3,opt,name=link,proto3" json:"link,omitempty"`
ActivityId *int32 `protobuf:"varint,4,opt,name=activity_id,json=activityId,proto3,oneof" json:"activity_id,omitempty"`
}
func (x *InboxMessage) Reset() {
*x = InboxMessage{}
if protoimpl.UnsafeEnabled {
mi := &file_store_inbox_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *InboxMessage) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*InboxMessage) ProtoMessage() {}
func (x *InboxMessage) ProtoReflect() protoreflect.Message {
mi := &file_store_inbox_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use InboxMessage.ProtoReflect.Descriptor instead.
func (*InboxMessage) Descriptor() ([]byte, []int) {
return file_store_inbox_proto_rawDescGZIP(), []int{0}
}
func (x *InboxMessage) GetTitle() string {
if x != nil {
return x.Title
}
return ""
}
func (x *InboxMessage) GetContent() string {
if x != nil {
return x.Content
}
return ""
}
func (x *InboxMessage) GetLink() string {
if x != nil {
return x.Link
}
return ""
}
func (x *InboxMessage) GetActivityId() int32 {
if x != nil && x.ActivityId != nil {
return *x.ActivityId
}
return 0
}
var File_store_inbox_proto protoreflect.FileDescriptor
var file_store_inbox_proto_rawDesc = []byte{
0x0a, 0x11, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2f, 0x69, 0x6e, 0x62, 0x6f, 0x78, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65,
0x22, 0x88, 0x01, 0x0a, 0x0c, 0x49, 0x6e, 0x62, 0x6f, 0x78, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65,
0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e,
0x74, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x69, 0x6e, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
0x04, 0x6c, 0x69, 0x6e, 0x6b, 0x12, 0x24, 0x0a, 0x0b, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74,
0x79, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x48, 0x00, 0x52, 0x0a, 0x61, 0x63,
0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x49, 0x64, 0x88, 0x01, 0x01, 0x42, 0x0e, 0x0a, 0x0c, 0x5f,
0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x5f, 0x69, 0x64, 0x42, 0x95, 0x01, 0x0a, 0x0f,
0x63, 0x6f, 0x6d, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x42,
0x0a, 0x49, 0x6e, 0x62, 0x6f, 0x78, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x29, 0x67,
0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x75, 0x73, 0x65, 0x6d, 0x65, 0x6d,
0x6f, 0x73, 0x2f, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67,
0x65, 0x6e, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0xa2, 0x02, 0x03, 0x4d, 0x53, 0x58, 0xaa, 0x02,
0x0b, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x65, 0xca, 0x02, 0x0b, 0x4d,
0x65, 0x6d, 0x6f, 0x73, 0x5c, 0x53, 0x74, 0x6f, 0x72, 0x65, 0xe2, 0x02, 0x17, 0x4d, 0x65, 0x6d,
0x6f, 0x73, 0x5c, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61,
0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0c, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x53, 0x74,
0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_store_inbox_proto_rawDescOnce sync.Once
file_store_inbox_proto_rawDescData = file_store_inbox_proto_rawDesc
)
func file_store_inbox_proto_rawDescGZIP() []byte {
file_store_inbox_proto_rawDescOnce.Do(func() {
file_store_inbox_proto_rawDescData = protoimpl.X.CompressGZIP(file_store_inbox_proto_rawDescData)
})
return file_store_inbox_proto_rawDescData
}
var file_store_inbox_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_store_inbox_proto_goTypes = []interface{}{
(*InboxMessage)(nil), // 0: memos.store.InboxMessage
}
var file_store_inbox_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_store_inbox_proto_init() }
func file_store_inbox_proto_init() {
if File_store_inbox_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_store_inbox_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*InboxMessage); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
file_store_inbox_proto_msgTypes[0].OneofWrappers = []interface{}{}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_store_inbox_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_store_inbox_proto_goTypes,
DependencyIndexes: file_store_inbox_proto_depIdxs,
MessageInfos: file_store_inbox_proto_msgTypes,
}.Build()
File_store_inbox_proto = out.File
file_store_inbox_proto_rawDesc = nil
file_store_inbox_proto_goTypes = nil
file_store_inbox_proto_depIdxs = nil
}

12
proto/store/inbox.proto Normal file
View File

@ -0,0 +1,12 @@
syntax = "proto3";
package memos.store;
option go_package = "gen/store";
message InboxMessage {
string title = 1;
string content = 2;
string link = 3;
optional int32 activity_id = 4;
}

27
store/db/mysql/inbox.go Normal file
View File

@ -0,0 +1,27 @@
package mysql
import (
"context"
"github.com/usememos/memos/store"
)
// nolint
func (d *DB) CreateInbox(ctx context.Context, create *store.Inbox) (*store.Inbox, error) {
return nil, nil
}
// nolint
func (d *DB) ListInboxes(ctx context.Context, find *store.FindInbox) ([]*store.Inbox, error) {
return nil, nil
}
// nolint
func (d *DB) UpdateInbox(ctx context.Context, update *store.UpdateInbox) (*store.Inbox, error) {
return nil, nil
}
// nolint
func (d *DB) DeleteInbox(ctx context.Context, delete *store.DeleteInbox) error {
return nil
}

27
store/db/sqlite/inbox.go Normal file
View File

@ -0,0 +1,27 @@
package sqlite
import (
"context"
"github.com/usememos/memos/store"
)
// nolint
func (d *DB) CreateInbox(ctx context.Context, create *store.Inbox) (*store.Inbox, error) {
return nil, nil
}
// nolint
func (d *DB) ListInboxes(ctx context.Context, find *store.FindInbox) ([]*store.Inbox, error) {
return nil, nil
}
// nolint
func (d *DB) UpdateInbox(ctx context.Context, update *store.UpdateInbox) (*store.Inbox, error) {
return nil, nil
}
// nolint
func (d *DB) DeleteInbox(ctx context.Context, delete *store.DeleteInbox) error {
return nil
}

View File

@ -133,3 +133,13 @@ CREATE TABLE idp (
identifier_filter TEXT NOT NULL DEFAULT '',
config TEXT NOT NULL DEFAULT '{}'
);
-- inbox
CREATE TABLE inbox (
id INTEGER PRIMARY KEY AUTOINCREMENT,
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
sender_id INTEGER NOT NULL,
receiver_id INTEGER NOT NULL,
status TEXT NOT NULL CHECK (row_status IN ('UNREAD', 'READ', 'ARCHIVED')) DEFAULT 'UNREAD',
message TEXT NOT NULL DEFAULT '{}'
);

View File

@ -81,4 +81,10 @@ type Driver interface {
GetStorage(ctx context.Context, find *FindStorage) (*Storage, error)
UpdateStorage(ctx context.Context, update *UpdateStorage) (*Storage, error)
DeleteStorage(ctx context.Context, delete *DeleteStorage) error
// Inbox model related methods.
CreateInbox(ctx context.Context, create *Inbox) (*Inbox, error)
ListInboxes(ctx context.Context, find *FindInbox) ([]*Inbox, error)
UpdateInbox(ctx context.Context, update *UpdateInbox) (*Inbox, error)
DeleteInbox(ctx context.Context, delete *DeleteInbox) error
}

57
store/inbox.go Normal file
View File

@ -0,0 +1,57 @@
package store
import (
"context"
storepb "github.com/usememos/memos/proto/gen/store"
)
// InboxStatus is the status for an inbox.
type InboxStatus string
const (
UNREAD InboxStatus = "UNREAD"
READ InboxStatus = "READ"
ARCHIVED InboxStatus = "ARCHIVED"
)
type Inbox struct {
ID int32
CreatedTs int64
SenderID int32
ReceiverID int32
Status InboxStatus
Message *storepb.InboxMessage
}
type UpdateInbox struct {
ID int32
Status InboxStatus
}
type FindInbox struct {
ID *int32
SenderID *int32
ReceiverID *int32
Status *InboxStatus
}
type DeleteInbox struct {
ID int32
}
func (s *Store) CreateInbox(ctx context.Context, create *Inbox) (*Inbox, error) {
return s.driver.CreateInbox(ctx, create)
}
func (s *Store) ListInboxes(ctx context.Context, find *FindInbox) ([]*Inbox, error) {
return s.driver.ListInboxes(ctx, find)
}
func (s *Store) UpdateInbox(ctx context.Context, update *UpdateInbox) (*Inbox, error) {
return s.driver.UpdateInbox(ctx, update)
}
func (s *Store) DeleteInbox(ctx context.Context, delete *DeleteInbox) error {
return s.driver.DeleteInbox(ctx, delete)
}