func NewMsgRepository(db *sql.DB) *MsgRepository { mr := &MsgRepository{} mr.db = db mr.urIDs = make(map[types.ID]types.ID, 10240) gsql.MustExec(mr.db, `create table if not exists read_msgs( user_id bigint primary key, msg_id bigint not null default 0 )`) for i := 0; i < userMsgTableCount; i++ { mr.CreateUserMsgTable(types.ID(i)) } for i := 0; i < groupMsgTableCount; i++ { mr.CreateGroupMsgTable(types.ID(i)) } var rows *sql.Rows rows, err := mr.db.Query("select user_id, msg_id from read_msgs") if err != nil { log.Panic(err) } defer rows.Close() var uid, msgID types.ID for rows.Next() { err = rows.Scan(&uid, &msgID) if err != nil { panic(err) } mr.urIDs[uid] = msgID } return mr }
func (rs *AccountsService) AutoLogin(c context.Context, req *pb.AutoLoginRequest) (*pb.LoginResponse, error) { return rs.handleLoginResult(services.AutoLogin(c, types.ID(req.AccountId), req.LoginToken)) }