accountsDB.go 3.8 KB
Newer Older
T
tanggen 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
// Copyright (C) 2020 Finogeeks Co., Ltd
//
// This program is free software: you can redistribute it and/or  modify
// it under the terms of the GNU Affero General Public License, version 3,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

package model

import (
	"context"

	"github.com/finogeeks/ligase/model/authtypes"
	"github.com/finogeeks/ligase/model/dbtypes"

	_ "github.com/lib/pq"
)

type AccountsDatabase interface {
	//NewDatabase(driver, createAddr, address, topic string, useAsync bool) (interface{}, error)

	RecoverCache()

	WriteDBEvent(ctx context.Context, update *dbtypes.DBEvent) error

	CreateAccount(
		ctx context.Context, userID, plaintextPassword, appServiceID, displayName string,
	) (*authtypes.Account, error)

	CreateAccountWithCheck(
		ctx context.Context, oldAccount *authtypes.Account, userID, plaintextPassword, appServiceID, displayName string,
	) (*authtypes.Account, error)

	GetAccount(ctx context.Context, userID string) (*authtypes.Account, error)

	UpsertProfile(ctx context.Context, userID, displayName, avatarURL string) error
	UpsertProfileSync(ctx context.Context, userID, displayName, avatarURL string) error

	UpsertDisplayName(ctx context.Context, userID, displayName string) error
	UpsertDisplayNameSync(ctx context.Context, userID, displayName string) error

	UpsertAvatar(ctx context.Context, userID, avatarURL string) error
	UpsertAvatarSync(ctx context.Context, userID, avatarURL string) error

	InsertAccount(
		ctx context.Context, userID, plaintextPassword, appServiceID, displayName string,
	) (*authtypes.Account, error)

	PutFilter(ctx context.Context, userID, filterID, filter string) error

	AddRoomTag(ctx context.Context, userId, roomID, tag string, content []byte) error

	DeleteRoomTag(ctx context.Context, userId, roomID, tag string) error

	GetAccountsTotal(ctx context.Context) (int, error)
	GetActualTotal(ctx context.Context) (int, error)
	GetRoomTagsTotal(ctx context.Context) (int, error)

	SaveAccountData(ctx context.Context, userID, roomID, dataType, content string) error

	GetAccountDataTotal(ctx context.Context) (int, error)
	OnInsertAccountData(ctx context.Context, userID, roomID, dataType, content string) error
	OnInsertAccount(ctx context.Context, userID, hash, appServiceID string, createdTs int64) error
	OnInsertFilter(ctx context.Context, filter, filterID, userID string) error
	OnUpsertProfile(ctx context.Context, userID, displayName, avatarURL string) error

	OnInitProfile(ctx context.Context, userID, displayName, avatarURL string) error

	OnUpsertDisplayName(ctx context.Context, userID, displayName string) error

	OnUpsertAvatar(ctx context.Context, userID, avatarURL string) error
	OnInsertRoomTag(ctx context.Context, userId, roomID, tag string, content []byte) error
	OnDeleteRoomTag(ctx context.Context, userId, roomID, tag string) error
	GetAllProfile() ([]authtypes.Profile, error)
	GetProfileByUserID(ctx context.Context, userID string) (authtypes.Profile, error)

	UpsertUserInfo(ctx context.Context, userID, userName, jobNumber, mobile, landline, email string) error
	OnUpsertUserInfo(ctx context.Context, userID, userName, jobNumber, mobile, landline, email string) error
	OnInitUserInfo(ctx context.Context, userID, userName, jobNumber, mobile, landline, email string) error
	GetAllUserInfo() ([]authtypes.UserInfo, error)
	DeleteUserInfo(ctx context.Context, userID string) error
	OnDeleteUserInfo(ctx context.Context, userID string) error
}