Skip to content

Commit 8a4507e

Browse files
committed
fix bug: Status of the message
1 parent 095a0dd commit 8a4507e

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

pkg/db/chat_log_model.go

Lines changed: 16 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 22 additions & 1 deletion
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 {

0 commit comments

Comments
 (0)