Make message handling more synchronous and fill history on portal create
This commit is contained in:
@ -142,6 +142,11 @@ func (ext *ExtendedConn) handleMessageChatUpdate(message []byte) {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
go chatUpdateHandler.HandleChatUpdate(event)
|
||||
|
||||
if ext.shouldCallSynchronously(chatUpdateHandler) {
|
||||
chatUpdateHandler.HandleChatUpdate(event)
|
||||
} else {
|
||||
go chatUpdateHandler.HandleChatUpdate(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,11 @@ func (ext *ExtendedConn) handleMessageCommand(message []byte) {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
go commandHandler.HandleCommand(event)
|
||||
|
||||
if ext.shouldCallSynchronously(commandHandler) {
|
||||
commandHandler.HandleCommand(event)
|
||||
} else {
|
||||
go commandHandler.HandleCommand(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,11 @@ func (ext *ExtendedConn) handleMessageConn(message []byte) {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
connInfoHandler.HandleConnInfo(event)
|
||||
|
||||
if ext.shouldCallSynchronously(connInfoHandler) {
|
||||
connInfoHandler.HandleConnInfo(event)
|
||||
} else {
|
||||
go connInfoHandler.HandleConnInfo(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,12 @@ func (ext *ExtendedConn) HandleJsonMessage(message string) {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
ujmHandler.HandleUnhandledJSONMessage(message)
|
||||
|
||||
if ext.shouldCallSynchronously(ujmHandler) {
|
||||
ujmHandler.HandleUnhandledJSONMessage(message)
|
||||
} else {
|
||||
go ujmHandler.HandleUnhandledJSONMessage(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,11 @@ func (ext *ExtendedConn) handleMessageMsgInfo(msgType JSONMessageType, message [
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
go msgInfoHandler.HandleMsgInfo(event)
|
||||
|
||||
if ext.shouldCallSynchronously(msgInfoHandler) {
|
||||
msgInfoHandler.HandleMsgInfo(event)
|
||||
} else {
|
||||
go msgInfoHandler.HandleMsgInfo(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,6 +62,11 @@ func (ext *ExtendedConn) handleMessagePresence(message []byte) {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
go presenceHandler.HandlePresence(event)
|
||||
|
||||
if ext.shouldCallSynchronously(presenceHandler) {
|
||||
presenceHandler.HandlePresence(event)
|
||||
} else {
|
||||
go presenceHandler.HandlePresence(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,11 @@ func (ext *ExtendedConn) handleMessageProps(message []byte) {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
go protocolPropsHandler.HandleProtocolProps(event)
|
||||
|
||||
if ext.shouldCallSynchronously(protocolPropsHandler) {
|
||||
protocolPropsHandler.HandleProtocolProps(event)
|
||||
} else {
|
||||
go protocolPropsHandler.HandleProtocolProps(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ type MessageRevocation struct {
|
||||
|
||||
func (ext *ExtendedConn) HandleRawMessage(message *proto.WebMessageInfo) {
|
||||
protoMsg := message.GetMessage().GetProtocolMessage()
|
||||
if protoMsg.GetType() == proto.ProtocolMessage_REVOKE {
|
||||
if protoMsg != nil && protoMsg.GetType() == proto.ProtocolMessage_REVOKE {
|
||||
key := protoMsg.GetKey()
|
||||
deletedMessage := MessageRevocation{
|
||||
Id: key.GetId(),
|
||||
@ -48,7 +48,12 @@ func (ext *ExtendedConn) HandleRawMessage(message *proto.WebMessageInfo) {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
mrHandler.HandleMessageRevoke(deletedMessage)
|
||||
|
||||
if ext.shouldCallSynchronously(mrHandler) {
|
||||
mrHandler.HandleMessageRevoke(deletedMessage)
|
||||
} else {
|
||||
go mrHandler.HandleMessageRevoke(deletedMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,11 @@ func (ext *ExtendedConn) handleMessageStream(message []json.RawMessage) {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
go streamHandler.HandleStreamEvent(event)
|
||||
|
||||
if ext.shouldCallSynchronously(streamHandler) {
|
||||
streamHandler.HandleStreamEvent(event)
|
||||
} else {
|
||||
go streamHandler.HandleStreamEvent(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,15 @@ func ExtendConn(conn *whatsapp.Conn) *ExtendedConn {
|
||||
return ext
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) shouldCallSynchronously(handler whatsapp.Handler) bool {
|
||||
sh, ok := handler.(whatsapp.SyncHandler)
|
||||
return ok && sh.ShouldCallSynchronously()
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) ShouldCallSynchronously() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type GroupInfo struct {
|
||||
JID string `json:"jid"`
|
||||
OwnerJID string `json:"owner"`
|
||||
|
Reference in New Issue
Block a user