Skip to content

Commit

Permalink
channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Haupc committed Apr 16, 2021
1 parent 09350ed commit d08e3f8
Show file tree
Hide file tree
Showing 41 changed files with 3,243 additions and 1,854 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0
github.com/jmoiron/sqlx v1.2.0
github.com/nyaruka/phonenumbers v1.0.55
github.com/stretchr/testify v1.4.0
go.etcd.io/etcd v0.0.0-20190917205325-a14579fbfb1a
go.uber.org/atomic v1.4.0
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2
google.golang.org/grpc v1.26.0
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127
)
44 changes: 44 additions & 0 deletions go.sum

Large diffs are not rendered by default.

59 changes: 30 additions & 29 deletions messenger/biz_server/biz/core/channel/channel_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/golang/glog"
"github.com/nebula-chat/chatengine/messenger/biz_server/biz/base"
"github.com/nebula-chat/chatengine/messenger/biz_server/biz/core"
"github.com/nebula-chat/chatengine/messenger/biz_server/biz/dal/dataobject"
"github.com/nebula-chat/chatengine/mtproto"
Expand All @@ -49,8 +50,8 @@ type channelLogicData struct {
cacheParticipantsData []channelParticipantData
dao *channelsDAO
cb core.PhotoCallback
// cb2 core.NotifySettingCallback
cb3 core.UsernameCallback
cb2 core.NotifySettingCallback
cb3 core.UsernameCallback
}

//func (m *ChannelModel) MakeChannelLogic(channelId int32) (channelData *channelLogicData) {
Expand All @@ -76,8 +77,8 @@ func (m *ChannelModel) NewChannelLogicById(channelId int32) (channelData2 *chann
cacheParticipantsData: make([]channelParticipantData, 0, 2),
dao: m.dao,
cb: m.photoCallback,
// cb2: m.notifySettingCallback,
cb3: m.usernameCallback,
cb2: m.notifySettingCallback,
cb3: m.usernameCallback,
}
}
return
Expand All @@ -103,8 +104,8 @@ func (m *ChannelModel) NewChannelLogicByLink(link string) (channelData2 *channel
cacheParticipantsData: make([]channelParticipantData, 0, 2),
dao: m.dao,
cb: m.photoCallback,
// cb2: m.notifySettingCallback,
cb3: m.usernameCallback,
cb2: m.notifySettingCallback,
cb3: m.usernameCallback,
}
}
return
Expand Down Expand Up @@ -167,8 +168,8 @@ func (m *ChannelModel) NewChannelLogicByCreateChannel(creatorId int32, broadcast
cacheParticipantsData: []channelParticipantData{channelParticipantData2},
dao: m.dao,
cb: m.photoCallback,
// cb2: m.notifySettingCallback,
cb3: m.usernameCallback,
cb2: m.notifySettingCallback,
cb3: m.usernameCallback,
}

return channelData, nil
Expand Down Expand Up @@ -1054,27 +1055,27 @@ func (m *channelLogicData) ToChannelForbidden() *mtproto.Chat {
}

func (m *channelLogicData) ToChannelFull(selfUserId int32) *mtproto.ChatFull {
// peer := &base.PeerUtil{
// PeerType: base.PEER_CHANNEL,
// PeerId: m.Id,
// }
peer := &base.PeerUtil{
PeerType: base.PEER_CHANNEL,
PeerId: m.Id,
}

// var notifySettings *mtproto.PeerNotifySettings
var notifySettings *mtproto.PeerNotifySettings

// TODO(@benqi): chat notifySetting...
//if notifySettingFunc == nil {
// notifySettings = &mtproto.PeerNotifySettings{
// Constructor: mtproto.TLConstructor_CRC32_peerNotifySettings,
// Data2: &mtproto.PeerNotifySettings_Data{
// ShowPreviews: true,
// Silent: false,
// MuteUntil: 0,
// Sound: "default",
// },
// }
//} else {
// notifySettings := m.cb2.GetNotifySettings(selfUserId, peer)
//}
if m.cb2 == nil {
notifySettings = &mtproto.PeerNotifySettings{
Constructor: mtproto.TLConstructor_CRC32_peerNotifySettings,
Data2: &mtproto.PeerNotifySettings_Data{
ShowPreviews: mtproto.ToBool(true),
Silent: mtproto.ToBool(false),
MuteUntil: 0,
Sound: "default",
},
}
} else {
notifySettings = m.cb2.GetNotifySettings(selfUserId, peer)
}

channelFull := &mtproto.TLChannelFull{Data2: &mtproto.ChatFull_Data{
// CanViewParticipants:
Expand All @@ -1083,9 +1084,9 @@ func (m *channelLogicData) ToChannelFull(selfUserId int32) *mtproto.ChatFull {
ParticipantsCount: m.ParticipantCount,
AdminsCount: 1, // TODO(@benqi): calc adminscount
ChatPhoto: m.getPhoto(),
// NotifySettings: notifySettings,
// ExportedInvite: mtproto.NewTLChatInviteEmpty().To_ExportedChatInvite(), // TODO(@benqi):
BotInfo: []*mtproto.BotInfo{},
NotifySettings: notifySettings,
ExportedInvite: mtproto.NewTLChatInviteEmpty().To_ExportedChatInvite(), // TODO(@benqi):
BotInfo: []*mtproto.BotInfo{},
}}

selfParticipant := m.checkOrLoadChannelParticipant(selfUserId)
Expand Down
16 changes: 8 additions & 8 deletions messenger/biz_server/biz/core/channel/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ type channelsDAO struct {
}

type ChannelModel struct {
dao *channelsDAO
photoCallback core.PhotoCallback
// notifySettingCallback core.NotifySettingCallback
dialogCallback core.DialogCallback
usernameCallback core.UsernameCallback
dao *channelsDAO
photoCallback core.PhotoCallback
notifySettingCallback core.NotifySettingCallback
dialogCallback core.DialogCallback
usernameCallback core.UsernameCallback
}

func (m *ChannelModel) InstallModel() {
Expand All @@ -56,9 +56,9 @@ func (m *ChannelModel) RegisterCallback(cb interface{}) {
case core.PhotoCallback:
glog.Info("channelModel - register core.PhotoCallback")
m.photoCallback = cb.(core.PhotoCallback)
// case core.NotifySettingCallback:
// glog.Info("channelModel - register core.NotifySettingCallback")
// m.notifySettingCallback = cb.(core.NotifySettingCallback)
case core.NotifySettingCallback:
glog.Info("channelModel - register core.NotifySettingCallback")
m.notifySettingCallback = cb.(core.NotifySettingCallback)
case core.DialogCallback:
glog.Info("channelModel - register core.DialogCallback")
m.dialogCallback = cb.(core.DialogCallback)
Expand Down
8 changes: 4 additions & 4 deletions messenger/biz_server/biz/core/chat/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package chat

import (
"github.com/golang/glog"
"github.com/nebula-chat/chatengine/mtproto"
"github.com/nebula-chat/chatengine/messenger/biz_server/biz/base"
"github.com/nebula-chat/chatengine/messenger/biz_server/biz/core"
"github.com/nebula-chat/chatengine/messenger/biz_server/biz/dal/dao"
"github.com/nebula-chat/chatengine/messenger/biz_server/biz/dal/dao/mysql_dao"
"github.com/nebula-chat/chatengine/mtproto"
)

type chatsDAO struct {
Expand All @@ -34,8 +34,8 @@ type chatsDAO struct {
}

type ChatModel struct {
dao *chatsDAO
photoCallback core.PhotoCallback
dao *chatsDAO
photoCallback core.PhotoCallback
accountCallback core.AccountCallback
}

Expand Down Expand Up @@ -127,7 +127,7 @@ func (m *ChatModel) GetChatFullBySelfId(selfUserId int32, chatData *chatLogicDat
var exportedInvite *mtproto.ExportedChatInvite
if selfUserId == chatData.GetCreator() {
chatLink := chatData.GetLink()
if chatLink == ""{
if chatLink == "" {
exportedInvite = mtproto.NewTLChatInviteEmpty().To_ExportedChatInvite()
} else {
inviteExported := &mtproto.TLChatInviteExported{Data2: &mtproto.ExportedChatInvite_Data{
Expand Down
10 changes: 5 additions & 5 deletions messenger/biz_server/biz/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package core

import (
base2 "github.com/nebula-chat/chatengine/pkg/util"
"github.com/nebula-chat/chatengine/messenger/biz_server/biz/base"
"github.com/nebula-chat/chatengine/mtproto"
"github.com/nebula-chat/chatengine/service/idgen/client"
base2 "github.com/nebula-chat/chatengine/pkg/util"
idgen "github.com/nebula-chat/chatengine/service/idgen/client"
)

const (
Expand Down Expand Up @@ -86,9 +86,9 @@ type AccountCallback interface {
GetNotifySettings(selfUserId int32, peer *base.PeerUtil) *mtproto.PeerNotifySettings
}

//type NotifySettingCallback interface {
// GetNotifySettings(selfUserId int32, peer *base.PeerUtil) *mtproto.PeerNotifySettings
//}
type NotifySettingCallback interface {
GetNotifySettings(selfUserId int32, peer *base.PeerUtil) *mtproto.PeerNotifySettings
}

type PhotoCallback interface {
GetUserProfilePhoto(photoId int64) *mtproto.UserProfilePhoto
Expand Down
30 changes: 16 additions & 14 deletions messenger/biz_server/biz/core/dialog/dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package dialog

import (
"encoding/json"

"github.com/nebula-chat/chatengine/messenger/biz_server/biz/base"
"github.com/nebula-chat/chatengine/messenger/biz_server/biz/core"
"github.com/nebula-chat/chatengine/messenger/biz_server/biz/dal/dataobject"
"github.com/nebula-chat/chatengine/mtproto"
base2 "github.com/nebula-chat/chatengine/pkg/util"
Expand Down Expand Up @@ -78,26 +80,26 @@ func dialogDOToDialog(dialogDO *dataobject.UserDialogsDO) *mtproto.TLDialog {
}

func (m *DialogModel) dialogDOListToDialogList(dialogDOList []dataobject.UserDialogsDO) (dialogs []*mtproto.Dialog) {
//channelIdList := make([]int32, 0, len(dialogDOList))
channelIdList := make([]int32, 0, len(dialogDOList))
for i := 0; i < len(dialogDOList); i++ {
//if dialogDO.DraftId > 0 {
// draftIdList = append(draftIdList, dialogDO.DraftId)
//}
// if dialogDO.DraftId > 0 {
// draftIdList = append(draftIdList, dialogDO.DraftId)
// }
dialogDO := &dialogDOList[i]
dialog := dialogDOToDialog(dialogDO)
//if dialogDO.PeerType == base.PEER_CHANNEL {
// channelIdList = append(channelIdList, dialogDO.PeerId)
//}
if dialogDO.PeerType == base.PEER_CHANNEL {
channelIdList = append(channelIdList, dialogDO.PeerId)
}
dialogs = append(dialogs, dialog.To_Dialog())
}

////topMessageMap := m.channelCallback.GetTopMessageListByIdList(channelIdList)
//for _, dialog := range dialogs {
// if dialog.Data2.Peer.GetConstructor() == mtproto.TLConstructor_CRC32_peerChannel {
// dialog.Data2.TopMessage = topMessageMap[dialog.Data2.Peer.Data2.ChannelId]
// dialog.Data2.Pts = int32(core.NextChannelPtsId(dialog.Data2.Peer.Data2.ChannelId))
// }
//}
topMessageMap := m.channelCallback.GetTopMessageListByIdList(channelIdList)
for _, dialog := range dialogs {
if dialog.Data2.Peer.GetConstructor() == mtproto.TLConstructor_CRC32_peerChannel {
dialog.Data2.TopMessage = topMessageMap[dialog.Data2.Peer.Data2.ChannelId]
dialog.Data2.Pts = int32(core.CurrentChannelPtsId(dialog.Data2.Peer.Data2.ChannelId))
}
}

// TODO(@benqi): fetch draft message list
return
Expand Down
7 changes: 4 additions & 3 deletions messenger/biz_server/biz/core/dialog/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
package dialog

import (
"time"

"github.com/golang/glog"
"github.com/nebula-chat/chatengine/messenger/biz_server/biz/core"
"github.com/nebula-chat/chatengine/messenger/biz_server/biz/dal/dao"
"github.com/nebula-chat/chatengine/messenger/biz_server/biz/dal/dao/mysql_dao"
"github.com/nebula-chat/chatengine/messenger/biz_server/biz/dal/dataobject"
"time"
)

type dialogsDAO struct {
Expand Down Expand Up @@ -90,12 +91,12 @@ func (m *DialogModel) InsertOrUpdateDialog(userId, peerType, peerId, topMessage
m.dao.UserDialogsDAO.InsertOrUpdate(dialogDO)
}

func (m *DialogModel) InsertOrChannelUpdateDialog(userId, peerType, peerId int32) {
func (m *DialogModel) InsertOrChannelUpdateDialog(userId, peerType, peerId, top_message int32) {
dialogDO := &dataobject.UserDialogsDO{
UserId: userId,
PeerType: int8(peerType),
PeerId: peerId,
TopMessage: 0,
TopMessage: top_message,
Date2: int32(time.Now().Unix()),
UnreadCount: 0,
UnreadMentionsCount: 0,
Expand Down
Loading

0 comments on commit d08e3f8

Please sign in to comment.