feat: incr sync version.
This commit is contained in:
144
go/chao-sdk-core/wasm/indexdb/black_model.go
Normal file
144
go/chao-sdk-core/wasm/indexdb/black_model.go
Normal file
@@ -0,0 +1,144 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/indexdb/temp_struct"
|
||||
)
|
||||
|
||||
type Black struct {
|
||||
loginUserID string
|
||||
}
|
||||
|
||||
func NewBlack(loginUserID string) *Black {
|
||||
return &Black{loginUserID: loginUserID}
|
||||
}
|
||||
|
||||
// GetBlackListDB gets the blacklist list from the database
|
||||
func (i Black) GetBlackListDB(ctx context.Context) (result []*model_struct.LocalBlack, err error) {
|
||||
gList, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp []model_struct.LocalBlack
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetBlackListUserID gets the list of blocked user IDs
|
||||
func (i Black) GetBlackListUserID(ctx context.Context) (result []string, err error) {
|
||||
gList, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetBlackInfoByBlockUserID gets the information of a blocked user by their user ID
|
||||
func (i Black) GetBlackInfoByBlockUserID(ctx context.Context, blockUserID string) (result *model_struct.LocalBlack, err error) {
|
||||
gList, err := exec.Exec(blockUserID, i.loginUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp model_struct.LocalBlack
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &temp, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetBlackInfoList gets the information of multiple blocked users by their user IDs
|
||||
func (i Black) GetBlackInfoList(ctx context.Context, blockUserIDList []string) (result []*model_struct.LocalBlack, err error) {
|
||||
gList, err := exec.Exec(utils.StructToJsonString(blockUserIDList))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp []model_struct.LocalBlack
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// InsertBlack inserts a new blocked user into the database
|
||||
func (i Black) InsertBlack(ctx context.Context, black *model_struct.LocalBlack) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(black))
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateBlack updates the information of a blocked user in the database
|
||||
func (i Black) UpdateBlack(ctx context.Context, black *model_struct.LocalBlack) error {
|
||||
tempLocalBlack := temp_struct.LocalBlack{
|
||||
Nickname: black.Nickname,
|
||||
FaceURL: black.FaceURL,
|
||||
CreateTime: black.CreateTime,
|
||||
AddSource: black.AddSource,
|
||||
OperatorUserID: black.OperatorUserID,
|
||||
Ex: black.Ex,
|
||||
AttachedInfo: black.AttachedInfo,
|
||||
}
|
||||
_, err := exec.Exec(black.OwnerUserID, black.BlockUserID, utils.StructToJsonString(tempLocalBlack))
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteBlack removes a blocked user from the database
|
||||
func (i Black) DeleteBlack(ctx context.Context, blockUserID string) error {
|
||||
_, err := exec.Exec(blockUserID, i.loginUserID)
|
||||
return err
|
||||
}
|
||||
45
go/chao-sdk-core/wasm/indexdb/cache_message.go
Normal file
45
go/chao-sdk-core/wasm/indexdb/cache_message.go
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
import (
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
)
|
||||
|
||||
type LocalCacheMessage struct {
|
||||
}
|
||||
|
||||
func NewLocalCacheMessage() *LocalCacheMessage {
|
||||
return &LocalCacheMessage{}
|
||||
}
|
||||
|
||||
func (i *LocalCacheMessage) BatchInsertTempCacheMessageList(ctx context.Context, MessageList []*model_struct.TempCacheLocalChatLog) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(MessageList))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalCacheMessage) InsertTempCacheMessage(ctx context.Context, Message *model_struct.TempCacheLocalChatLog) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(Message))
|
||||
return err
|
||||
}
|
||||
759
go/chao-sdk-core/wasm/indexdb/chat_log_model.go
Normal file
759
go/chao-sdk-core/wasm/indexdb/chat_log_model.go
Normal file
@@ -0,0 +1,759 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/indexdb/temp_struct"
|
||||
)
|
||||
|
||||
type LocalChatLogs struct {
|
||||
loginUserID string
|
||||
}
|
||||
|
||||
// NewLocalChatLogs creates a new LocalChatLogs
|
||||
func NewLocalChatLogs(loginUserID string) *LocalChatLogs {
|
||||
return &LocalChatLogs{loginUserID: loginUserID}
|
||||
}
|
||||
|
||||
// GetMessage gets the message from the database
|
||||
func (i *LocalChatLogs) GetMessage(ctx context.Context, conversationID, clientMsgID string) (*model_struct.LocalChatLog, error) {
|
||||
msg, err := exec.Exec(conversationID, clientMsgID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msg.(string); ok {
|
||||
result := model_struct.LocalChatLog{}
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMessage updates the message in the database
|
||||
func (i *LocalChatLogs) UpdateMessage(ctx context.Context, conversationID string, c *model_struct.LocalChatLog) error {
|
||||
if c.ClientMsgID == "" {
|
||||
return exec.PrimaryKeyNull
|
||||
}
|
||||
tempLocalChatLog := temp_struct.LocalChatLog{
|
||||
ServerMsgID: c.ServerMsgID,
|
||||
SendID: c.SendID,
|
||||
RecvID: c.RecvID,
|
||||
SenderPlatformID: c.SenderPlatformID,
|
||||
SenderNickname: c.SenderNickname,
|
||||
SenderFaceURL: c.SenderFaceURL,
|
||||
SessionType: c.SessionType,
|
||||
MsgFrom: c.MsgFrom,
|
||||
ContentType: c.ContentType,
|
||||
Content: c.Content,
|
||||
IsRead: c.IsRead,
|
||||
Status: c.Status,
|
||||
Seq: c.Seq,
|
||||
SendTime: c.SendTime,
|
||||
CreateTime: c.CreateTime,
|
||||
AttachedInfo: c.AttachedInfo,
|
||||
Ex: c.Ex,
|
||||
IsReact: c.IsReact,
|
||||
IsExternalExtensions: c.IsExternalExtensions,
|
||||
MsgFirstModifyTime: c.MsgFirstModifyTime,
|
||||
}
|
||||
_, err := exec.Exec(conversationID, c.ClientMsgID, utils.StructToJsonString(tempLocalChatLog))
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateMessageStatus updates the message status in the database
|
||||
func (i *LocalChatLogs) BatchInsertMessageList(ctx context.Context, conversationID string, messageList []*model_struct.LocalChatLog) error {
|
||||
_, err := exec.Exec(conversationID, utils.StructToJsonString(messageList))
|
||||
return err
|
||||
}
|
||||
|
||||
// InsertMessage inserts a message into the local chat log.
|
||||
func (i *LocalChatLogs) InsertMessage(ctx context.Context, conversationID string, message *model_struct.LocalChatLog) error {
|
||||
_, err := exec.Exec(conversationID, utils.StructToJsonString(message))
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateColumnsMessageList updates multiple columns of a message in the local chat log.
|
||||
func (i *LocalChatLogs) UpdateColumnsMessageList(ctx context.Context, clientMsgIDList []string, args map[string]interface{}) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(clientMsgIDList), args)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateColumnsMessage updates a column of a message in the local chat log.
|
||||
func (i *LocalChatLogs) UpdateColumnsMessage(ctx context.Context, conversationID, clientMsgID string, args map[string]interface{}) error {
|
||||
_, err := exec.Exec(conversationID, clientMsgID, utils.StructToJsonString(args))
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteAllMessage deletes all messages from the local chat log.
|
||||
func (i *LocalChatLogs) DeleteAllMessage(ctx context.Context) error {
|
||||
_, err := exec.Exec()
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateMessageStatusBySourceID updates the status of a message in the local chat log by its source ID.
|
||||
func (i *LocalChatLogs) UpdateMessageStatusBySourceID(ctx context.Context, sourceID string, status, sessionType int32) error {
|
||||
_, err := exec.Exec(sourceID, status, sessionType, i.loginUserID)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateMessageTimeAndStatus updates the time and status of a message in the local chat log.
|
||||
func (i *LocalChatLogs) UpdateMessageTimeAndStatus(ctx context.Context, conversationID, clientMsgID string, serverMsgID string, sendTime int64, status int32) error {
|
||||
_, err := exec.Exec(conversationID, clientMsgID, serverMsgID, sendTime, status)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetMessageList retrieves a list of messages from the local chat log.
|
||||
func (i *LocalChatLogs) GetMessageList(ctx context.Context, conversationID string, count int, startTime int64, isReverse bool) (result []*model_struct.LocalChatLog, err error) {
|
||||
msgList, err := exec.Exec(conversationID, count, startTime, isReverse, i.loginUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgList.(string); ok {
|
||||
var temp []model_struct.LocalChatLog
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetMessageListNoTime retrieves a list of messages from the local chat log without specifying a start time.
|
||||
func (i *LocalChatLogs) GetMessageListNoTime(ctx context.Context, conversationID string, count int, isReverse bool) (result []*model_struct.LocalChatLog, err error) {
|
||||
msgList, err := exec.Exec(conversationID, count, isReverse)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgList.(string); ok {
|
||||
var temp []model_struct.LocalChatLog
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateSingleMessageHasRead updates the hasRead field of a single message in the local chat log.
|
||||
func (i *LocalChatLogs) UpdateSingleMessageHasRead(ctx context.Context, sendID string, msgIDList []string) error {
|
||||
_, err := exec.Exec(sendID, utils.StructToJsonString(msgIDList))
|
||||
return err
|
||||
}
|
||||
|
||||
// SearchMessageByContentType searches for messages in the local chat log by content type.
|
||||
func (i *LocalChatLogs) SearchMessageByContentType(ctx context.Context, contentType []int, conversationID string, startTime, endTime int64, offset, count int) (messages []*model_struct.LocalChatLog, err error) {
|
||||
msgList, err := exec.Exec(conversationID, utils.StructToJsonString(contentType), startTime, endTime, offset, count)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgList.(string); ok {
|
||||
var temp []model_struct.LocalChatLog
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
messages = append(messages, &v1)
|
||||
}
|
||||
return messages, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//funcation (i *LocalChatLogs) SuperGroupSearchMessageByContentType(ctx context.Context, contentType []int, sourceID string, startTime, endTime int64, sessionType, offset, count int) (messages []*model_struct.LocalChatLog, err error) {
|
||||
// msgList, err := Exec(utils.StructToJsonString(contentType), sourceID, startTime, endTime, sessionType, offset, count)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// } else {
|
||||
// if v, ok := msgList.(string); ok {
|
||||
// var temp []model_struct.LocalChatLog
|
||||
// err := utils.JsonStringToStruct(v, &temp)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// for _, v := range temp {
|
||||
// v1 := v
|
||||
// messages = append(messages, &v1)
|
||||
// }
|
||||
// return messages, err
|
||||
// } else {
|
||||
// return nil, ErrType
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
// SearchMessageByKeyword searches for messages in the local chat log by keyword.
|
||||
func (i *LocalChatLogs) SearchMessageByContentTypeAndKeyword(ctx context.Context, contentType []int, conversationID string, keywordList []string, keywordListMatchType int, startTime, endTime int64) (result []*model_struct.LocalChatLog, err error) {
|
||||
msgList, err := exec.Exec(conversationID, utils.StructToJsonString(contentType), utils.StructToJsonString(keywordList), keywordListMatchType, startTime, endTime)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgList.(string); ok {
|
||||
var temp []model_struct.LocalChatLog
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MessageIfExists check if message exists
|
||||
func (i *LocalChatLogs) MessageIfExists(ctx context.Context, clientMsgID string) (bool, error) {
|
||||
isExist, err := exec.Exec(clientMsgID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
} else {
|
||||
if v, ok := isExist.(bool); ok {
|
||||
return v, nil
|
||||
} else {
|
||||
return false, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IsExistsInErrChatLogBySeq check if message exists in error chat log by seq
|
||||
func (i *LocalChatLogs) IsExistsInErrChatLogBySeq(ctx context.Context, seq int64) bool {
|
||||
isExist, err := exec.Exec(seq)
|
||||
if err != nil {
|
||||
return false
|
||||
} else {
|
||||
if v, ok := isExist.(bool); ok {
|
||||
return v
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MessageIfExistsBySeq check if message exists by seq
|
||||
func (i *LocalChatLogs) MessageIfExistsBySeq(ctx context.Context, seq int64) (bool, error) {
|
||||
isExist, err := exec.Exec(seq)
|
||||
if err != nil {
|
||||
return false, err
|
||||
} else {
|
||||
if v, ok := isExist.(bool); ok {
|
||||
return v, nil
|
||||
} else {
|
||||
return false, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetMultipleMessage gets multiple messages from the local chat log.
|
||||
func (i *LocalChatLogs) GetMultipleMessage(ctx context.Context, msgIDList []string) (result []*model_struct.LocalChatLog, err error) {
|
||||
msgList, err := exec.Exec(utils.StructToJsonString(msgIDList))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgList.(string); ok {
|
||||
var temp []model_struct.LocalChatLog
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetLostMsgSeqList gets lost message seq list.
|
||||
func (i *LocalChatLogs) GetLostMsgSeqList(ctx context.Context, minSeqInSvr uint32) (result []uint32, err error) {
|
||||
l, err := exec.Exec(minSeqInSvr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := l.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetTestMessage gets test message.
|
||||
func (i *LocalChatLogs) GetTestMessage(ctx context.Context, seq uint32) (*model_struct.LocalChatLog, error) {
|
||||
msg, err := exec.Exec(seq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msg.(model_struct.LocalChatLog); ok {
|
||||
return &v, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the sender's nickname in the chat logs
|
||||
func (i *LocalChatLogs) UpdateMsgSenderNickname(ctx context.Context, sendID, nickname string, sType int) error {
|
||||
_, err := exec.Exec(sendID, nickname, sType)
|
||||
return err
|
||||
}
|
||||
|
||||
// Update the sender's face URL in the chat logs
|
||||
func (i *LocalChatLogs) UpdateMsgSenderFaceURL(ctx context.Context, sendID, faceURL string, sType int) error {
|
||||
_, err := exec.Exec(sendID, faceURL, sType)
|
||||
return err
|
||||
}
|
||||
|
||||
// Update the sender's face URL and nickname in the chat logs
|
||||
func (i *LocalChatLogs) UpdateMsgSenderFaceURLAndSenderNickname(ctx context.Context, conversationID, sendID, faceURL, nickname string) error {
|
||||
_, err := exec.Exec(conversationID, sendID, faceURL, nickname)
|
||||
return err
|
||||
}
|
||||
|
||||
// Get the message sequence number by client message ID
|
||||
func (i *LocalChatLogs) GetMsgSeqByClientMsgID(ctx context.Context, clientMsgID string) (uint32, error) {
|
||||
result, err := exec.Exec(clientMsgID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if v, ok := result.(float64); ok {
|
||||
return uint32(v), nil
|
||||
}
|
||||
return 0, exec.ErrType
|
||||
}
|
||||
|
||||
// Search all messages by content type
|
||||
func (i *LocalChatLogs) SearchAllMessageByContentType(ctx context.Context, conversationID string, contentType int) (result []*model_struct.LocalChatLog, err error) {
|
||||
msgList, err := exec.Exec(conversationID, contentType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgList.(string); ok {
|
||||
var temp []*model_struct.LocalChatLog
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the message sequence number list by group ID
|
||||
func (i *LocalChatLogs) GetMsgSeqListByGroupID(ctx context.Context, groupID string) (result []uint32, err error) {
|
||||
l, err := exec.Exec(groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := l.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the message sequence number list by peer user ID
|
||||
func (i *LocalChatLogs) GetMsgSeqListByPeerUserID(ctx context.Context, userID string) (result []uint32, err error) {
|
||||
l, err := exec.Exec(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := l.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the message sequence number list by self user ID
|
||||
func (i *LocalChatLogs) GetMsgSeqListBySelfUserID(ctx context.Context, userID string) (result []uint32, err error) {
|
||||
l, err := exec.Exec(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := l.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the abnormal message sequence number
|
||||
func (i *LocalChatLogs) GetAbnormalMsgSeq(ctx context.Context) (int64, error) {
|
||||
result, err := exec.Exec()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if v, ok := result.(float64); ok {
|
||||
return int64(v), nil
|
||||
}
|
||||
return 0, exec.ErrType
|
||||
}
|
||||
|
||||
// Get the list of abnormal message sequence numbers
|
||||
func (i *LocalChatLogs) GetAbnormalMsgSeqList(ctx context.Context) (result []int64, err error) {
|
||||
l, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := l.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Batch insert exception messages into the chat logs
|
||||
func (i *LocalChatLogs) BatchInsertExceptionMsg(ctx context.Context, MessageList []*model_struct.LocalErrChatLog) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(MessageList))
|
||||
return err
|
||||
}
|
||||
|
||||
// Update the message status to read in the chat logs
|
||||
func (i *LocalChatLogs) UpdateGroupMessageHasRead(ctx context.Context, msgIDList []string, sessionType int32) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(msgIDList), sessionType)
|
||||
return err
|
||||
}
|
||||
|
||||
// Get the message by message ID
|
||||
func (i *LocalChatLogs) SearchMessageByKeyword(ctx context.Context, contentType []int, keywordList []string, keywordListMatchType int, conversationID string, startTime, endTime int64, offset, count int) (result []*model_struct.LocalChatLog, err error) {
|
||||
msgList, err := exec.Exec(conversationID, utils.StructToJsonString(contentType), utils.StructToJsonString(keywordList), keywordListMatchType, startTime, endTime, offset, count)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgList.(string); ok {
|
||||
var temp []model_struct.LocalChatLog
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetSuperGroupAbnormalMsgSeq get super group abnormal msg seq
|
||||
func (i *LocalChatLogs) GetSuperGroupAbnormalMsgSeq(ctx context.Context, groupID string) (uint32, error) {
|
||||
isExist, err := exec.Exec(groupID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
if v, ok := isExist.(uint32); ok {
|
||||
return v, nil
|
||||
} else {
|
||||
return 0, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetAlreadyExistSeqList get already exist seq list
|
||||
func (i *LocalChatLogs) GetAlreadyExistSeqList(ctx context.Context, conversationID string, lostSeqList []int64) (result []int64, err error) {
|
||||
seqList, err := exec.Exec(conversationID, utils.StructToJsonString(lostSeqList))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := seqList.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetMessagesBySeq get message by seq
|
||||
func (i *LocalChatLogs) GetMessageBySeq(ctx context.Context, conversationID string, seq int64) (*model_struct.LocalChatLog, error) {
|
||||
msg, err := exec.Exec(conversationID, seq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msg.(string); ok {
|
||||
result := model_struct.LocalChatLog{}
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMessageBySeq update message
|
||||
func (i *LocalChatLogs) UpdateMessageBySeq(ctx context.Context, conversationID string, c *model_struct.LocalChatLog) error {
|
||||
if c.Seq == 0 {
|
||||
return exec.PrimaryKeyNull
|
||||
}
|
||||
tempLocalChatLog := temp_struct.LocalChatLog{
|
||||
ServerMsgID: c.ServerMsgID,
|
||||
SendID: c.SendID,
|
||||
RecvID: c.RecvID,
|
||||
SenderPlatformID: c.SenderPlatformID,
|
||||
SenderNickname: c.SenderNickname,
|
||||
SenderFaceURL: c.SenderFaceURL,
|
||||
SessionType: c.SessionType,
|
||||
MsgFrom: c.MsgFrom,
|
||||
ContentType: c.ContentType,
|
||||
Content: c.Content,
|
||||
IsRead: c.IsRead,
|
||||
Status: c.Status,
|
||||
Seq: c.Seq,
|
||||
SendTime: c.SendTime,
|
||||
CreateTime: c.CreateTime,
|
||||
AttachedInfo: c.AttachedInfo,
|
||||
Ex: c.Ex,
|
||||
IsReact: c.IsReact,
|
||||
IsExternalExtensions: c.IsExternalExtensions,
|
||||
MsgFirstModifyTime: c.MsgFirstModifyTime,
|
||||
}
|
||||
_, err := exec.Exec(conversationID, c.Seq, utils.StructToJsonString(tempLocalChatLog))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalChatLogs) MarkConversationMessageAsReadDB(ctx context.Context, conversationID string, msgIDs []string) (rowsAffected int64, err error) {
|
||||
rows, err := exec.Exec(conversationID, utils.StructToJsonString(msgIDs), i.loginUserID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
if v, ok := rows.(float64); ok {
|
||||
rowsAffected = int64(v)
|
||||
return rowsAffected, err
|
||||
} else {
|
||||
return 0, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalChatLogs) MarkConversationMessageAsReadBySeqs(ctx context.Context, conversationID string, seqs []int64) (rowsAffected int64, err error) {
|
||||
rows, err := exec.Exec(conversationID, utils.StructToJsonString(seqs), i.loginUserID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
if v, ok := rows.(float64); ok {
|
||||
rowsAffected = int64(v)
|
||||
return rowsAffected, err
|
||||
} else {
|
||||
return 0, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalChatLogs) MarkConversationAllMessageAsRead(ctx context.Context, conversationID string) (rowsAffected int64, err error) {
|
||||
rows, err := exec.Exec(conversationID, i.loginUserID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
if v, ok := rows.(float64); ok {
|
||||
rowsAffected = int64(v)
|
||||
return rowsAffected, err
|
||||
} else {
|
||||
return 0, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalChatLogs) GetUnreadMessage(ctx context.Context, conversationID string) (result []*model_struct.LocalChatLog, err error) {
|
||||
msgs, err := exec.Exec(conversationID, i.loginUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgs.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalChatLogs) GetMessagesByClientMsgIDs(ctx context.Context, conversationID string, msgIDs []string) (result []*model_struct.LocalChatLog, err error) {
|
||||
msgs, err := exec.Exec(conversationID, utils.StructToJsonString(msgIDs))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgs.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetMessagesBySeqs gets messages by seqs
|
||||
func (i *LocalChatLogs) GetMessagesBySeqs(ctx context.Context, conversationID string, seqs []int64) (result []*model_struct.LocalChatLog, err error) {
|
||||
msgs, err := exec.Exec(conversationID, utils.StructToJsonString(seqs))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgs.(string); ok {
|
||||
var temp []model_struct.LocalChatLog
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetConversationNormalMsgSeq gets the maximum seq of the session
|
||||
func (i *LocalChatLogs) GetConversationNormalMsgSeq(ctx context.Context, conversationID string) (int64, error) {
|
||||
seq, err := exec.Exec(conversationID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
if v, ok := seq.(float64); ok {
|
||||
var result int64
|
||||
result = int64(v)
|
||||
return result, err
|
||||
} else {
|
||||
return 0, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetConversationPeerNormalMsgSeq gets the maximum seq of the peer in the session
|
||||
func (i *LocalChatLogs) GetConversationPeerNormalMsgSeq(ctx context.Context, conversationID string) (int64, error) {
|
||||
seq, err := exec.Exec(conversationID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
if v, ok := seq.(float64); ok {
|
||||
var result int64
|
||||
result = int64(v)
|
||||
return result, nil
|
||||
} else {
|
||||
return 0, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetConversationAbnormalMsgSeq gets the maximum abnormal seq of the session
|
||||
func (i *LocalChatLogs) GetConversationAbnormalMsgSeq(ctx context.Context, groupID string) (int64, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
// DeleteConversationAllMessages deletes all messages of the session
|
||||
func (i *LocalChatLogs) DeleteConversationAllMessages(ctx context.Context, conversationID string) error {
|
||||
_, err := exec.Exec(conversationID)
|
||||
return err
|
||||
}
|
||||
|
||||
// MarkDeleteConversationAllMessages marks all messages of the session as deleted
|
||||
func (i *LocalChatLogs) MarkDeleteConversationAllMessages(ctx context.Context, conversationID string) error {
|
||||
_, err := exec.Exec(conversationID)
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteConversationMsgs deletes messages of the session
|
||||
func (i *LocalChatLogs) DeleteConversationMsgs(ctx context.Context, conversationID string, msgIDs []string) error {
|
||||
_, err := exec.Exec(conversationID, utils.StructToJsonString(msgIDs))
|
||||
return err
|
||||
}
|
||||
|
||||
// DeleteConversationMsgsBySeqs deletes messages of the session
|
||||
func (i *LocalChatLogs) DeleteConversationMsgsBySeqs(ctx context.Context, conversationID string, seqs []int64) error {
|
||||
_, err := exec.Exec(conversationID, utils.StructToJsonString(seqs))
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
type LocalChatLogReactionExtensions struct {
|
||||
ExtKey string `json:"ext_key"`
|
||||
ExtVal string `json:"ext_val"`
|
||||
ExtKey2 string `json:"ext_key2"`
|
||||
ExtVal2 string `json:"ext_val2"`
|
||||
}
|
||||
|
||||
func NewLocalChatLogReactionExtensions() *LocalChatLogReactionExtensions {
|
||||
return &LocalChatLogReactionExtensions{}
|
||||
}
|
||||
|
||||
func (i *LocalChatLogReactionExtensions) GetMessageReactionExtension(ctx context.Context, clientMsgID string) (result *model_struct.LocalChatLogReactionExtensions, err error) {
|
||||
msg, err := exec.Exec(clientMsgID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msg.(string); ok {
|
||||
result := model_struct.LocalChatLogReactionExtensions{}
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalChatLogReactionExtensions) InsertMessageReactionExtension(ctx context.Context, messageReactionExtension *model_struct.LocalChatLogReactionExtensions) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(messageReactionExtension))
|
||||
return err
|
||||
}
|
||||
|
||||
// func (i *LocalChatLogReactionExtensions) GetAndUpdateMessageReactionExtension(ctx context.Context, clientMsgID string, m map[string]*sdkws.KeyValue) error {
|
||||
// _, err := exec.Exec(clientMsgID, utils.StructToJsonString(m))
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// func (i *LocalChatLogReactionExtensions) DeleteAndUpdateMessageReactionExtension(ctx context.Context, clientMsgID string, m map[string]*sdkws.KeyValue) error {
|
||||
// _, err := exec.Exec(clientMsgID, utils.StructToJsonString(m))
|
||||
// return err
|
||||
// }
|
||||
func (i *LocalChatLogReactionExtensions) GetMultipleMessageReactionExtension(ctx context.Context, msgIDList []string) (result []*model_struct.LocalChatLogReactionExtensions, err error) {
|
||||
msgReactionExtensionList, err := exec.Exec(utils.StructToJsonString(msgIDList))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgReactionExtensionList.(string); ok {
|
||||
var temp []model_struct.LocalChatLogReactionExtensions
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
func (i *LocalChatLogReactionExtensions) DeleteMessageReactionExtension(ctx context.Context, msgID string) error {
|
||||
_, err := exec.Exec(msgID)
|
||||
return err
|
||||
}
|
||||
func (i *LocalChatLogReactionExtensions) UpdateMessageReactionExtension(ctx context.Context, c *model_struct.LocalChatLogReactionExtensions) error {
|
||||
_, err := exec.Exec(c.ClientMsgID, utils.StructToJsonString(c))
|
||||
return err
|
||||
}
|
||||
430
go/chao-sdk-core/wasm/indexdb/conversation_model.go
Normal file
430
go/chao-sdk-core/wasm/indexdb/conversation_model.go
Normal file
@@ -0,0 +1,430 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/indexdb/temp_struct"
|
||||
)
|
||||
|
||||
type LocalConversations struct {
|
||||
}
|
||||
|
||||
func NewLocalConversations() *LocalConversations {
|
||||
return &LocalConversations{}
|
||||
}
|
||||
|
||||
func (i *LocalConversations) GetAllConversationListDB(ctx context.Context) (result []*model_struct.LocalConversation, err error) {
|
||||
cList, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := cList.(string); ok {
|
||||
var temp []model_struct.LocalConversation
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalConversations) GetConversation(ctx context.Context, conversationID string) (*model_struct.LocalConversation, error) {
|
||||
c, err := exec.Exec(conversationID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := c.(string); ok {
|
||||
result := model_struct.LocalConversation{}
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalConversations) GetHiddenConversationList(ctx context.Context) (result []*model_struct.LocalConversation, err error) {
|
||||
cList, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := cList.(string); ok {
|
||||
var temp []model_struct.LocalConversation
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
func (i *LocalConversations) GetAllConversations(ctx context.Context) (result []*model_struct.LocalConversation, err error) {
|
||||
cList, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := cList.(string); ok {
|
||||
var temp []model_struct.LocalConversation
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
func (i *LocalConversations) UpdateColumnsConversation(ctx context.Context, conversationID string, args map[string]interface{}) error {
|
||||
_, err := exec.Exec(conversationID, utils.StructToJsonString(args))
|
||||
return err
|
||||
}
|
||||
func (i *LocalConversations) GetConversationByUserID(ctx context.Context, userID string) (*model_struct.LocalConversation, error) {
|
||||
c, err := exec.Exec(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := c.(string); ok {
|
||||
result := model_struct.LocalConversation{}
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalConversations) GetConversationListSplitDB(ctx context.Context, offset, count int) (result []*model_struct.LocalConversation, err error) {
|
||||
cList, err := exec.Exec(offset, count)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := cList.(string); ok {
|
||||
var temp []model_struct.LocalConversation
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalConversations) BatchInsertConversationList(ctx context.Context, conversationList []*model_struct.LocalConversation) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(conversationList))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversations) InsertConversation(ctx context.Context, conversationList *model_struct.LocalConversation) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(conversationList))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversations) DeleteConversation(ctx context.Context, conversationID string) error {
|
||||
_, err := exec.Exec(conversationID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversations) UpdateConversation(ctx context.Context, c *model_struct.LocalConversation) error {
|
||||
if c.ConversationID == "" {
|
||||
return exec.PrimaryKeyNull
|
||||
}
|
||||
tempLocalConversation := temp_struct.LocalConversation{
|
||||
ConversationType: c.ConversationType,
|
||||
UserID: c.UserID,
|
||||
GroupID: c.GroupID,
|
||||
ShowName: c.ShowName,
|
||||
FaceURL: c.FaceURL,
|
||||
RecvMsgOpt: c.RecvMsgOpt,
|
||||
UnreadCount: c.UnreadCount,
|
||||
GroupAtType: c.GroupAtType,
|
||||
LatestMsg: c.LatestMsg,
|
||||
LatestMsgSendTime: c.LatestMsgSendTime,
|
||||
DraftText: c.DraftText,
|
||||
DraftTextTime: c.DraftTextTime,
|
||||
IsPinned: c.IsPinned,
|
||||
IsPrivateChat: c.IsPrivateChat,
|
||||
BurnDuration: c.BurnDuration,
|
||||
IsNotInGroup: c.IsNotInGroup,
|
||||
UpdateUnreadCountTime: c.UpdateUnreadCountTime,
|
||||
AttachedInfo: c.AttachedInfo,
|
||||
Ex: c.Ex,
|
||||
}
|
||||
_, err := exec.Exec(c.ConversationID, utils.StructToJsonString(tempLocalConversation))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversations) UpdateConversationForSync(ctx context.Context, c *model_struct.LocalConversation) error {
|
||||
if c.ConversationID == "" {
|
||||
return exec.PrimaryKeyNull
|
||||
}
|
||||
tempLocalConversation := temp_struct.LocalPartConversation{
|
||||
RecvMsgOpt: c.RecvMsgOpt,
|
||||
GroupAtType: c.GroupAtType,
|
||||
IsPinned: c.IsPinned,
|
||||
IsPrivateChat: c.IsPrivateChat,
|
||||
IsNotInGroup: c.IsNotInGroup,
|
||||
UpdateUnreadCountTime: c.UpdateUnreadCountTime,
|
||||
BurnDuration: c.BurnDuration,
|
||||
AttachedInfo: c.AttachedInfo,
|
||||
Ex: c.Ex,
|
||||
}
|
||||
_, err := exec.Exec(c.ConversationID, utils.StructToJsonString(tempLocalConversation))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversations) BatchUpdateConversationList(ctx context.Context, conversationList []*model_struct.LocalConversation) error {
|
||||
for _, v := range conversationList {
|
||||
err := i.UpdateConversation(ctx, v)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "BatchUpdateConversationList failed")
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *LocalConversations) ConversationIfExists(ctx context.Context, conversationID string) (bool, error) {
|
||||
seq, err := exec.Exec(conversationID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
} else {
|
||||
if v, ok := seq.(bool); ok {
|
||||
return v, err
|
||||
} else {
|
||||
return false, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalConversations) ResetConversation(ctx context.Context, conversationID string) error {
|
||||
_, err := exec.Exec(conversationID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversations) ResetAllConversation(ctx context.Context) error {
|
||||
_, err := exec.Exec()
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversations) ClearConversation(ctx context.Context, conversationID string) error {
|
||||
_, err := exec.Exec(conversationID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversations) ClearAllConversation(ctx context.Context) error {
|
||||
_, err := exec.Exec()
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversations) SetConversationDraftDB(ctx context.Context, conversationID, draftText string) error {
|
||||
_, err := exec.Exec(conversationID, draftText)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversations) RemoveConversationDraft(ctx context.Context, conversationID, draftText string) error {
|
||||
_, err := exec.Exec(conversationID, draftText)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversations) UnPinConversation(ctx context.Context, conversationID string, isPinned int) error {
|
||||
_, err := exec.Exec(conversationID, isPinned)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversations) UpdateAllConversation(ctx context.Context, conversation *model_struct.LocalConversation) error {
|
||||
_, err := exec.Exec()
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversations) IncrConversationUnreadCount(ctx context.Context, conversationID string) error {
|
||||
_, err := exec.Exec(conversationID)
|
||||
return err
|
||||
}
|
||||
func (i *LocalConversations) DecrConversationUnreadCount(ctx context.Context, conversationID string, count int64) error {
|
||||
_, err := exec.Exec(conversationID, count)
|
||||
return err
|
||||
}
|
||||
func (i *LocalConversations) GetTotalUnreadMsgCountDB(ctx context.Context) (totalUnreadCount int32, err error) {
|
||||
count, err := exec.Exec()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
if v, ok := count.(float64); ok {
|
||||
var result int32
|
||||
result = int32(v)
|
||||
return result, err
|
||||
} else {
|
||||
return 0, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalConversations) SetMultipleConversationRecvMsgOpt(ctx context.Context, conversationIDList []string, opt int) (err error) {
|
||||
_, err = exec.Exec(utils.StructToJsonString(conversationIDList), opt)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversations) GetMultipleConversationDB(ctx context.Context, conversationIDList []string) (result []*model_struct.LocalConversation, err error) {
|
||||
cList, err := exec.Exec(utils.StructToJsonString(conversationIDList))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := cList.(string); ok {
|
||||
var temp []model_struct.LocalConversation
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalConversations) GetAllSingleConversationIDList(ctx context.Context) (result []string, err error) {
|
||||
conversationIDs, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := conversationIDs.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalConversations) GetAllConversationIDList(ctx context.Context) ([]string, error) {
|
||||
conversationIDList, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := conversationIDList.(string); ok {
|
||||
var result []string
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
func (i *LocalConversations) SearchConversations(ctx context.Context, searchParam string) ([]*model_struct.LocalConversation, error) {
|
||||
|
||||
var result []*model_struct.LocalConversation
|
||||
// Perform the search operation. Replace the below line with the actual search logic.
|
||||
searchResult, err := exec.Exec(searchParam)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "SearchConversations failed")
|
||||
}
|
||||
|
||||
// Convert searchResult to []*model_struct.LocalConversation
|
||||
// Assuming searchResult is in a format that can be converted to the required type
|
||||
err = utils.JsonStringToStruct(searchResult.(string), &result)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "Failed to parse search results")
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (i *LocalConversations) UpdateOrCreateConversations(ctx context.Context, conversationList []*model_struct.LocalConversation) error {
|
||||
//conversationIDs, err := Exec(ctx)
|
||||
return nil
|
||||
//if err != nil {
|
||||
// return err
|
||||
//} else {
|
||||
// if v, ok := conversationIDs.(string); ok {
|
||||
// var conversationIDs []string
|
||||
// err := utils.JsonStringToStruct(v, &conversationIDs)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// var notExistConversations []*model_struct.LocalConversation
|
||||
// var existConversations []*model_struct.LocalConversation
|
||||
// for i, v := range conversationList {
|
||||
// if utils.IsContain(v.ConversationID, conversationIDs) {
|
||||
// existConversations = append(existConversations, v)
|
||||
// continue
|
||||
// } else {
|
||||
// notExistConversations = append(notExistConversations, conversationList[i])
|
||||
// }
|
||||
// }
|
||||
// if len(notExistConversations) > 0 {
|
||||
// err := Exec(ctx, notExistConversations)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// for _, v := range existConversations {
|
||||
// err := Exec(ctx, v)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// return nil
|
||||
// } else {
|
||||
// return ErrType
|
||||
// }
|
||||
//}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
import (
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
)
|
||||
|
||||
type LocalConversationUnreadMessages struct {
|
||||
}
|
||||
|
||||
func NewLocalConversationUnreadMessages() *LocalConversationUnreadMessages {
|
||||
return &LocalConversationUnreadMessages{}
|
||||
}
|
||||
|
||||
func (i *LocalConversationUnreadMessages) BatchInsertConversationUnreadMessageList(ctx context.Context, messageList []*model_struct.LocalConversationUnreadMessage) error {
|
||||
if messageList == nil {
|
||||
return nil
|
||||
}
|
||||
_, err := exec.Exec(utils.StructToJsonString(messageList))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalConversationUnreadMessages) DeleteConversationUnreadMessageList(ctx context.Context, conversationID string, sendTime int64) int64 {
|
||||
deleteRows, err := exec.Exec(conversationID, sendTime)
|
||||
if err != nil {
|
||||
return 0
|
||||
} else {
|
||||
if v, ok := deleteRows.(float64); ok {
|
||||
var result int64
|
||||
result = int64(v)
|
||||
return result
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
}
|
||||
172
go/chao-sdk-core/wasm/indexdb/friend_model.go
Normal file
172
go/chao-sdk-core/wasm/indexdb/friend_model.go
Normal file
@@ -0,0 +1,172 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
import (
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/indexdb/temp_struct"
|
||||
)
|
||||
|
||||
type Friend struct {
|
||||
loginUserID string
|
||||
}
|
||||
|
||||
func NewFriend(loginUserID string) *Friend {
|
||||
return &Friend{loginUserID: loginUserID}
|
||||
}
|
||||
|
||||
func (i *Friend) InsertFriend(ctx context.Context, friend *model_struct.LocalFriend) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(friend))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *Friend) DeleteFriendDB(ctx context.Context, friendUserID string) error {
|
||||
_, err := exec.Exec(friendUserID, i.loginUserID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *Friend) UpdateFriend(ctx context.Context, friend *model_struct.LocalFriend) error {
|
||||
tempLocalFriend := temp_struct.LocalFriend{
|
||||
OwnerUserID: friend.OwnerUserID,
|
||||
FriendUserID: friend.FriendUserID,
|
||||
Remark: friend.Remark,
|
||||
CreateTime: friend.CreateTime,
|
||||
AddSource: friend.AddSource,
|
||||
OperatorUserID: friend.OperatorUserID,
|
||||
Nickname: friend.Nickname,
|
||||
FaceURL: friend.FaceURL,
|
||||
Ex: friend.Ex,
|
||||
AttachedInfo: friend.AttachedInfo,
|
||||
IsPinned: friend.IsPinned,
|
||||
}
|
||||
_, err := exec.Exec(utils.StructToJsonString(tempLocalFriend))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *Friend) GetAllFriendList(ctx context.Context) (result []*model_struct.LocalFriend, err error) {
|
||||
gList, err := exec.Exec(i.loginUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp []model_struct.LocalFriend
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Friend) SearchFriendList(ctx context.Context, keyword string, isSearchUserID, isSearchNickname, isSearchRemark bool) (result []*model_struct.LocalFriend, err error) {
|
||||
gList, err := exec.Exec(keyword, isSearchUserID, isSearchNickname, isSearchRemark)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp []model_struct.LocalFriend
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
func (i *Friend) UpdateColumnsFriend(ctx context.Context, friendIDs []string, args map[string]interface{}) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(friendIDs), utils.StructToJsonString(args))
|
||||
if err != nil {
|
||||
return err // Return immediately if there's an error with any friendID
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Friend) GetFriendInfoByFriendUserID(ctx context.Context, FriendUserID string) (*model_struct.LocalFriend, error) {
|
||||
c, err := exec.Exec(FriendUserID, i.loginUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := c.(string); ok {
|
||||
result := model_struct.LocalFriend{}
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Friend) GetFriendInfoList(ctx context.Context, friendUserIDList []string) (result []*model_struct.LocalFriend, err error) {
|
||||
gList, err := exec.Exec(utils.StructToJsonString(friendUserIDList))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp []model_struct.LocalFriend
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
func (i *Friend) GetPageFriendList(ctx context.Context, offset, count int) (result []*model_struct.LocalFriend, err error) {
|
||||
gList, err := exec.Exec(offset, count, i.loginUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
149
go/chao-sdk-core/wasm/indexdb/friend_request_model.go
Normal file
149
go/chao-sdk-core/wasm/indexdb/friend_request_model.go
Normal file
@@ -0,0 +1,149 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/indexdb/temp_struct"
|
||||
)
|
||||
|
||||
type FriendRequest struct {
|
||||
loginUserID string
|
||||
}
|
||||
|
||||
func NewFriendRequest(loginUserID string) *FriendRequest {
|
||||
return &FriendRequest{loginUserID: loginUserID}
|
||||
}
|
||||
|
||||
func (i FriendRequest) InsertFriendRequest(ctx context.Context, friendRequest *model_struct.LocalFriendRequest) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(friendRequest))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i FriendRequest) DeleteFriendRequestBothUserID(ctx context.Context, fromUserID, toUserID string) error {
|
||||
_, err := exec.Exec(fromUserID, toUserID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i FriendRequest) UpdateFriendRequest(ctx context.Context, friendRequest *model_struct.LocalFriendRequest) error {
|
||||
tempLocalFriendRequest := temp_struct.LocalFriendRequest{
|
||||
FromUserID: friendRequest.FromUserID,
|
||||
FromNickname: friendRequest.FromNickname,
|
||||
FromFaceURL: friendRequest.FromFaceURL,
|
||||
ToUserID: friendRequest.ToUserID,
|
||||
ToNickname: friendRequest.ToNickname,
|
||||
ToFaceURL: friendRequest.ToFaceURL,
|
||||
HandleResult: friendRequest.HandleResult,
|
||||
ReqMsg: friendRequest.ReqMsg,
|
||||
CreateTime: friendRequest.CreateTime,
|
||||
HandlerUserID: friendRequest.HandlerUserID,
|
||||
HandleMsg: friendRequest.HandleMsg,
|
||||
HandleTime: friendRequest.HandleTime,
|
||||
Ex: friendRequest.Ex,
|
||||
AttachedInfo: friendRequest.AttachedInfo,
|
||||
}
|
||||
_, err := exec.Exec(utils.StructToJsonString(tempLocalFriendRequest))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i FriendRequest) GetRecvFriendApplication(ctx context.Context) (result []*model_struct.LocalFriendRequest, err error) {
|
||||
gList, err := exec.Exec(i.loginUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp []model_struct.LocalFriendRequest
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i FriendRequest) GetSendFriendApplication(ctx context.Context) (result []*model_struct.LocalFriendRequest, err error) {
|
||||
gList, err := exec.Exec(i.loginUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp []model_struct.LocalFriendRequest
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i FriendRequest) GetFriendApplicationByBothID(ctx context.Context, fromUserID, toUserID string) (*model_struct.LocalFriendRequest, error) {
|
||||
c, err := exec.Exec(fromUserID, toUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := c.(string); ok {
|
||||
result := model_struct.LocalFriendRequest{}
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i FriendRequest) GetBothFriendReq(ctx context.Context, fromUserID, toUserID string) (result []*model_struct.LocalFriendRequest, err error) {
|
||||
gList, err := exec.Exec(fromUserID, toUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp []model_struct.LocalFriendRequest
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
335
go/chao-sdk-core/wasm/indexdb/group_member_model.go
Normal file
335
go/chao-sdk-core/wasm/indexdb/group_member_model.go
Normal file
@@ -0,0 +1,335 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
type LocalGroupMember struct {
|
||||
}
|
||||
|
||||
func NewLocalGroupMember() *LocalGroupMember {
|
||||
return &LocalGroupMember{}
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetGroupMemberInfoByGroupIDUserID(ctx context.Context, groupID, userID string) (*model_struct.LocalGroupMember, error) {
|
||||
member, err := exec.Exec(groupID, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := member.(string); ok {
|
||||
var temp model_struct.LocalGroupMember
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &temp, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetAllGroupMemberList(ctx context.Context) ([]model_struct.LocalGroupMember, error) {
|
||||
member, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := member.(string); ok {
|
||||
var temp []model_struct.LocalGroupMember
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return temp, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetAllGroupMemberUserIDList(ctx context.Context) ([]model_struct.LocalGroupMember, error) {
|
||||
member, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := member.(string); ok {
|
||||
var temp []model_struct.LocalGroupMember
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return temp, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetGroupMemberCount(ctx context.Context, groupID string) (int32, error) {
|
||||
count, err := exec.Exec(groupID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if v, ok := count.(float64); ok {
|
||||
return int32(v), nil
|
||||
}
|
||||
return 0, exec.ErrType
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetGroupSomeMemberInfo(ctx context.Context, groupID string, userIDList []string) ([]*model_struct.LocalGroupMember, error) {
|
||||
member, err := exec.Exec(groupID, utils.StructToJsonString(userIDList))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := member.(string); ok {
|
||||
var temp []*model_struct.LocalGroupMember
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return temp, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetGroupAdminID(ctx context.Context, groupID string) ([]string, error) {
|
||||
IDList, err := exec.Exec(groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if v, ok := IDList.(string); ok {
|
||||
var temp []string
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return temp, nil
|
||||
}
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetGroupMemberListByGroupID(ctx context.Context, groupID string) ([]*model_struct.LocalGroupMember, error) {
|
||||
member, err := exec.Exec(groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := member.(string); ok {
|
||||
var temp []*model_struct.LocalGroupMember
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return temp, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetGroupMemberListSplit(ctx context.Context, groupID string, filter int32, offset, count int) ([]*model_struct.LocalGroupMember, error) {
|
||||
member, err := exec.Exec(groupID, filter, offset, count)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := member.(string); ok {
|
||||
var temp []*model_struct.LocalGroupMember
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return temp, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetGroupMemberOwnerAndAdminDB(ctx context.Context, groupID string) ([]*model_struct.LocalGroupMember, error) {
|
||||
member, err := exec.Exec(groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := member.(string); ok {
|
||||
var temp []*model_struct.LocalGroupMember
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return temp, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetGroupMemberOwner(ctx context.Context, groupID string) (*model_struct.LocalGroupMember, error) {
|
||||
member, err := exec.Exec(groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := member.(string); ok {
|
||||
var temp model_struct.LocalGroupMember
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &temp, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetGroupMemberListSplitByJoinTimeFilter(ctx context.Context, groupID string, offset, count int, joinTimeBegin, joinTimeEnd int64, userIDList []string) ([]*model_struct.LocalGroupMember, error) {
|
||||
member, err := exec.Exec(groupID, offset, count, joinTimeBegin, joinTimeEnd, utils.StructToJsonString(userIDList))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := member.(string); ok {
|
||||
var temp []*model_struct.LocalGroupMember
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return temp, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetGroupOwnerAndAdminByGroupID(ctx context.Context, groupID string) ([]*model_struct.LocalGroupMember, error) {
|
||||
member, err := exec.Exec(groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := member.(string); ok {
|
||||
var temp []*model_struct.LocalGroupMember
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return temp, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetGroupMemberUIDListByGroupID(ctx context.Context, groupID string) (result []string, err error) {
|
||||
IDList, err := exec.Exec(groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if v, ok := IDList.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) InsertGroupMember(ctx context.Context, groupMember *model_struct.LocalGroupMember) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(groupMember))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) BatchInsertGroupMember(ctx context.Context, groupMemberList []*model_struct.LocalGroupMember) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(groupMemberList))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) DeleteGroupMember(ctx context.Context, groupID, userID string) error {
|
||||
_, err := exec.Exec(groupID, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) DeleteGroupAllMembers(ctx context.Context, groupID string) error {
|
||||
_, err := exec.Exec(groupID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) UpdateGroupMember(ctx context.Context, groupMember *model_struct.LocalGroupMember) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(groupMember))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) UpdateGroupMemberField(ctx context.Context, groupID, userID string, args map[string]interface{}) error {
|
||||
_, err := exec.Exec(groupID, userID, utils.StructToJsonString(args))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetGroupMemberInfoIfOwnerOrAdmin(ctx context.Context) ([]*model_struct.LocalGroupMember, error) {
|
||||
member, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := member.(string); ok {
|
||||
var temp []*model_struct.LocalGroupMember
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return temp, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) SearchGroupMembersDB(ctx context.Context, keyword string, groupID string, isSearchMemberNickname, isSearchUserID bool, offset, count int) (result []*model_struct.LocalGroupMember, err error) {
|
||||
member, err := exec.Exec(keyword, groupID, isSearchMemberNickname, isSearchUserID, offset, count)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := member.(string); ok {
|
||||
var temp []*model_struct.LocalGroupMember
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return temp, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroupMember) GetUserJoinedGroupIDs(ctx context.Context, userID string) (result []string, err error) {
|
||||
IDList, err := exec.Exec(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if v, ok := IDList.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
157
go/chao-sdk-core/wasm/indexdb/group_model.go
Normal file
157
go/chao-sdk-core/wasm/indexdb/group_model.go
Normal file
@@ -0,0 +1,157 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
type LocalGroups struct{}
|
||||
|
||||
func NewLocalGroups() *LocalGroups {
|
||||
return &LocalGroups{}
|
||||
}
|
||||
|
||||
func (i *LocalGroups) InsertGroup(ctx context.Context, groupInfo *model_struct.LocalGroup) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(groupInfo))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroups) DeleteGroup(ctx context.Context, groupID string) error {
|
||||
_, err := exec.Exec(groupID)
|
||||
return err
|
||||
}
|
||||
|
||||
// 该函数需要全更新
|
||||
func (i *LocalGroups) UpdateGroup(ctx context.Context, groupInfo *model_struct.LocalGroup) error {
|
||||
_, err := exec.Exec(groupInfo.GroupID, utils.StructToJsonString(groupInfo))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroups) GetJoinedGroupListDB(ctx context.Context) (result []*model_struct.LocalGroup, err error) {
|
||||
gList, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp []model_struct.LocalGroup
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroups) GetGroups(ctx context.Context, groupIDs []string) (result []*model_struct.LocalGroup, err error) {
|
||||
gList, err := exec.Exec(utils.StructToJsonString(groupIDs))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp []model_struct.LocalGroup
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroups) GetGroupInfoByGroupID(ctx context.Context, groupID string) (*model_struct.LocalGroup, error) {
|
||||
c, err := exec.Exec(groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := c.(string); ok {
|
||||
result := model_struct.LocalGroup{}
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroups) GetAllGroupInfoByGroupIDOrGroupName(ctx context.Context, keyword string, isSearchGroupID bool, isSearchGroupName bool) (result []*model_struct.LocalGroup, err error) {
|
||||
gList, err := exec.Exec(keyword, isSearchGroupID, isSearchGroupName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp []model_struct.LocalGroup
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroups) AddMemberCount(ctx context.Context, groupID string) error {
|
||||
_, err := exec.Exec(groupID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroups) SubtractMemberCount(ctx context.Context, groupID string) error {
|
||||
_, err := exec.Exec(groupID)
|
||||
return err
|
||||
}
|
||||
func (i *LocalGroups) GetGroupMemberAllGroupIDs(ctx context.Context) (result []string, err error) {
|
||||
groupIDList, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := groupIDList.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
97
go/chao-sdk-core/wasm/indexdb/group_request.model.go
Normal file
97
go/chao-sdk-core/wasm/indexdb/group_request.model.go
Normal file
@@ -0,0 +1,97 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
import (
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
)
|
||||
|
||||
type LocalGroupRequest struct {
|
||||
}
|
||||
|
||||
func NewLocalGroupRequest() *LocalGroupRequest {
|
||||
return &LocalGroupRequest{}
|
||||
}
|
||||
|
||||
func (i *LocalGroupRequest) InsertGroupRequest(ctx context.Context, groupRequest *model_struct.LocalGroupRequest) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(groupRequest))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroupRequest) DeleteGroupRequest(ctx context.Context, groupID, userID string) error {
|
||||
_, err := exec.Exec(groupID, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroupRequest) UpdateGroupRequest(ctx context.Context, groupRequest *model_struct.LocalGroupRequest) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(groupRequest))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroupRequest) GetSendGroupApplication(ctx context.Context) ([]*model_struct.LocalGroupRequest, error) {
|
||||
result, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if v, ok := result.(string); ok {
|
||||
var request []*model_struct.LocalGroupRequest
|
||||
if err := utils.JsonStringToStruct(v, &request); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return request, nil
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalGroupRequest) InsertAdminGroupRequest(ctx context.Context, groupRequest *model_struct.LocalAdminGroupRequest) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(groupRequest))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroupRequest) DeleteAdminGroupRequest(ctx context.Context, groupID, userID string) error {
|
||||
_, err := exec.Exec(groupID, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroupRequest) UpdateAdminGroupRequest(ctx context.Context, groupRequest *model_struct.LocalAdminGroupRequest) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(groupRequest))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalGroupRequest) GetAdminGroupApplication(ctx context.Context) ([]*model_struct.LocalAdminGroupRequest, error) {
|
||||
result, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if v, ok := result.(string); ok {
|
||||
var request []*model_struct.LocalAdminGroupRequest
|
||||
if err := utils.JsonStringToStruct(v, &request); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return request, nil
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
101
go/chao-sdk-core/wasm/indexdb/init.go
Normal file
101
go/chao-sdk-core/wasm/indexdb/init.go
Normal file
@@ -0,0 +1,101 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
//1,使用wasm原生的方式,tinygo应用于go的嵌入式领域,支持的功能有限,支持go语言的子集,甚至json序列化都无法支持
|
||||
//2.函数命名遵从驼峰命名
|
||||
//3.提供的sql生成语句中,关于bool值需要特殊处理,create语句的设计的到bool值的需要在创建语句中单独说明,这是因为在原有的sqlite中并不支持bool,用整数1或者0替代,gorm对其做了转换。
|
||||
//4.提供的sql生成语句中,字段名是下划线方式 例如:recv_id,但是接口转换的数据json tag字段的风格是recvID,类似的所有的字段需要做个map映射
|
||||
//5.任何涉及到gorm获取的是否需要返回错误,比如take和find都需要在文档上说明
|
||||
//6.任何涉及到update的操作,一定要看gorm原型中实现,如果有select(*)则不需要用temp_struct中的结构体
|
||||
//7.任何和接口重名的时候,db接口统一加上后缀DB
|
||||
//8.任何map类型统一使用json字符串转换,文档说明
|
||||
|
||||
type IndexDB struct {
|
||||
LocalUsers
|
||||
LocalConversations
|
||||
*LocalChatLogs
|
||||
LocalSuperGroupChatLogs
|
||||
LocalSuperGroup
|
||||
LocalConversationUnreadMessages
|
||||
LocalGroups
|
||||
LocalGroupMember
|
||||
LocalGroupRequest
|
||||
LocalCacheMessage
|
||||
LocalStrangers
|
||||
LocalUserCommand
|
||||
*FriendRequest
|
||||
*Black
|
||||
*Friend
|
||||
LocalChatLogReactionExtensions
|
||||
loginUserID string
|
||||
}
|
||||
|
||||
func (i IndexDB) Close(ctx context.Context) error {
|
||||
_, err := exec.Exec()
|
||||
return err
|
||||
}
|
||||
|
||||
func (i IndexDB) InitDB(ctx context.Context, userID string, dataDir string) error {
|
||||
_, err := exec.Exec(userID, dataDir)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i IndexDB) SetChatLogFailedStatus(ctx context.Context) {
|
||||
//msgList, err := i.GetSendingMessageList()
|
||||
//if err != nil {
|
||||
// log.Error("", "GetSendingMessageList failed ", err.Error())
|
||||
// return
|
||||
//}
|
||||
//for _, v := range msgList {
|
||||
// v.Status = constant.MsgStatusSendFailed
|
||||
// err := i.UpdateMessage(v)
|
||||
// if err != nil {
|
||||
// log.Error("", "UpdateMessage failed ", err.Error(), v)
|
||||
// continue
|
||||
// }
|
||||
//}
|
||||
//groupIDList, err := i.GetReadDiffusionGroupIDList()
|
||||
//if err != nil {
|
||||
// log.Error("", "GetReadDiffusionGroupIDList failed ", err.Error())
|
||||
// return
|
||||
//}
|
||||
//for _, v := range groupIDList {
|
||||
// msgList, err := i.SuperGroupGetSendingMessageList(v)
|
||||
// if err != nil {
|
||||
// log.Error("", "GetSendingMessageList failed ", err.Error())
|
||||
// return
|
||||
// }
|
||||
// if len(msgList) > 0 {
|
||||
// for _, v := range msgList {
|
||||
// v.Status = constant.MsgStatusSendFailed
|
||||
// err := i.SuperGroupUpdateMessage(v)
|
||||
// if err != nil {
|
||||
// log.Error("", "UpdateMessage failed ", err.Error(), v)
|
||||
// continue
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
}
|
||||
54
go/chao-sdk-core/wasm/indexdb/notification_model.go
Normal file
54
go/chao-sdk-core/wasm/indexdb/notification_model.go
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
type NotificationSeqs struct {
|
||||
}
|
||||
|
||||
func NewNotificationSeqs() *NotificationSeqs {
|
||||
return &NotificationSeqs{}
|
||||
}
|
||||
|
||||
func (i *NotificationSeqs) SetNotificationSeq(ctx context.Context, conversationID string, seq int64) error {
|
||||
_, err := exec.Exec(conversationID, seq)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *NotificationSeqs) GetNotificationAllSeqs(ctx context.Context) (result []*model_struct.NotificationSeqs, err error) {
|
||||
gList, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
62
go/chao-sdk-core/wasm/indexdb/sending_messages_model.go
Normal file
62
go/chao-sdk-core/wasm/indexdb/sending_messages_model.go
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
type LocalSendingMessages struct {
|
||||
}
|
||||
|
||||
func NewLocalSendingMessages() *LocalSendingMessages {
|
||||
return &LocalSendingMessages{}
|
||||
}
|
||||
func (i *LocalSendingMessages) InsertSendingMessage(ctx context.Context, message *model_struct.LocalSendingMessages) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(message))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalSendingMessages) DeleteSendingMessage(ctx context.Context, conversationID, clientMsgID string) error {
|
||||
_, err := exec.Exec(conversationID, clientMsgID)
|
||||
return err
|
||||
}
|
||||
func (i *LocalSendingMessages) GetAllSendingMessages(ctx context.Context) (result []*model_struct.LocalSendingMessages, err error) {
|
||||
gList, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp []model_struct.LocalSendingMessages
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
62
go/chao-sdk-core/wasm/indexdb/stranger_model.go
Normal file
62
go/chao-sdk-core/wasm/indexdb/stranger_model.go
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
import (
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
)
|
||||
|
||||
type LocalStrangers struct {
|
||||
}
|
||||
|
||||
func NewLocalStrangers() *LocalStrangers {
|
||||
return &LocalStrangers{}
|
||||
}
|
||||
|
||||
func (l *LocalStrangers) GetStrangerInfo(ctx context.Context, userIDs []string) (result []*model_struct.LocalStranger, err error) {
|
||||
gList, err := exec.Exec(utils.StructToJsonString(userIDs))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp []model_struct.LocalStranger
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LocalStrangers) SetStrangerInfo(ctx context.Context, strangerList []*model_struct.LocalStranger) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(strangerList))
|
||||
return err
|
||||
}
|
||||
461
go/chao-sdk-core/wasm/indexdb/super_group_chat_log_model.go
Normal file
461
go/chao-sdk-core/wasm/indexdb/super_group_chat_log_model.go
Normal file
@@ -0,0 +1,461 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/sdk_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/indexdb/temp_struct"
|
||||
)
|
||||
|
||||
type LocalSuperGroupChatLogs struct{}
|
||||
|
||||
func NewLocalSuperGroupChatLogs() *LocalSuperGroupChatLogs {
|
||||
return &LocalSuperGroupChatLogs{}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupGetNormalMinSeq(ctx context.Context, groupID string) (uint32, error) {
|
||||
seq, err := exec.Exec(groupID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
if v, ok := seq.(float64); ok {
|
||||
var result uint32
|
||||
result = uint32(v)
|
||||
return result, err
|
||||
} else {
|
||||
return 0, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupGetMessage(ctx context.Context, message *sdk_struct.MsgStruct) (*model_struct.LocalChatLog, error) {
|
||||
msg, err := exec.Exec(message.GroupID, message.ClientMsgID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msg.(string); ok {
|
||||
result := model_struct.LocalChatLog{}
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupUpdateMessage(ctx context.Context, c *model_struct.LocalChatLog) error {
|
||||
if c.ClientMsgID == "" {
|
||||
return exec.PrimaryKeyNull
|
||||
}
|
||||
tempLocalChatLog := temp_struct.LocalChatLog{
|
||||
ServerMsgID: c.ServerMsgID,
|
||||
SendID: c.SendID,
|
||||
RecvID: c.RecvID,
|
||||
SenderPlatformID: c.SenderPlatformID,
|
||||
SenderNickname: c.SenderNickname,
|
||||
SenderFaceURL: c.SenderFaceURL,
|
||||
SessionType: c.SessionType,
|
||||
MsgFrom: c.MsgFrom,
|
||||
ContentType: c.ContentType,
|
||||
Content: c.Content,
|
||||
IsRead: c.IsRead,
|
||||
Status: c.Status,
|
||||
Seq: c.Seq,
|
||||
SendTime: c.SendTime,
|
||||
CreateTime: c.CreateTime,
|
||||
AttachedInfo: c.AttachedInfo,
|
||||
Ex: c.Ex,
|
||||
IsReact: c.IsReact,
|
||||
IsExternalExtensions: c.IsExternalExtensions,
|
||||
MsgFirstModifyTime: c.MsgFirstModifyTime,
|
||||
}
|
||||
_, err := exec.Exec(c.RecvID, c.ClientMsgID, utils.StructToJsonString(tempLocalChatLog))
|
||||
return err
|
||||
|
||||
}
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupBatchInsertMessageList(ctx context.Context, messageList []*model_struct.LocalChatLog, groupID string) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(messageList), groupID)
|
||||
return err
|
||||
}
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupInsertMessage(ctx context.Context, message *model_struct.LocalChatLog, groupID string) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(message), groupID)
|
||||
return err
|
||||
}
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupGetMultipleMessage(ctx context.Context, msgIDList []string, groupID string) (result []*model_struct.LocalChatLog, err error) {
|
||||
msgList, err := exec.Exec(utils.StructToJsonString(msgIDList), groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgList.(string); ok {
|
||||
var temp []model_struct.LocalChatLog
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupUpdateMessageTimeAndStatus(ctx context.Context, msg *sdk_struct.MsgStruct) error {
|
||||
_, err := exec.Exec(msg.GroupID, msg.ClientMsgID, msg.ServerMsgID, msg.SendTime, msg.Status)
|
||||
return err
|
||||
}
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupGetMessageListNoTime(ctx context.Context, sourceID string, sessionType, count int, isReverse bool) (result []*model_struct.LocalChatLog, err error) {
|
||||
msgList, err := exec.Exec(sourceID, sessionType, count, isReverse)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgList.(string); ok {
|
||||
var temp []model_struct.LocalChatLog
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupGetMessageList(ctx context.Context, sourceID string, sessionType, count int, startTime int64, isReverse bool) (result []*model_struct.LocalChatLog, err error) {
|
||||
msgList, err := exec.Exec(sourceID, sessionType, count, startTime, isReverse)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgList.(string); ok {
|
||||
var temp []model_struct.LocalChatLog
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupSearchMessageByKeyword(ctx context.Context, contentType []int, keywordList []string, keywordListMatchType int, sourceID string, startTime, endTime int64, sessionType, offset, count int) (result []*model_struct.LocalChatLog, err error) {
|
||||
msgList, err := exec.Exec(utils.StructToJsonString(contentType), utils.StructToJsonString(keywordList), keywordListMatchType, sourceID, startTime, endTime, sessionType, offset, count)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgList.(string); ok {
|
||||
var temp []model_struct.LocalChatLog
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupSearchAllMessageByContentType(ctx context.Context, superGroupID string, contentType int32) (result []*model_struct.LocalChatLog, err error) {
|
||||
msgList, err := exec.Exec(superGroupID, contentType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := msgList.(string); ok {
|
||||
var temp []*model_struct.LocalChatLog
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) InitSuperLocalErrChatLog(ctx context.Context, groupID string) {
|
||||
_, _ = exec.Exec(groupID)
|
||||
}
|
||||
func (i *LocalSuperGroupChatLogs) SuperBatchInsertExceptionMsg(ctx context.Context, MessageList []*model_struct.LocalErrChatLog, groupID string) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(MessageList), groupID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) InitSuperLocalChatLog(ctx context.Context, groupID string) {
|
||||
_, _ = exec.Exec(groupID)
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupDeleteAllMessage(ctx context.Context, groupID string) error {
|
||||
_, err := exec.Exec(groupID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupSearchMessageByContentTypeAndKeyword(ctx context.Context, contentType []int, keywordList []string, keywordListMatchType int, startTime, endTime int64, groupID string) (result []*model_struct.LocalChatLog, err error) {
|
||||
gList, err := exec.Exec(utils.StructToJsonString(contentType), utils.StructToJsonString(keywordList), keywordListMatchType, startTime, endTime, groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var temp []model_struct.LocalChatLog
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupBatchUpdateMessageList(ctx context.Context, MessageList []*model_struct.LocalChatLog) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(MessageList))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupMessageIfExists(ctx context.Context, ClientMsgID string) (bool, error) {
|
||||
isExist, err := exec.Exec(ClientMsgID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
} else {
|
||||
if v, ok := isExist.(bool); ok {
|
||||
return v, nil
|
||||
} else {
|
||||
return false, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupIsExistsInErrChatLogBySeq(ctx context.Context, seq int64) bool {
|
||||
isExist, err := exec.Exec(seq)
|
||||
if err != nil {
|
||||
return false
|
||||
} else {
|
||||
if v, ok := isExist.(bool); ok {
|
||||
return v
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupMessageIfExistsBySeq(ctx context.Context, seq int64) (bool, error) {
|
||||
isExist, err := exec.Exec(seq)
|
||||
if err != nil {
|
||||
return false, err
|
||||
} else {
|
||||
if v, ok := isExist.(bool); ok {
|
||||
return v, nil
|
||||
} else {
|
||||
return false, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupGetAllUnDeleteMessageSeqList(ctx context.Context) ([]uint32, error) {
|
||||
gList, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var result []uint32
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupUpdateColumnsMessage(ctx context.Context, clientMsgID, groupID string, args map[string]interface{}) error {
|
||||
_, err := exec.Exec(clientMsgID, groupID, utils.StructToJsonString(args))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupUpdateMessageStatusBySourceID(ctx context.Context, sourceID string, status, sessionType int32) error {
|
||||
_, err := exec.Exec(sourceID, status, sessionType)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupGetSendingMessageList(ctx context.Context, groupID string) (result []*model_struct.LocalChatLog, err error) {
|
||||
gList, err := exec.Exec(groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupUpdateGroupMessageHasRead(ctx context.Context, msgIDList []string, groupID string) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(msgIDList), groupID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupGetNormalMsgSeq(ctx context.Context) (uint32, error) {
|
||||
seq, err := exec.Exec()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
if v, ok := seq.(float64); ok {
|
||||
return uint32(v), nil
|
||||
} else {
|
||||
return 0, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupGetTestMessage(ctx context.Context, seq uint32) (*model_struct.LocalChatLog, error) {
|
||||
c, err := exec.Exec(seq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := c.(string); ok {
|
||||
result := model_struct.LocalChatLog{}
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupUpdateMsgSenderNickname(ctx context.Context, sendID, nickname string, sType int) error {
|
||||
_, err := exec.Exec(sendID, nickname, sType)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupUpdateMsgSenderFaceURL(ctx context.Context, sendID, faceURL string, sType int) error {
|
||||
_, err := exec.Exec(sendID, faceURL, sType)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupUpdateMsgSenderFaceURLAndSenderNickname(ctx context.Context, sendID, faceURL, nickname string, sessionType int, groupID string) error {
|
||||
_, err := exec.Exec(sendID, faceURL, nickname, sessionType, groupID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupGetMsgSeqByClientMsgID(ctx context.Context, clientMsgID string, groupID string) (uint32, error) {
|
||||
seq, err := exec.Exec(clientMsgID, groupID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
if v, ok := seq.(float64); ok {
|
||||
return uint32(v), nil
|
||||
} else {
|
||||
return 0, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupGetMsgSeqListByGroupID(ctx context.Context, groupID string) ([]uint32, error) {
|
||||
gList, err := exec.Exec(groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var result []uint32
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupGetMsgSeqListByPeerUserID(ctx context.Context, userID string) ([]uint32, error) {
|
||||
gList, err := exec.Exec(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var result []uint32
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroupChatLogs) SuperGroupGetMsgSeqListBySelfUserID(ctx context.Context, userID string) ([]uint32, error) {
|
||||
gList, err := exec.Exec(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := gList.(string); ok {
|
||||
var result []uint32
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
128
go/chao-sdk-core/wasm/indexdb/super_group_model.go
Normal file
128
go/chao-sdk-core/wasm/indexdb/super_group_model.go
Normal file
@@ -0,0 +1,128 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
type LocalSuperGroup struct{}
|
||||
|
||||
func NewLocalSuperGroup() *LocalSuperGroup {
|
||||
return &LocalSuperGroup{}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroup) GetJoinedSuperGroupList(ctx context.Context) (result []*model_struct.LocalGroup, err error) {
|
||||
groupList, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := groupList.(string); ok {
|
||||
var temp []model_struct.LocalGroup
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroup) InsertSuperGroup(ctx context.Context, groupInfo *model_struct.LocalGroup) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(groupInfo))
|
||||
return err
|
||||
}
|
||||
func (i *LocalSuperGroup) UpdateSuperGroup(ctx context.Context, g *model_struct.LocalGroup) error {
|
||||
_, err := exec.Exec(g.GroupID, utils.StructToJsonString(g))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroup) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
||||
_, err := exec.Exec(groupID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroup) DeleteAllSuperGroup(ctx context.Context) error {
|
||||
_, err := exec.Exec()
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroup) GetSuperGroupInfoByGroupID(ctx context.Context, groupID string) (*model_struct.LocalGroup, error) {
|
||||
groupInfo, err := exec.Exec(groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := groupInfo.(string); ok {
|
||||
result := model_struct.LocalGroup{}
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroup) GetJoinedWorkingGroupIDList(ctx context.Context) ([]string, error) {
|
||||
IDList, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if v, ok := IDList.(string); ok {
|
||||
var temp []string
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return temp, nil
|
||||
}
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
|
||||
func (i *LocalSuperGroup) GetJoinedWorkingGroupList(ctx context.Context) (result []*model_struct.LocalGroup, err error) {
|
||||
groupList, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := groupList.(string); ok {
|
||||
var temp []model_struct.LocalGroup
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range temp {
|
||||
v1 := v
|
||||
result = append(result, &v1)
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
178
go/chao-sdk-core/wasm/indexdb/temp_struct/struct.go
Normal file
178
go/chao-sdk-core/wasm/indexdb/temp_struct/struct.go
Normal file
@@ -0,0 +1,178 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package temp_struct
|
||||
|
||||
type LocalChatLog struct {
|
||||
ServerMsgID string ` json:"serverMsgID,omitempty"`
|
||||
SendID string ` json:"sendID,omitempty"`
|
||||
RecvID string ` json:"recvID,omitempty"`
|
||||
SenderPlatformID int32 ` json:"senderPlatformID,omitempty"`
|
||||
SenderNickname string ` json:"senderNickname,omitempty"`
|
||||
SenderFaceURL string ` json:"senderFaceURL,omitempty"`
|
||||
SessionType int32 ` json:"sessionType,omitempty"`
|
||||
MsgFrom int32 ` json:"msgFrom,omitempty"`
|
||||
ContentType int32 ` json:"contentType,omitempty"`
|
||||
Content string ` json:"content,omitempty"`
|
||||
IsRead bool ` json:"isRead,omitempty"`
|
||||
Status int32 ` json:"status,omitempty"`
|
||||
Seq int64 ` json:"seq,omitempty"`
|
||||
SendTime int64 ` json:"sendTime,omitempty"`
|
||||
CreateTime int64 ` json:"createTime,omitempty"`
|
||||
AttachedInfo string ` json:"attachedInfo,omitempty"`
|
||||
Ex string ` json:"ex,omitempty"`
|
||||
IsReact bool ` json:"isReact,omitempty"`
|
||||
IsExternalExtensions bool ` json:"isExternalExtensions,omitempty"`
|
||||
MsgFirstModifyTime int64 ` json:"msgFirstModifyTime,omitempty"`
|
||||
}
|
||||
type LocalConversation struct {
|
||||
ConversationID string ` json:"conversationID,omitempty"`
|
||||
ConversationType int32 ` json:"conversationType,omitempty"`
|
||||
UserID string ` json:"userID,omitempty"`
|
||||
GroupID string ` json:"groupID,omitempty"`
|
||||
ShowName string ` json:"showName,omitempty"`
|
||||
FaceURL string ` json:"faceURL,omitempty"`
|
||||
RecvMsgOpt int32 ` json:"recvMsgOpt,omitempty"`
|
||||
UnreadCount int32 ` json:"unreadCount,omitempty"`
|
||||
GroupAtType int32 ` json:"groupAtType,omitempty"`
|
||||
LatestMsg string ` json:"latestMsg,omitempty"`
|
||||
LatestMsgSendTime int64 ` json:"latestMsgSendTime,omitempty"`
|
||||
DraftText string ` json:"draftText,omitempty"`
|
||||
DraftTextTime int64 ` json:"draftTextTime,omitempty"`
|
||||
IsPinned bool ` json:"isPinned,omitempty"`
|
||||
IsPrivateChat bool ` json:"isPrivateChat,omitempty"`
|
||||
BurnDuration int32 ` json:"burnDuration,omitempty"`
|
||||
IsNotInGroup bool ` json:"isNotInGroup,omitempty"`
|
||||
UpdateUnreadCountTime int64 ` json:"updateUnreadCountTime,omitempty"`
|
||||
AttachedInfo string ` json:"attachedInfo,omitempty"`
|
||||
Ex string ` json:"ex,omitempty"`
|
||||
}
|
||||
type LocalPartConversation struct {
|
||||
RecvMsgOpt int32 ` json:"recvMsgOpt"`
|
||||
GroupAtType int32 ` json:"groupAtType"`
|
||||
IsPinned bool ` json:"isPinned,"`
|
||||
IsPrivateChat bool ` json:"isPrivateChat"`
|
||||
IsNotInGroup bool ` json:"isNotInGroup"`
|
||||
UpdateUnreadCountTime int64 ` json:"updateUnreadCountTime"`
|
||||
BurnDuration int32 ` json:"burnDuration,omitempty"`
|
||||
AttachedInfo string ` json:"attachedInfo"`
|
||||
Ex string ` json:"ex"`
|
||||
}
|
||||
|
||||
type LocalSuperGroup struct {
|
||||
GroupID string `json:"groupID,omitempty"`
|
||||
GroupName string `json:"groupName,omitempty"`
|
||||
Notification string `json:"notification,omitempty"`
|
||||
Introduction string `json:"introduction,omitempty"`
|
||||
FaceURL string `json:"faceURL,omitempty"`
|
||||
CreateTime uint32 `json:"createTime,omitempty"`
|
||||
Status int32 `json:"status,omitempty"`
|
||||
CreatorUserID string `json:"creatorUserID,omitempty"`
|
||||
GroupType int32 `json:"groupType,omitempty"`
|
||||
OwnerUserID string `json:"ownerUserID,omitempty"`
|
||||
MemberCount int32 `json:"memberCount,omitempty"`
|
||||
Ex string `json:"ex,omitempty"`
|
||||
AttachedInfo string `json:"attachedInfo,omitempty"`
|
||||
NeedVerification int32 `json:"needVerification,omitempty"`
|
||||
LookMemberInfo int32 `json:"lookMemberInfo,omitempty"`
|
||||
ApplyMemberFriend int32 `json:"applyMemberFriend,omitempty"`
|
||||
NotificationUpdateTime uint32 `json:"notificationUpdateTime,omitempty"`
|
||||
NotificationUserID string `json:"notificationUserID,omitempty"`
|
||||
}
|
||||
|
||||
type LocalGroup struct {
|
||||
GroupID string `json:"groupID,omitempty"`
|
||||
GroupName string `json:"groupName,omitempty"`
|
||||
Notification string `json:"notification,omitempty"`
|
||||
Introduction string `json:"introduction,omitempty"`
|
||||
FaceURL string `json:"faceURL,omitempty"`
|
||||
CreateTime uint32 `json:"createTime,omitempty"`
|
||||
Status int32 `json:"status,omitempty"`
|
||||
CreatorUserID string `json:"creatorUserID,omitempty"`
|
||||
GroupType int32 `json:"groupType,omitempty"`
|
||||
OwnerUserID string `json:"ownerUserID,omitempty"`
|
||||
MemberCount int32 `json:"memberCount,omitempty"`
|
||||
Ex string `json:"ex,omitempty"`
|
||||
AttachedInfo string `json:"attachedInfo,omitempty"`
|
||||
NeedVerification int32 `json:"needVerification,omitempty"`
|
||||
LookMemberInfo int32 `json:"lookMemberInfo,omitempty"`
|
||||
ApplyMemberFriend int32 `json:"applyMemberFriend,omitempty"`
|
||||
NotificationUpdateTime uint32 `json:"notificationUpdateTime,omitempty"`
|
||||
NotificationUserID string `json:"notificationUserID,omitempty"`
|
||||
}
|
||||
|
||||
type LocalFriendRequest struct {
|
||||
FromUserID string `json:"fromUserID,omitempty"`
|
||||
FromNickname string `json:"fromNickname,omitempty"`
|
||||
FromFaceURL string `json:"fromFaceURL,omitempty"`
|
||||
ToUserID string `json:"toUserID,omitempty"`
|
||||
ToNickname string `json:"toNickname,omitempty"`
|
||||
ToFaceURL string `json:"toFaceURL,omitempty"`
|
||||
HandleResult int32 `json:"handleResult,omitempty"`
|
||||
ReqMsg string `json:"reqMsg,omitempty"`
|
||||
CreateTime int64 `json:"createTime,omitempty"`
|
||||
HandlerUserID string `json:"handlerUserID,omitempty"`
|
||||
HandleMsg string `json:"handleMsg,omitempty"`
|
||||
HandleTime int64 `json:"handleTime,omitempty"`
|
||||
Ex string `json:"ex,omitempty"`
|
||||
AttachedInfo string `json:"attachedInfo,omitempty"`
|
||||
}
|
||||
|
||||
type LocalBlack struct {
|
||||
OwnerUserID string `json:"ownerUserID,omitempty"`
|
||||
BlockUserID string `json:"blockUserID,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
FaceURL string `json:"faceURL,omitempty"`
|
||||
CreateTime int64 `json:"createTime,omitempty"`
|
||||
AddSource int32 `json:"addSource,omitempty"`
|
||||
OperatorUserID string `json:"operatorUserID,omitempty"`
|
||||
Ex string `json:"ex,omitempty"`
|
||||
AttachedInfo string `json:"attachedInfo,omitempty"`
|
||||
}
|
||||
|
||||
type LocalFriend struct {
|
||||
OwnerUserID string `json:"ownerUserID,omitempty"`
|
||||
FriendUserID string `json:"friendUserID,omitempty"`
|
||||
Remark string `json:"remark,omitempty"`
|
||||
CreateTime int64 `json:"createTime,omitempty"`
|
||||
AddSource int32 `json:"addSource,omitempty"`
|
||||
OperatorUserID string `json:"operatorUserID,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
FaceURL string `json:"faceURL,omitempty"`
|
||||
Ex string `json:"ex,omitempty"`
|
||||
AttachedInfo string `json:"attachedInfo,omitempty"`
|
||||
IsPinned bool `json:"isPinned,omitempty"`
|
||||
}
|
||||
|
||||
type LocalUser struct {
|
||||
UserID string `json:"userID,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
FaceURL string `json:"faceURL,omitempty"`
|
||||
CreateTime int64 `json:"createTime,omitempty"`
|
||||
AppMangerLevel int32 `json:"-"`
|
||||
Ex string `json:"ex,omitempty"`
|
||||
AttachedInfo string `json:"attachedInfo,omitempty"`
|
||||
GlobalRecvMsgOpt int32 `json:"globalRecvMsgOpt,omitempty"`
|
||||
}
|
||||
|
||||
type LocalUserCommand struct {
|
||||
UserID string `json:"userID,omitempty"`
|
||||
Type int32 `json:"type,omitempty"`
|
||||
CreateTime int64 `json:"createTime,omitempty"`
|
||||
Uuid string `json:"uuid,omitempty"`
|
||||
Value string `json:"value,omitempty"`
|
||||
}
|
||||
68
go/chao-sdk-core/wasm/indexdb/upload_model.go
Normal file
68
go/chao-sdk-core/wasm/indexdb/upload_model.go
Normal file
@@ -0,0 +1,68 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
type LocalUpload struct{}
|
||||
|
||||
func NewLocalUpload() *LocalUpload {
|
||||
return &LocalUpload{}
|
||||
}
|
||||
|
||||
func (i *LocalUpload) GetUpload(ctx context.Context, partHash string) (*model_struct.LocalUpload, error) {
|
||||
c, err := exec.Exec(partHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := c.(string); ok {
|
||||
result := model_struct.LocalUpload{}
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalUpload) InsertUpload(ctx context.Context, upload *model_struct.LocalUpload) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(upload))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalUpload) DeleteUpload(ctx context.Context, partHash string) error {
|
||||
_, err := exec.Exec(partHash)
|
||||
return err
|
||||
}
|
||||
func (i *LocalUpload) UpdateUpload(ctx context.Context, upload *model_struct.LocalUpload) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(upload))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalUpload) DeleteExpireUpload(ctx context.Context) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
63
go/chao-sdk-core/wasm/indexdb/user_command.go
Normal file
63
go/chao-sdk-core/wasm/indexdb/user_command.go
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
type LocalUserCommand struct{}
|
||||
|
||||
func NewLocalUserCommand() *LocalUserCommand {
|
||||
return &LocalUserCommand{}
|
||||
}
|
||||
|
||||
func (i *LocalUserCommand) ProcessUserCommandGetAll(ctx context.Context) ([]*model_struct.LocalUserCommand, error) {
|
||||
c, err := exec.Exec()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := c.(string); ok {
|
||||
result := []*model_struct.LocalUserCommand{}
|
||||
err := utils.JsonStringToStruct(v, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LocalUserCommand) ProcessUserCommandAdd(ctx context.Context, command *model_struct.LocalUserCommand) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(command))
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *LocalUserCommand) ProcessUserCommandUpdate(ctx context.Context, command *model_struct.LocalUserCommand) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(command))
|
||||
return err
|
||||
}
|
||||
func (i *LocalUserCommand) ProcessUserCommandDelete(ctx context.Context, command *model_struct.LocalUserCommand) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(command))
|
||||
return err
|
||||
}
|
||||
96
go/chao-sdk-core/wasm/indexdb/user_model.go
Normal file
96
go/chao-sdk-core/wasm/indexdb/user_model.go
Normal file
@@ -0,0 +1,96 @@
|
||||
// Copyright © 2023 OpenIM SDK. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build js && wasm
|
||||
// +build js,wasm
|
||||
|
||||
package indexdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
|
||||
)
|
||||
|
||||
import (
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
|
||||
"github.com/openimsdk/openim-sdk-core/v3/wasm/indexdb/temp_struct"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LocalUsers struct {
|
||||
}
|
||||
|
||||
func NewLocalUsers() *LocalUsers {
|
||||
return &LocalUsers{}
|
||||
}
|
||||
|
||||
func (l *LocalUsers) GetLoginUser(ctx context.Context, userID string) (*model_struct.LocalUser, error) {
|
||||
user, err := exec.Exec(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
if v, ok := user.(string); ok {
|
||||
result := model_struct.LocalUser{}
|
||||
temp := temp_struct.LocalUser{}
|
||||
err := utils.JsonStringToStruct(v, &temp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result.UserID = temp.UserID
|
||||
result.Nickname = temp.Nickname
|
||||
result.FaceURL = temp.FaceURL
|
||||
result.CreateTime = temp.CreateTime
|
||||
result.AppMangerLevel = temp.AppMangerLevel
|
||||
result.Ex = temp.Ex
|
||||
result.AttachedInfo = temp.Ex
|
||||
result.GlobalRecvMsgOpt = temp.GlobalRecvMsgOpt
|
||||
return &result, err
|
||||
} else {
|
||||
return nil, exec.ErrType
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LocalUsers) UpdateLoginUser(ctx context.Context, user *model_struct.LocalUser) error {
|
||||
_, err := exec.Exec(utils.StructToJsonString(user))
|
||||
return err
|
||||
|
||||
}
|
||||
func (l *LocalUsers) UpdateLoginUserByMap(ctx context.Context, user *model_struct.LocalUser, args map[string]interface{}) error {
|
||||
if v, ok := args["birth_time"]; ok {
|
||||
if t, ok := v.(time.Time); ok {
|
||||
args["birth_time"] = utils.TimeToString(t)
|
||||
} else {
|
||||
return exec.ErrType
|
||||
}
|
||||
}
|
||||
_, err := exec.Exec(user.UserID, args)
|
||||
return err
|
||||
}
|
||||
|
||||
func (l *LocalUsers) InsertLoginUser(ctx context.Context, user *model_struct.LocalUser) error {
|
||||
temp := temp_struct.LocalUser{}
|
||||
temp.UserID = user.UserID
|
||||
temp.Nickname = user.Nickname
|
||||
temp.FaceURL = user.FaceURL
|
||||
temp.CreateTime = user.CreateTime
|
||||
temp.AppMangerLevel = user.AppMangerLevel
|
||||
temp.Ex = user.Ex
|
||||
temp.AttachedInfo = user.Ex
|
||||
temp.GlobalRecvMsgOpt = user.GlobalRecvMsgOpt
|
||||
_, err := exec.Exec(utils.StructToJsonString(temp))
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user