user

package
v0.0.0-...-6e21e7b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2018 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package user is a generated protocol buffer package.

It is generated from these files:

profile_photo_ids.proto

It has these top-level messages:

ProfilePhotoIds

Index

Constants

View Source
const (
	ONLINE_TIMEOUT       = 60 // 15秒
	CHECK_ONLINE_TIMEOUT = 70 // 17秒, 15+2秒的误差

)

- 简单设计思路(@benqi)

  • IM里,在线状态是一种Weak状态,不需要非常的精确,在线状态只需要达到最终一致性要求即可 故可以将在线状态存储在redis里
  • 以一种租约机制设置用户状态的在线状态 > 一旦收到account_status,如果不存在,则设置为在线,并为这个key设置一个过期时间 如果key存在,则延长过期时间
  • 回到我们的应用场景,一个客户端对应于一个AuthKeyId,以如下结构存储 > key(online_user_id) --> hash { [auth_key_id]_[session_id] : {time, server_id, net_lib_session_id} } > - key为用户Id > - value为hash结构,实际存储值通过连接符'_'拼装 > - hash里的field为<auth_key_id, session_id>二元组 > - field的value为<time, server_id, net_lib_session_id>三元组
  • why?? > telegram最大的一个特色是允许多端同步,由auth_key_id标识一个客户端设备,连接到服务端以后,由auth_key_id+session_id对应于 > telegram实例(https://core.telegram.org/mtproto/description),一个用户可能会有多个auth_key_id,而且每个由auth_key_id > 也可能会有多个session_id,所以以<auth_key_id, session_id>二元组做为字段唯一标识客户端实例已经上线,但这样会存在如下问题: > - hash没有指定某一个field设置过期时间,会导致已经下线的客户端还存在field里,故field的value里要缓存一个time时间,由业务层通过 > 过期时间来判断是否已经失效
  • 运维需要注意的地方
  • 各服务器要对时,服务器时间误差不能太大
  • ......

auth_key_id ->

Variables

This section is empty.

Functions

func CheckAccessHashByUserId

func CheckAccessHashByUserId(userId int32, accessHash int64) bool

func CheckPhoneNumberExist

func CheckPhoneNumberExist(phoneNumber string) bool

func CheckUserAccessHash

func CheckUserAccessHash(id int32, hash int64) bool

func CreateNewUser

func CreateNewUser(phoneNumber, countryCode, firstName, lastName string) *mtproto.TLUser

func CreateNewUserPassword

func CreateNewUserPassword(userId int32)

func CreateOrUpdateByInbox

func CreateOrUpdateByInbox(userId, peerType int32, peerId int32, topMessage int32, unreadMentions bool)

收件箱

func CreateOrUpdateByOutbox

func CreateOrUpdateByOutbox(userId, peerType int32, peerId int32, topMessage int32, unreadMentions, clearDraft bool)

发件箱

func DeleteUserPhotoID

func DeleteUserPhotoID(userId int32, photoId int64)

func GetContactUserIDList

func GetContactUserIDList(userId int32) []int32

func GetCountryCodeByUser

func GetCountryCodeByUser(userId int32) string

func GetDefaultUserPhotoID

func GetDefaultUserPhotoID(userId int32) int64

func GetDialogsByOffsetId

func GetDialogsByOffsetId(userId int32, isPinned bool, offsetId int32, limit int32) (dialogs []*mtproto.Dialog)

func GetDialogsByUserIDAndType

func GetDialogsByUserIDAndType(userId, peerType int32) (dialogs []*mtproto.Dialog)

func GetMyUserByPhoneNumber

func GetMyUserByPhoneNumber(phoneNumber string) *userData

func GetPeersDialogs

func GetPeersDialogs(selfId int32, peers []*mtproto.InputPeer) (dialogs []*mtproto.Dialog)

func GetPinnedDialogs

func GetPinnedDialogs(userId int32) (dialogs []*mtproto.Dialog)

func GetStatuseList

func GetStatuseList(selfId int32) []*mtproto.ContactStatus

func GetUserById

func GetUserById(selfId int32, userId int32) *userData

func GetUserByPhoneNumber

func GetUserByPhoneNumber(selfId int32, phoneNumber string) *userData

func GetUserFull

func GetUserFull(selfUserId int32, userId int32) (userFull *mtproto.TLUserFull)

func GetUserPhotoIDList

func GetUserPhotoIDList(userId int32) []int64

func GetUserStatus

func GetUserStatus(userId int32) *mtproto.UserStatus

func GetUsersBySelfAndIDList

func GetUsersBySelfAndIDList(selfUserId int32, userIdList []int32) (users []*mtproto.User)

func SaveDraftMessage

func SaveDraftMessage(userId int32, peerType int32, peerId int32, message *mtproto.DraftMessage)

func SetOffline

func SetOffline(status *SessionStatus) (err error)

func SetOnline

func SetOnline(status *SessionStatus) (err error)

func SetUserPhotoID

func SetUserPhotoID(userId int32, photoId int64)

func UpdateUserStatus

func UpdateUserStatus(userId int32, lastSeenAt int64)

Types

type ProfilePhotoIds

type ProfilePhotoIds struct {
	Default int64   `protobuf:"varint,1,opt,name=default" json:"default,omitempty"`
	IdList  []int64 `protobuf:"varint,2,rep,packed,name=id_list,json=idList" json:"id_list,omitempty"`
}

func MakeProfilePhotoData

func MakeProfilePhotoData(jsonData string) *ProfilePhotoIds

func (*ProfilePhotoIds) AddPhotoId

func (m *ProfilePhotoIds) AddPhotoId(id int64)

func (*ProfilePhotoIds) Descriptor

func (*ProfilePhotoIds) Descriptor() ([]byte, []int)

func (*ProfilePhotoIds) GetDefault

func (m *ProfilePhotoIds) GetDefault() int64

func (*ProfilePhotoIds) GetIdList

func (m *ProfilePhotoIds) GetIdList() []int64

func (*ProfilePhotoIds) ProtoMessage

func (*ProfilePhotoIds) ProtoMessage()

func (*ProfilePhotoIds) RemovePhotoId

func (m *ProfilePhotoIds) RemovePhotoId(id int64) int64

func (*ProfilePhotoIds) Reset

func (m *ProfilePhotoIds) Reset()

func (*ProfilePhotoIds) String

func (m *ProfilePhotoIds) String() string

func (*ProfilePhotoIds) ToJson

func (m *ProfilePhotoIds) ToJson() string

type SessionStatus

type SessionStatus struct {
	UserId int32 //

	AuthKeyId int64 //
	SessionId int64 //

	ServerId        int32 // ServerId
	NetlibSessionId int64 // 网络库SessionID,不是
	Now             int64 // 上报时间
}

func GetOnlineByUserId

func GetOnlineByUserId(userId int32) ([]*SessionStatus, error)

func GetOnlineByUserIdList

func GetOnlineByUserIdList(userIdList []int32) (statusList []*SessionStatus, err error)

TODO(@benqi): 优化 取多个用户的状态信息,可以使用lua脚本,避免多次请求 eval "local rst={}; for i,v in pairs(KEYS) do rst[i]=redis.call('hgetall', v) end; return rst" 2 user:1 user:2

func (*SessionStatus) FromKeyValue

func (status *SessionStatus) FromKeyValue(k, v string) (err error)

func (*SessionStatus) ToField

func (status *SessionStatus) ToField() string

func (*SessionStatus) ToKey

func (status *SessionStatus) ToKey() string

func (*SessionStatus) ToValue

func (status *SessionStatus) ToValue() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL