Skip to content

Commit e48975c

Browse files
committed
Merge branch 'tuoyun'
2 parents dc5f874 + 575c454 commit e48975c

File tree

9 files changed

+58
-15
lines changed

9 files changed

+58
-15
lines changed

internal/conversation_msg/conversation.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (c *Conversation) revokeOneMessage(callback open_im_sdk_callback.Base, req
251251
switch req.SessionType {
252252
case constant.SingleChatType:
253253
recvID = req.RecvID
254-
conversationID = utils.GetConversationIDBySessionType(groupID, constant.SingleChatType)
254+
conversationID = utils.GetConversationIDBySessionType(recvID, constant.SingleChatType)
255255
case constant.GroupChatType:
256256
groupID = req.GroupID
257257
conversationID = utils.GetConversationIDBySessionType(groupID, constant.GroupChatType)
@@ -261,7 +261,11 @@ func (c *Conversation) revokeOneMessage(callback open_im_sdk_callback.Base, req
261261
req.Content = message.ClientMsgID
262262
req.ClientMsgID = utils.GetMsgID(message.SendID)
263263
req.ContentType = constant.Revoke
264+
req.SendTime = 0
265+
req.CreateTime = utils.GetCurrentTimestampByMill()
264266
options := make(map[string]bool, 5)
267+
utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
268+
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false)
265269
resp, _ := c.internalSendMessage(callback, (*sdk_struct.MsgStruct)(&req), recvID, groupID, operationID, &server_api_params.OfflinePushInfo{}, false, options)
266270
req.ServerMsgID = resp.ServerMsgID
267271
req.SendTime = resp.SendTime

internal/conversation_msg/conversation_msg.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ func (c *Conversation) doUpdateConversation(c2v common.Cmd2Value) {
445445
lc := node.Args.(db.LocalConversation)
446446
oc, err := c.db.GetConversation(lc.ConversationID)
447447
if err == nil {
448-
log.Info("this is old conversation", oc)
448+
log.Info("this is old conversation", *oc)
449449
if lc.LatestMsgSendTime >= oc.LatestMsgSendTime { //The session update of asynchronous messages is subject to the latest sending time
450450
err := c.db.UpdateColumnsConversation(node.ConID, map[string]interface{}{"latest_msg_send_time": lc.LatestMsgSendTime, "latest_msg": lc.LatestMsg})
451451
if err != nil {
@@ -458,6 +458,7 @@ func (c *Conversation) doUpdateConversation(c2v common.Cmd2Value) {
458458
}
459459
}
460460
} else {
461+
log.Info("this is new conversation", lc)
461462
err4 := c.db.InsertConversation(&lc)
462463
if err4 != nil {
463464
log.Error("internal", "insert new conversation err:", err4.Error())

pkg/common/check.go

-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package common
33
import (
44
"encoding/json"
55
"errors"
6-
"fmt"
76
"github.com/go-playground/validator/v10"
87
"github.com/mitchellh/mapstructure"
98
"open_im_sdk/open_im_sdk_callback"
@@ -98,7 +97,6 @@ func CheckErrAndResp(err error, resp []byte, output interface{}) error {
9897
var c2 server_api_params.CommDataRespOne
9998

10099
err = json.Unmarshal(resp, &c2)
101-
fmt.Println("CommDataRespOne ", string(resp), c2)
102100
if err != nil {
103101
return utils.Wrap(err, "")
104102
}
@@ -107,7 +105,6 @@ func CheckErrAndResp(err error, resp []byte, output interface{}) error {
107105
}
108106
if output != nil {
109107
err = mapstructure.Decode(c2.Data, output)
110-
fmt.Println("CommDataRespOne2 ", c2.Data)
111108
if err != nil {
112109
return utils.Wrap(err, "")
113110
}

pkg/constant/constant.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,6 @@ const (
216216
Female = 2
217217
)
218218

219-
const BigVersion = "3"
219+
const BigVersion = "v2"
220220
const UpdateVersion = ".0.0"
221-
const SdkVersion = "Open-IM-SDK-Core-v"
221+
const SdkVersion = "Open-IM-SDK-Core-"

pkg/db/chat_log_model.go

+16
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func (d *DataBase) SearchMessageByKeyword(keyword string, startTime, endTime int
4949
}
5050
return result, err
5151
}
52+
5253
func (d *DataBase) BatchUpdateMessageList(MessageList []*LocalChatLog) error {
5354
if MessageList == nil {
5455
return nil
@@ -67,6 +68,7 @@ func (d *DataBase) BatchUpdateMessageList(MessageList []*LocalChatLog) error {
6768
}
6869
return nil
6970
}
71+
7072
func (d *DataBase) MessageIfExists(ClientMsgID string) (bool, error) {
7173
d.mRWMutex.Lock()
7274
defer d.mRWMutex.Unlock()
@@ -150,6 +152,7 @@ func (d *DataBase) UpdateMessageTimeAndStatus(clientMsgID string, serverMsgID st
150152
}
151153
return utils.Wrap(t.Error, "UpdateMessageStatusBySourceID failed")
152154
}
155+
153156
func (d *DataBase) GetMessageList(sourceID string, sessionType, count int, startTime int64) (result []*LocalChatLog, err error) {
154157
d.mRWMutex.Lock()
155158
defer d.mRWMutex.Unlock()
@@ -168,6 +171,19 @@ func (d *DataBase) GetMessageList(sourceID string, sessionType, count int, start
168171
}
169172
return result, err
170173
}
174+
175+
func (d *DataBase) GetSendingMessageList() (result []*LocalChatLog, err error) {
176+
d.mRWMutex.Lock()
177+
defer d.mRWMutex.Unlock()
178+
var messageList []LocalChatLog
179+
err = utils.Wrap(d.conn.Where("status = ?", constant.MsgStatusSendFailed).Find(&messageList).Error, "GetMessageList failed")
180+
for _, v := range messageList {
181+
v1 := v
182+
result = append(result, &v1)
183+
}
184+
return result, err
185+
}
186+
171187
func (d *DataBase) UpdateMessageHasRead(sendID string, msgIDList []string) error {
172188
d.mRWMutex.Lock()
173189
defer d.mRWMutex.Unlock()

pkg/db/data_model_struct.go

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type LocalFriend struct {
4242
Birth uint32 `gorm:"column:birth" json:"birth"`
4343
Email string `gorm:"column:email;type:varchar(64)" json:"email"`
4444
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
45+
AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
4546
}
4647

4748
//message FriendRequest{
@@ -74,6 +75,8 @@ type LocalFriendRequest struct {
7475
HandleMsg string `gorm:"column:handle_msg;type:varchar(255)" json:"handleMsg"`
7576
HandleTime uint32 `gorm:"column:handle_time" json:"handleTime"`
7677
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
78+
79+
AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
7780
}
7881

7982
//message GroupInfo{
@@ -119,6 +122,7 @@ type LocalGroup struct {
119122
OwnerUserID string `gorm:"column:owner_user_id;type:varchar(64)" json:"ownerUserID"`
120123
MemberCount int32 `gorm:"column:member_count" json:"memberCount"`
121124
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
125+
AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
122126
}
123127

124128
//message GroupMemberFullInfo {
@@ -152,6 +156,7 @@ type LocalGroupMember struct {
152156
JoinSource int32 `gorm:"column:join_source" json:"joinSource"`
153157
OperatorUserID string `gorm:"column:operator_user_id;type:varchar(64)" json:"operatorUserID"`
154158
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
159+
AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
155160
}
156161

157162
//message GroupRequest{
@@ -190,6 +195,7 @@ type LocalGroupRequest struct {
190195
HandleUserID string `gorm:"column:handle_user_id;type:varchar(64)" json:"handleUserID"`
191196
HandledTime uint32 `gorm:"column:handle_time" json:"handledTime"`
192197
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
198+
AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
193199
}
194200

195201
//string UserID = 1;
@@ -214,6 +220,7 @@ type LocalUser struct {
214220
CreateTime uint32 `gorm:"column:create_time" json:"createTime"`
215221
AppMangerLevel int32 `gorm:"column:app_manger_level" json:"-"`
216222
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
223+
AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
217224
}
218225

219226
//message BlackInfo{
@@ -235,6 +242,7 @@ type LocalBlack struct {
235242
AddSource int32 `gorm:"column:add_source" json:"addSource"`
236243
OperatorUserID string `gorm:"column:operator_user_id;type:varchar(64)" json:"operatorUserID"`
237244
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
245+
AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
238246
}
239247

240248
type LocalSeqData struct {

pkg/db/db_init.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,28 @@ type DataBase struct {
1919

2020
func NewDataBase(loginUserID string, dbDir string) (*DataBase, error) {
2121
dataBase := &DataBase{loginUserID: loginUserID, dbDir: dbDir}
22-
return dataBase, utils.Wrap(dataBase.initDB(), "db init error")
22+
err := dataBase.initDB()
23+
if err != nil {
24+
return dataBase, utils.Wrap(err, "initDB failed")
25+
}
26+
dataBase.setChatLogFailedStatus()
27+
return dataBase, nil
28+
}
29+
30+
func (d *DataBase) setChatLogFailedStatus() {
31+
msgList, err := d.GetSendingMessageList()
32+
if err != nil {
33+
log.Error("", "GetSendingMessageList failed ", err.Error())
34+
return
35+
}
36+
for _, v := range msgList {
37+
v.Status = constant.MsgStatusSendFailed
38+
err := d.UpdateMessage(v)
39+
if err != nil {
40+
log.Error("", "UpdateMessage failed ", err.Error(), v)
41+
continue
42+
}
43+
}
2344
}
2445

2546
func (d *DataBase) initDB() error {
@@ -29,7 +50,7 @@ func (d *DataBase) initDB() error {
2950
d.mRWMutex.Lock()
3051
defer d.mRWMutex.Unlock()
3152

32-
dbFileName := d.dbDir + "OpenIM_" + "v" + constant.BigVersion + "_" + d.loginUserID + ".db"
53+
dbFileName := d.dbDir + "OpenIM_" + constant.BigVersion + "_" + d.loginUserID + ".db"
3354
db, err := gorm.Open(sqlite.Open(dbFileName), &gorm.Config{})
3455
log.Info("open db:", dbFileName)
3556
if err != nil {

pkg/network/http_client.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import (
44
"bytes"
55
"encoding/json"
66
"errors"
7-
"fmt"
87

9-
//"fmt"
10-
11-
//"fmt"
128
"io/ioutil"
139
"net/http"
1410
"open_im_sdk/pkg/utils"
@@ -78,6 +74,6 @@ func postLogic(url string, data interface{}, token string) (content []byte, err
7874
if err != nil {
7975
return nil, utils.Wrap(err, "ioutil.ReadAll failed, url")
8076
}
81-
fmt.Println(url, "Marshal data: ", string(jsonStr), string(result))
77+
// fmt.Println(url, "Marshal data: ", string(jsonStr), string(result))
8278
return result, nil
8379
}

sdk_struct/sdk_struct.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ type MsgStruct struct {
893893
NotificationElem struct {
894894
Detail string `json:"detail"`
895895
DefaultTips string `json:"defaultTips"`
896-
}
896+
} `json:"notificationElem"`
897897
//RevokeMessage struct {
898898
// ServerMsgID string `json:"serverMsgID"`
899899
// SendID string `json:"sendID"`

0 commit comments

Comments
 (0)