@@ -85,7 +85,7 @@ func (s ChatService) ChannelMsgToHost(ctx context.Context, sess *state.Session,
8585 Body : bodyOut ,
8686 })
8787 } else {
88- // forward message all participants, except sender
88+ // forward message all participants, except sender
8989 s .chatMessageRelayer .RelayToAllExcept (ctx , sess .ChatRoomCookie (), sess .IdentScreenName (), wire.SNACMessage {
9090 Frame : frameOut ,
9191 Body : bodyOut ,
@@ -116,7 +116,14 @@ func (s ChatService) transformChatMessage(inBody wire.SNAC_0x0E_0x05_ChatChannel
116116 if ! hasMessage {
117117 return wire.TLVRestBlock {}, errors .New ("SNAC(0x0E,0x05) does not contain a message TLV" )
118118 }
119- messageText , err := textFromChatMsgBlob (messageBlob )
119+ msgBlock := wire.TLVRestBlock {}
120+ if err := wire .UnmarshalBE (& msgBlock , bytes .NewBuffer (messageBlob )); err != nil {
121+ return wire.TLVRestBlock {}, err
122+ }
123+
124+ msgBlock = removeUnsupportedTLVs (msgBlock )
125+
126+ messageText , err := textFromChatMsgBlob (msgBlock )
120127 if err != nil {
121128 return wire.TLVRestBlock {}, err
122129 }
@@ -141,7 +148,18 @@ func (s ChatService) transformChatMessage(inBody wire.SNAC_0x0E_0x05_ChatChannel
141148 }
142149
143150 // return the incoming payload without modification
144- return newMessageBlock (sender , messageBlob ), nil
151+ return newMessageBlock (sender , msgBlock ), nil
152+ }
153+
154+ // remove TLVs that break the macos 2.x chat
155+ func removeUnsupportedTLVs (block wire.TLVRestBlock ) wire.TLVRestBlock {
156+ newBlock := wire.TLVRestBlock {}
157+ for _ , tlv := range block .TLVList {
158+ if tlv .Tag < 4 {
159+ newBlock .TLVList = append (newBlock .TLVList , tlv )
160+ }
161+ }
162+ return newBlock
145163}
146164
147165// rollDice generates a chat response for the results of a die roll.
@@ -163,13 +181,9 @@ func (s ChatService) rollDice(sess *state.Session, dice int, sides int) wire.TLV
163181
164182// textFromChatMsgBlob extracts plaintext message text from HTML located in
165183// chat message info TLV(0x05).
166- func textFromChatMsgBlob (msg []byte ) ([]byte , error ) {
167- block := wire.TLVRestBlock {}
168- if err := wire .UnmarshalBE (& block , bytes .NewBuffer (msg )); err != nil {
169- return nil , err
170- }
184+ func textFromChatMsgBlob (msg wire.TLVRestBlock ) ([]byte , error ) {
171185
172- b , hasMsg := block .Bytes (wire .ChatTLVMessageInfoText )
186+ b , hasMsg := msg .Bytes (wire .ChatTLVMessageInfoText )
173187 if ! hasMsg {
174188 return nil , errors .New ("SNAC(0x0E,0x05) has no chat msg text TLV" )
175189 }
0 commit comments