-
Notifications
You must be signed in to change notification settings - Fork 1
/
messages.forwardMessage_handler.go
executable file
·101 lines (87 loc) · 3.84 KB
/
messages.forwardMessage_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Copyright (c) 2018, https://github.com/airwide-code/airwide.datacenter
* All rights reserved.
*
*
*
*/
package rpc
import (
"github.com/golang/glog"
"github.com/airwide-code/airwide.datacenter/baselib/logger"
"github.com/airwide-code/airwide.datacenter/baselib/grpc_util"
"github.com/airwide-code/airwide.datacenter/mtproto"
"github.com/airwide-code/airwide.datacenter/biz/base"
message2 "github.com/airwide-code/airwide.datacenter/biz/core/message"
"github.com/airwide-code/airwide.datacenter/biz/core/user"
"golang.org/x/net/context"
"github.com/airwide-code/airwide.datacenter/biz_server/sync_client"
)
// @benqi: android和pc客户端未发现会发送此消息
// messages.forwardMessage#33963bf9 peer:InputPeer id:int random_id:long = Updates;
func (s *MessagesServiceImpl) MessagesForwardMessage(ctx context.Context, request *mtproto.TLMessagesForwardMessage) (*mtproto.Updates, error) {
md := grpc_util.RpcMetadataFromIncoming(ctx)
glog.Infof("messages.forwardMessage#33963bf9 - metadata: %s, request: %s", logger.JsonDebugData(md), logger.JsonDebugData(request))
//// peer
var (
// fromPeer = helper.FromInputPeer2(md.UserId, request.GetFromPeer())
peer = base.FromInputPeer2(md.UserId, request.GetPeer())
messageOutboxList message2.MessageBoxList
)
// TODO(@benqi):
outboxMessages, ridList := makeForwardMessagesData(md.UserId, []int32{request.GetId()}, peer, []int64{request.GetRandomId()})
for i := 0; i < len(outboxMessages); i++ {
messageOutbox := message2.CreateMessageOutboxByNew(md.UserId, peer, ridList[i], outboxMessages[i], func(messageId int32) {
// 更新会话信息
user.CreateOrUpdateByOutbox(md.UserId, peer.PeerType, peer.PeerId, messageId, outboxMessages[i].GetData2().GetMentioned(), false)
})
messageOutboxList = append(messageOutboxList, messageOutbox)
}
syncUpdates := makeUpdateNewMessageListUpdates(md.UserId, messageOutboxList)
state, err := sync_client.GetSyncClient().SyncUpdatesData(md.AuthId, md.SessionId, md.UserId, syncUpdates.To_Updates())
if err != nil {
return nil, err
}
reply := SetupUpdatesState(state, syncUpdates)
updateList := []*mtproto.Update{}
for i := 0; i < len(messageOutboxList); i++ {
updateMessageID := &mtproto.TLUpdateMessageID{Data2: &mtproto.Update_Data{
Id_4: messageOutboxList[i].MessageId,
RandomId: ridList[i],
}}
updateList = append(updateList, updateMessageID.To_Update())
}
updateList = append(updateList, reply.GetUpdates()...)
reply.SetUpdates(updateList)
/////////////////////////////////////////////////////////////////////////////////////
// 收件箱
if request.GetPeer().GetConstructor() != mtproto.TLConstructor_CRC32_inputPeerSelf {
// var inBoxes message2.MessageBoxList
var inBoxeMap = map[int32][]*message2.MessageBox{}
for i := 0; i < len(outboxMessages); i++ {
inBoxes, _ := messageOutboxList[i].InsertMessageToInbox(md.UserId, peer, func(inBoxUserId, messageId int32) {
// 更新会话信息
switch peer.PeerType {
case base.PEER_USER:
user.CreateOrUpdateByInbox(inBoxUserId, peer.PeerType, md.UserId, messageId, outboxMessages[i].GetData2().GetMentioned())
case base.PEER_CHAT, base.PEER_CHANNEL:
user.CreateOrUpdateByInbox(inBoxUserId, peer.PeerType, peer.PeerId, messageId, outboxMessages[i].GetData2().GetMentioned())
}
})
for j := 0; j < len(inBoxes); j++ {
if boxList, ok := inBoxeMap[inBoxes[j].UserId]; !ok {
inBoxeMap[inBoxes[j].UserId] = []*message2.MessageBox{inBoxes[j]}
} else {
boxList = append(boxList, inBoxes[j])
inBoxeMap[inBoxes[j].UserId] = boxList
}
}
}
for k, v := range inBoxeMap {
syncUpdates = makeUpdateNewMessageListUpdates(k, v)
sync_client.GetSyncClient().PushToUserUpdatesData(k, syncUpdates.To_Updates())
}
}
glog.Infof("messages.forwardMessage#33963bf9 - reply: %s", logger.JsonDebugData(reply))
return reply.To_Updates(), nil
}