/
dialog.editPeerFolders_handler.go
97 lines (86 loc) · 2.61 KB
/
dialog.editPeerFolders_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
/*
* Created from 'scheme.tl' by 'mtprotoc'
*
* Copyright (c) 2021-present, Teamgram Studio (https://teamgram.io).
* All rights reserved.
*
* Author: teamgramio (teamgram.io@gmail.com)
*/
package core
import (
"sort"
"github.com/teamgram/proto/mtproto"
"github.com/teamgram/teamgram-server/app/service/biz/dialog/dialog"
"github.com/teamgram/teamgram-server/app/service/biz/dialog/internal/dal/dataobject"
)
// DialogEditPeerFolders
// dialog.editPeerFolders user_id:long peer_dialog_list:Vector<long> folder_id:int = Vector<DialogPinnedExt>;
func (c *DialogCore) DialogEditPeerFolders(in *dialog.TLDialogEditPeerFolders) (*dialog.Vector_DialogPinnedExt, error) {
var (
dialogPinnedList dialog.DialogPinnedExtList
)
c.svcCtx.Dao.DialogsDAO.SelectPeerDialogListWithCB(c.ctx,
in.UserId,
in.PeerDialogList,
func(i int, v *dataobject.DialogsDO) {
if in.FolderId == 0 {
if v.Pinned > 0 {
dialogPinnedList = append(dialogPinnedList, &dialog.DialogPinnedExt{
Order: v.Pinned,
PeerType: v.PeerType,
PeerId: v.PeerId,
})
}
} else {
if v.FolderPinned > 0 {
dialogPinnedList = append(dialogPinnedList, &dialog.DialogPinnedExt{
Order: v.FolderPinned,
PeerType: v.PeerType,
PeerId: v.PeerId,
})
}
}
})
if len(dialogPinnedList) > 0 {
if in.FolderId == 0 {
c.svcCtx.Dao.DialogsDAO.SelectPinnedDialogsWithCB(c.ctx,
in.UserId,
func(i int, v *dataobject.DialogsDO) {
dialogPinnedList = append(dialogPinnedList, &dialog.DialogPinnedExt{
Order: v.FolderPinned,
PeerType: v.PeerType,
PeerId: v.PeerId,
})
})
} else {
c.svcCtx.Dao.DialogsDAO.SelectFolderPinnedDialogsWithCB(c.ctx,
in.UserId,
func(i int, v *dataobject.DialogsDO) {
dialogPinnedList = append(dialogPinnedList, &dialog.DialogPinnedExt{
Order: v.FolderPinned,
PeerType: v.PeerType,
PeerId: v.PeerId,
})
})
}
}
sd := sort.Reverse(dialogPinnedList)
sort.Sort(sd)
// update
c.svcCtx.Dao.DialogsDAO.UpdatePeerDialogListFolderId(c.ctx, in.FolderId, in.UserId, in.PeerDialogList)
if in.FolderId == 0 {
// cut
if len(dialogPinnedList) > 5 {
unpinnedList := make([]int64, 0, len(dialogPinnedList)-5)
for i := 5; i < len(dialogPinnedList); i++ {
unpinnedList = append(unpinnedList, mtproto.MakePeerDialogId(dialogPinnedList[i].PeerType, dialogPinnedList[i].PeerId))
}
//
c.svcCtx.Dao.DialogsDAO.UpdatePeerDialogListPinned(c.ctx, 0, in.UserId, unpinnedList)
dialogPinnedList = dialogPinnedList[:5]
}
}
return &dialog.Vector_DialogPinnedExt{
Datas: dialogPinnedList,
}, nil
}