Skip to content

Commit

Permalink
Add layer86 to support the latest open source client.
Browse files Browse the repository at this point in the history
  • Loading branch information
wubenqi committed Sep 16, 2018
1 parent 95cb1c0 commit 1897f2b
Show file tree
Hide file tree
Showing 264 changed files with 139,650 additions and 100,846 deletions.
8 changes: 8 additions & 0 deletions baselib/base/conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ func BoolToInt8(b bool) int8 {
return 0
}
}

func Int8ToBool(b int8) bool {
if b == 1 {
return true
} else {
return false
}
}
2 changes: 1 addition & 1 deletion baselib/base/string_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ func IsAlNumString(s string) bool {
prevtmp = r
}
return len(s) == c
}
}
4 changes: 2 additions & 2 deletions baselib/crypto/md5_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
package crypto

import (
"github.com/golang/glog"
"crypto/md5"
"fmt"
"os"
"github.com/golang/glog"
"io"
"os"
)

// TODO(@benqi): remove to baselib
Expand Down
36 changes: 18 additions & 18 deletions biz/base/peer_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
PEER_CHANNEL = 4
PEER_USERS = 5
PEER_CHATS = 6
PEER_ALL = 7
// PEER_ALL = 7
PEER_UNKNOWN = -1
)

Expand All @@ -57,12 +57,12 @@ func (p PeerUtil) String() (s string) {
return fmt.Sprintf("PEER_USERS: {peer_id: %d, access_hash: %d", p.PeerId, p.AccessHash)
case PEER_CHATS:
return fmt.Sprintf("PEER_CHATS: {peer_id: %d, access_hash: %d", p.PeerId, p.AccessHash)
case PEER_ALL:
return fmt.Sprintf("PEER_ALL: {peer_id: %d, access_hash: %d", p.PeerId, p.AccessHash)
//case PEER_ALL:
// return fmt.Sprintf("PEER_ALL: {peer_id: %d, access_hash: %d", p.PeerId, p.AccessHash)
default:
return fmt.Sprintf("PEER_UNKNOWN: {peer_id: %d, access_hash: %d", p.PeerId, p.AccessHash)
}
return
// return
}

func FromInputPeer(peer *mtproto.InputPeer) (p *PeerUtil) {
Expand Down Expand Up @@ -222,8 +222,8 @@ func FromInputNotifyPeer(peer *mtproto.InputNotifyPeer) (p *PeerUtil) {
p.PeerType = PEER_USERS
case mtproto.TLConstructor_CRC32_inputNotifyChats:
p.PeerType = PEER_CHATS
case mtproto.TLConstructor_CRC32_inputNotifyAll:
p.PeerType = PEER_ALL
//case mtproto.TLConstructor_CRC32_inputNotifyAll:
// p.PeerType = PEER_ALL
default:
panic(fmt.Sprintf("FromInputNotifyPeer(%v) error!", p))
}
Expand All @@ -249,11 +249,11 @@ func (p *PeerUtil) ToInputNotifyPeer(peer *mtproto.InputNotifyPeer) {
Constructor: mtproto.TLConstructor_CRC32_inputNotifyChats,
Data2: &mtproto.InputNotifyPeer_Data{},
}
case PEER_ALL:
peer = &mtproto.InputNotifyPeer{
Constructor: mtproto.TLConstructor_CRC32_inputNotifyAll,
Data2: &mtproto.InputNotifyPeer_Data{},
}
//case PEER_ALL:
// peer = &mtproto.InputNotifyPeer{
// Constructor: mtproto.TLConstructor_CRC32_inputNotifyAll,
// Data2: &mtproto.InputNotifyPeer_Data{},
// }
default:
panic(fmt.Sprintf("ToInputNotifyPeer(%v) error!", p))
}
Expand All @@ -269,8 +269,8 @@ func FromNotifyPeer(peer *mtproto.NotifyPeer) (p *PeerUtil) {
p.PeerType = PEER_USERS
case mtproto.TLConstructor_CRC32_notifyChats:
p.PeerType = PEER_CHATS
case mtproto.TLConstructor_CRC32_notifyAll:
p.PeerType = PEER_ALL
//case mtproto.TLConstructor_CRC32_notifyAll:
// p.PeerType = PEER_ALL
default:
panic(fmt.Sprintf("FromNotifyPeer(%v) error!", p))
}
Expand All @@ -296,11 +296,11 @@ func (p *PeerUtil) ToNotifyPeer() (peer *mtproto.NotifyPeer) {
Constructor: mtproto.TLConstructor_CRC32_notifyChats,
Data2: &mtproto.NotifyPeer_Data{},
}
case PEER_ALL:
peer = &mtproto.NotifyPeer{
Constructor: mtproto.TLConstructor_CRC32_notifyAll,
Data2: &mtproto.NotifyPeer_Data{},
}
//case PEER_ALL:
// peer = &mtproto.NotifyPeer{
// Constructor: mtproto.TLConstructor_CRC32_notifyAll,
// Data2: &mtproto.NotifyPeer_Data{},
// }
default:
panic(fmt.Sprintf("ToNotifyPeer(%v) error!", p))
}
Expand Down
2 changes: 1 addition & 1 deletion biz/base/report_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (i ReportReasonType) ToReportReason(text string) (reason *mtproto.ReportRea
case REASON_OTHER:
reason = &mtproto.ReportReason{
Constructor: mtproto.TLConstructor_CRC32_inputReportReasonOther,
Data2: &mtproto.ReportReason_Data{text},
Data2: &mtproto.ReportReason_Data{Text: text},
}
case REASON_SPAM:
reason = &mtproto.ReportReason{
Expand Down
38 changes: 25 additions & 13 deletions biz/core/account/notify_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
base2 "github.com/nebulaim/telegramd/baselib/base"
"github.com/nebulaim/telegramd/biz/base"
"github.com/nebulaim/telegramd/biz/dal/dataobject"
// "github.com/nebulaim/telegramd/proto/mtproto"
"github.com/nebulaim/telegramd/proto/mtproto"
)

Expand All @@ -30,27 +31,38 @@ func (m *AccountModel) GetNotifySettings(userId int32, peer *base.PeerUtil) *mtp
// var mute_until int32 = 0
if do == nil {
settings := &mtproto.TLPeerNotifySettings{Data2: &mtproto.PeerNotifySettings_Data{
ShowPreviews: true,
Silent: false,
MuteUntil: 0,
//ShowPreviews: mtproto.ToBool(false),
//Silent: mtproto.ToBool(false),
MuteUntil: 1,
Sound: "default",
}}
return settings.To_PeerNotifySettings()
} else {
settings := &mtproto.TLPeerNotifySettings{Data2: &mtproto.PeerNotifySettings_Data{
ShowPreviews: do.ShowPreviews == 1,
Silent: do.Silent == 1,
MuteUntil: do.MuteUntil,
Sound: do.Sound,
}}
settings := mtproto.NewTLPeerNotifySettings()
if do.ShowPreviews == 1 {
settings.SetShowPreviews(mtproto.ToBool(true))
}
if do.Silent == 1 {
settings.SetSilent(mtproto.ToBool(true))
}
if do.MuteUntil == 0 {
settings.SetMuteUntil(1)
} else {
settings.SetMuteUntil(do.MuteUntil)
}
if do.Sound == "" {
settings.SetSound("default")
} else {
settings.SetSound(do.Sound)
}
return settings.To_PeerNotifySettings()
}
}

func (m *AccountModel) SetNotifySettings(userId int32, peer *base.PeerUtil, settings *mtproto.TLInputPeerNotifySettings) {
var (
showPreviews = base2.BoolToInt8(settings.GetShowPreviews())
silent = base2.BoolToInt8(settings.GetSilent())
showPreviews = base2.BoolToInt8(mtproto.FromBool(settings.GetShowPreviews()))
silent = base2.BoolToInt8(mtproto.FromBool(settings.GetSilent()))
)

do := m.dao.UserNotifySettingsDAO.SelectByPeer(userId, int8(peer.PeerType), peer.PeerId)
Expand All @@ -76,13 +88,13 @@ func (m *AccountModel) ResetNotifySettings(userId int32) {
if do == nil {
do = &dataobject.UserNotifySettingsDO{}
do.UserId = userId
do.PeerType = base.PEER_ALL
// do.PeerType = base.PEER_ALL
do.PeerId = 0
do.ShowPreviews = 1
do.Silent = 0
do.MuteUntil = 0
m.dao.UserNotifySettingsDAO.Insert(do)
} else {
m.dao.UserNotifySettingsDAO.UpdateByPeer(1, 0, 0, "default", 0, userId, base.PEER_ALL, 0)
m.dao.UserNotifySettingsDAO.UpdateByPeer(1, 0, 0, "default", 0, userId, base.PEER_USER, 0)
}
}
64 changes: 32 additions & 32 deletions biz/core/account/password_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,38 +189,38 @@ func (p *passwordData) getHasRecovery() *mtproto.Bool {

func (p *passwordData) GetPassword() *mtproto.Account_Password {
switch p.state {
case kStatePasswordNone:
noPassword := &mtproto.TLAccountNoPassword{Data2: &mtproto.Account_Password_Data{
NewSalt: p.serverSalt,
EmailUnconfirmedPattern: "",
}}
return noPassword.To_Account_Password()
case kStateNoRecoveryPassword:
password := &mtproto.TLAccountPassword{Data2: &mtproto.Account_Password_Data{
NewSalt: p.serverSalt,
CurrentSalt: p.salt,
Hint: p.hint,
HasRecovery: mtproto.ToBool(false),
// TODO(@benqi): make pattern
EmailUnconfirmedPattern: "",
}}
return password.To_Account_Password()
case kStateEmailUnconfirmedPassword:
noPassword := &mtproto.TLAccountNoPassword{Data2: &mtproto.Account_Password_Data{
NewSalt: p.serverSalt,
EmailUnconfirmedPattern: makeEMailPattern(p.email),
}}
return noPassword.To_Account_Password()
case kStateConfirmedPassword:
password := &mtproto.TLAccountPassword{Data2: &mtproto.Account_Password_Data{
NewSalt: p.serverSalt,
CurrentSalt: p.salt,
Hint: p.hint,
HasRecovery: mtproto.ToBool(true),
// TODO(@benqi): make pattern
EmailUnconfirmedPattern: "",
}}
return password.To_Account_Password()
//case kStatePasswordNone:
// noPassword := &mtproto.TLAccountNoPassword{Data2: &mtproto.Account_Password_Data{
// NewSalt: p.serverSalt,
// EmailUnconfirmedPattern: "",
// }}
// return noPassword.To_Account_Password()
//case kStateNoRecoveryPassword:
// password := &mtproto.TLAccountPassword{Data2: &mtproto.Account_Password_Data{
// NewSalt: p.serverSalt,
// CurrentSalt: p.salt,
// Hint: p.hint,
// HasRecovery: mtproto.ToBool(false),
// // TODO(@benqi): make pattern
// EmailUnconfirmedPattern: "",
// }}
// return password.To_Account_Password()
//case kStateEmailUnconfirmedPassword:
// noPassword := &mtproto.TLAccountNoPassword{Data2: &mtproto.Account_Password_Data{
// NewSalt: p.serverSalt,
// EmailUnconfirmedPattern: makeEMailPattern(p.email),
// }}
// return noPassword.To_Account_Password()
//case kStateConfirmedPassword:
// password := &mtproto.TLAccountPassword{Data2: &mtproto.Account_Password_Data{
// NewSalt: p.serverSalt,
// CurrentSalt: p.salt,
// Hint: p.hint,
// HasRecovery: mtproto.ToBool(true),
// // TODO(@benqi): make pattern
// EmailUnconfirmedPattern: "",
// }}
// return password.To_Account_Password()
default:
// bug.
err := mtproto.NewRpcError2(mtproto.TLRpcErrorCodes_INTERNAL_SERVER_ERROR)
Expand Down
Loading

0 comments on commit 1897f2b

Please sign in to comment.