Skip to content

Commit

Permalink
feat: fix getDialogs bug
Browse files Browse the repository at this point in the history
  • Loading branch information
teamgramio committed Mar 13, 2023
1 parent 9461bd1 commit 420fdae
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 227 deletions.
26 changes: 13 additions & 13 deletions app/messenger/msg/internal/dao/outbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ import (
"errors"
"fmt"
idgen_client "github.com/teamgram/teamgram-server/app/service/idgen/client"
"math"
"time"

"github.com/zeromicro/go-zero/core/jsonx"
"github.com/zeromicro/go-zero/core/logx"
"math"
"time"

"github.com/teamgram/marmota/pkg/hack"
"github.com/teamgram/marmota/pkg/stores/sqlx"
Expand Down Expand Up @@ -132,7 +131,7 @@ func (d *Dao) sendMessageToOutbox(ctx context.Context, fromId int64, peer *mtpro
Message: message.Message,
Mentioned: false,
MediaUnread: message.MediaUnread,
Date2: time.Now().Unix(),
Date2: int64(outMsgBox.Message.Date),
Deleted: false,
}

Expand Down Expand Up @@ -167,7 +166,7 @@ func (d *Dao) sendMessageToOutbox(ctx context.Context, fromId int64, peer *mtpro
TopMessage: outBoxMsgId,
UnreadCount: 0,
DraftMessageData: "null",
Date2: time.Now().Unix(),
Date2: int64(outMsgBox.Message.Date),
}
if dialogMessageId > 1 {
//// if box_id > 1, then dialogs already created.
Expand Down Expand Up @@ -214,7 +213,7 @@ func (d *Dao) sendMessageToOutbox(ctx context.Context, fromId int64, peer *mtpro
TopMessage: outBoxMsgId,
UnreadCount: 0,
DraftMessageData: "null",
Date2: time.Now().Unix(),
Date2: int64(outMsgBox.Message.Date),
}

if dialogMessageId > 1 {
Expand Down Expand Up @@ -401,14 +400,14 @@ func (d *Dao) DeleteMessages(ctx context.Context, userId int64, msgIds []int32)
topMessageIndex = math.MaxInt32
}

getLastTopMessage := func(topMessage2 int32) int32 {
getLastTopMessage := func(topMessage2 int32) (int32, int64) {
for i := 0; i < len(topMessageDOList); i++ {
if topMessageDOList[i].UserMessageBoxId >= topMessage2 {
continue
}
return topMessageDOList[i].UserMessageBoxId
return topMessageDOList[i].UserMessageBoxId, topMessageDOList[i].Date2
}
return 0
return 0, 0
}

//_, err = d.DialogsDAO.SelectDialogsWithCB().SelectByPeer(ctx, userId, model.GetPeerIdByDialogId(userId, dialogId))
Expand All @@ -417,7 +416,7 @@ func (d *Dao) DeleteMessages(ctx context.Context, userId int64, msgIds []int32)
//}

for i := 0; i < len(msgDOList); i++ {
topMessage := getLastTopMessage(topMessageIndex)
topMessage, _ := getLastTopMessage(topMessageIndex)
if topMessage == msgDOList[i].UserMessageBoxId {
topMessageIndex = topMessage
}
Expand All @@ -430,9 +429,10 @@ func (d *Dao) DeleteMessages(ctx context.Context, userId int64, msgIds []int32)
if result.Err != nil {
return
}

d.DialogsDAO.UpdateOutboxDialogTx(tx,
getLastTopMessage(topMessageIndex),
topMessage, _ := getLastTopMessage(topMessageIndex)
d.DialogsDAO.UpdateOutboxDialogTx(
tx,
topMessage,
time.Now().Unix(),
userId,
peer.PeerType,
Expand Down
6 changes: 3 additions & 3 deletions app/service/biz/dialog/dialog/class_name_registers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WARNING! All changes made in this file will be lost!
* Created from 'scheme.tl' by 'mtprotoc'
*
* Copyright (c) 2022-present, Teamgram Authors.
* Copyright (c) 2023-present, Teamgram Authors.
* All rights reserved.
*
* Author: Benqi ([email protected])
Expand Down Expand Up @@ -139,7 +139,7 @@ var clazzNameRegisters2 = map[string]map[int]int32{

},
Predicate_dialog_insertOrUpdateDialog: {
0: -317723281, // 0xed0fed6f
0: 382601889, // 0x16ce0aa1

},
Predicate_dialog_deleteDialog: {
Expand Down Expand Up @@ -219,7 +219,7 @@ var clazzIdNameRegisters2 = map[int32]string{
-92425614: Predicate_dialog_getTopMessage, // 0xfa7db272
489158840: Predicate_dialog_updateReadInbox, // 0x1d27f8b8
1483799934: Predicate_dialog_updateReadOutbox, // 0x5870fd7e
-317723281: Predicate_dialog_insertOrUpdateDialog, // 0xed0fed6f
382601889: Predicate_dialog_insertOrUpdateDialog, // 0x16ce0aa1
28515811: Predicate_dialog_deleteDialog, // 0x1b31de3
-1885617487: Predicate_dialog_getUserPinnedMessage, // 0x8f9bc2b1
371388970: Predicate_dialog_updateUserPinnedMessage, // 0x1622f22a
Expand Down
21 changes: 16 additions & 5 deletions app/service/biz/dialog/dialog/codec_schema.tl.pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ var clazzIdRegisters2 = map[int32]func() mtproto.TLObject{
Constructor: 1483799934,
}
},
-317723281: func() mtproto.TLObject { // 0xed0fed6f
382601889: func() mtproto.TLObject { // 0x16ce0aa1
return &TLDialogInsertOrUpdateDialog{
Constructor: -317723281,
Constructor: 382601889,
}
},
28515811: func() mtproto.TLObject { // 0x1b31de3
Expand Down Expand Up @@ -1914,8 +1914,8 @@ func (m *TLDialogInsertOrUpdateDialog) Encode(layer int32) []byte {
// x.Int(int32(CRC32_dialog_insertOrUpdateDialog))

switch uint32(m.Constructor) {
case 0xed0fed6f:
x.UInt(0xed0fed6f)
case 0x16ce0aa1:
x.UInt(0x16ce0aa1)

// set flags
var flags uint32 = 0
Expand All @@ -1935,6 +1935,9 @@ func (m *TLDialogInsertOrUpdateDialog) Encode(layer int32) []byte {
if m.GetUnreadMark() == true {
flags |= 1 << 4
}
if m.GetDate2() != nil {
flags |= 1 << 5
}

x.UInt(flags)

Expand All @@ -1958,6 +1961,10 @@ func (m *TLDialogInsertOrUpdateDialog) Encode(layer int32) []byte {
x.Int(m.GetUnreadCount().Value)
}

if m.GetDate2() != nil {
x.Long(m.GetDate2().Value)
}

default:
// log.Errorf("")
}
Expand All @@ -1971,7 +1978,7 @@ func (m *TLDialogInsertOrUpdateDialog) CalcByteSize(layer int32) int {

func (m *TLDialogInsertOrUpdateDialog) Decode(dBuf *mtproto.DecodeBuf) error {
switch uint32(m.Constructor) {
case 0xed0fed6f:
case 0x16ce0aa1:

flags := dBuf.UInt()
_ = flags
Expand Down Expand Up @@ -1999,6 +2006,10 @@ func (m *TLDialogInsertOrUpdateDialog) Decode(dBuf *mtproto.DecodeBuf) error {
if (flags & (1 << 4)) != 0 {
m.UnreadMark = true
}
if (flags & (1 << 5)) != 0 {
m.Date2 = &types.Int64Value{Value: dBuf.Long()}
}

return dBuf.GetError()

default:
Expand Down
Loading

0 comments on commit 420fdae

Please sign in to comment.