Skip to content

Commit

Permalink
Merge pull request #14 from FGadvancer/main
Browse files Browse the repository at this point in the history
fix: sdk add function for upload file.
  • Loading branch information
FGadvancer authored May 22, 2024
2 parents d256b76 + e8ccae6 commit d8c95c3
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 14 deletions.
16 changes: 8 additions & 8 deletions go/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ const (

MESSAGE_KV_INFO_CHANGED

UPLOAD_FILE_CALLBACK_OPEN
UPLOAD_FILE_CALLBACK_PART_SIZE
UPLOAD_FILE_CALLBACK_HASH_PART_PROGRESS
UPLOAD_FILE_CALLBACK_HASH_PART_COMPLETE
UPLOAD_FILE_CALLBACK_UPLOAD_ID
UPLOAD_FILE_CALLBACK_UPLOAD_PART_COMPLETE
UPLOAD_FILE_CALLBACK_UPLOAD_COMPLETE
UPLOAD_FILE_CALLBACK_COMPLETE
OPEN
PART_SIZE
HASH_PART_PROGRESS
HASH_PART_COMPLETE
UPLOAD_ID
UPLOAD_PART_COMPLETE
UPLOAD_COMPLETE
COMPLETE
CONVERSATION_USER_INPUT_STATUS_CHANGED
RECV_ONLINE_ONLY_MESSAGE
)
80 changes: 76 additions & 4 deletions go/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (c ConversationCallback) OnConversationChanged(conversationList string) {
}

func (c ConversationCallback) OnTotalUnreadMessageCountChanged(totalUnreadCount int32) {
C.Call_CB_I_S(c.cCallback, TOTAL_UNREAD_MESSAGE_COUNT_CHANGED, C.CString(Int32ToString(totalUnreadCount)))
C.Call_CB_I_S(c.cCallback, TOTAL_UNREAD_MESSAGE_COUNT_CHANGED, C.CString(IntToString(totalUnreadCount)))
}

func (c ConversationCallback) OnConversationUserInputStatusChanged(change string) {
Expand Down Expand Up @@ -126,21 +126,21 @@ func (a AdvancedMsgCallback) OnNewRecvMessageRevoked(messageRevoked string) {
}

func (a AdvancedMsgCallback) OnRecvMessageExtensionsChanged(msgID string, reactionExtensionList string) {
m := make(map[string]string)
m := make(map[string]any)
m["msgID"] = msgID
m["reactionExtensionList"] = reactionExtensionList
C.Call_CB_I_S(a.cCallback, RECV_MESSAGE_EXTENSIONS_CHANGED, C.CString(StructToJsonString(m)))
}

func (a AdvancedMsgCallback) OnRecvMessageExtensionsDeleted(msgID string, reactionExtensionKeyList string) {
m := make(map[string]string)
m := make(map[string]any)
m["msgID"] = msgID
m["reactionExtensionKeyList"] = reactionExtensionKeyList
C.Call_CB_I_S(a.cCallback, RECV_MESSAGE_EXTENSIONS_DELETED, C.CString(StructToJsonString(m)))
}

func (a AdvancedMsgCallback) OnRecvMessageExtensionsAdded(msgID string, reactionExtensionList string) {
m := make(map[string]string)
m := make(map[string]any)
m["msgID"] = msgID
m["reactionExtensionList"] = reactionExtensionList
C.Call_CB_I_S(a.cCallback, RECV_MESSAGE_EXTENSIONS_ADDED, C.CString(StructToJsonString(m)))
Expand Down Expand Up @@ -336,6 +336,68 @@ func (b BaseCallback) OnSuccess(data string) {
C.Call_CB_S_I_S_S(b.cCallback, C.CString(b.operationID), NO_ERR, NO_ERR_MSG, C.CString(data))
}

type UploadFileCallback struct {
cCallback C.CB_I_S
}

func NewUploadFileCallback(cCallback C.CB_I_S) *UploadFileCallback {
return &UploadFileCallback{cCallback: cCallback}
}

func (u UploadFileCallback) Open(size int64) {
C.Call_CB_I_S(u.cCallback, OPEN, C.CString(IntToString(size)))
}

func (u UploadFileCallback) PartSize(partSize int64, num int) {
m := make(map[string]any)
m["partSize"] = partSize
m["num"] = num
C.Call_CB_I_S(u.cCallback, PART_SIZE, C.CString(StructToJsonString(m)))
}

func (u UploadFileCallback) HashPartProgress(index int, size int64, partHash string) {
m := make(map[string]any)
m["index"] = index
m["size"] = size
m["partHash"] = partHash
C.Call_CB_I_S(u.cCallback, HASH_PART_PROGRESS, C.CString(StructToJsonString(m)))
}

func (u UploadFileCallback) HashPartComplete(partsHash string, fileHash string) {
m := make(map[string]any)
m["partsHash"] = partsHash
m["fileHash"] = fileHash
C.Call_CB_I_S(u.cCallback, HASH_PART_COMPLETE, C.CString(StructToJsonString(m)))
}

func (u UploadFileCallback) UploadID(uploadID string) {
C.Call_CB_I_S(u.cCallback, UPLOAD_ID, C.CString(uploadID))
}

func (u UploadFileCallback) UploadPartComplete(index int, partSize int64, partHash string) {
m := make(map[string]any)
m["index"] = index
m["partSize"] = partSize
m["partHash"] = partHash
C.Call_CB_I_S(u.cCallback, UPLOAD_PART_COMPLETE, C.CString(StructToJsonString(m)))
}

func (u UploadFileCallback) UploadComplete(fileSize int64, streamSize int64, storageSize int64) {
m := make(map[string]any)
m["fileSize"] = fileSize
m["streamSize"] = streamSize
m["storageSize"] = storageSize
C.Call_CB_I_S(u.cCallback, UPLOAD_COMPLETE, C.CString(StructToJsonString(m)))
}

func (u UploadFileCallback) Complete(size int64, url string, typ int) {
m := make(map[string]any)
m["size"] = size
m["url"] = url
m["typ"] = typ
C.Call_CB_I_S(u.cCallback, COMPLETE, C.CString(StructToJsonString(m)))
}

// =====================================================global_callback===============================================

//export set_group_listener
Expand Down Expand Up @@ -849,6 +911,16 @@ func get_user_status(cCallback C.CB_S_I_S_S, operationID *C.char, userIDs *C.cha
open_im_sdk.GetUserStatus(baseCallback, C.GoString(operationID), C.GoString(userIDs))
}

// =====================================================file===============================================
//

//export upload_file
func upload_file(cCallback C.CB_S_I_S_S, operationID *C.char, req *C.char, uploadCallback C.CB_I_S) {
baseCallback := NewBaseCallback(cCallback, operationID)
uploadFileCallback := NewUploadFileCallback(uploadCallback)
open_im_sdk.UploadFile(baseCallback, C.GoString(operationID), C.GoString(req), uploadFileCallback)
}

// =====================================================friend===============================================
//
//export get_specified_friends_info
Expand Down
5 changes: 3 additions & 2 deletions go/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func FreeCString(strList ...*C.char) {
C.free(unsafe.Pointer(str))
}
}
func Int32ToString(intValue int32) string {
return strconv.Itoa(int(intValue))

func IntToString[T int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](intValue T) string {
return strconv.FormatInt(int64(intValue), 10)
}

0 comments on commit d8c95c3

Please sign in to comment.